~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSAlphabetParser.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Stephan Aiche $
 
25
// $Authors: Anton Pervukhin <Anton.Pervukhin@CeBiTec.Uni-Bielefeld.DE> $
 
26
// --------------------------------------------------------------------------
 
27
//
 
28
 
 
29
#ifndef OPENMS_CHEMISTRY_MASSDECOMPOSITION_IMS_IMSALPHABETPARSER_H
 
30
#define OPENMS_CHEMISTRY_MASSDECOMPOSITION_IMS_IMSALPHABETPARSER_H
 
31
 
 
32
#include <fstream>
 
33
#include <istream>
 
34
#include <map>
 
35
#include <string>
 
36
 
 
37
#include <OpenMS/CONCEPT/Exception.h>
 
38
 
 
39
namespace OpenMS {
 
40
 
 
41
  namespace ims {
 
42
 
 
43
    /**
 
44
      @brief An abstract templatized parser to load the data that is used to initialize @c Alphabet objects.
 
45
 
 
46
      @c AlphabetParser reads the input source, which is given as a template parameter @c InputSource , by
 
47
      @c load (const std::string& fname) function where @c fname is the source name.
 
48
      Loaded data can be retrieved by calling @c getElements().
 
49
 
 
50
      @see Alphabet
 
51
    */
 
52
    template <typename AlphabetElementType = double,
 
53
              typename Container = std::map<std::string, AlphabetElementType>,
 
54
              typename InputSource = std::istream>
 
55
    class IMSAlphabetParser
 
56
    {
 
57
    public:
 
58
      /**
 
59
        Type of data to be loaded.
 
60
      */
 
61
      typedef Container ContainerType;
 
62
 
 
63
      /**
 
64
        Loads the data from the InputSource with the name @c fname.
 
65
        If there is an error occurred while reading data from InputSource,
 
66
        @c IOException is thrown.
 
67
 
 
68
        @param fname The name of the input source.
 
69
      */
 
70
      void load(const std::string& fname);
 
71
 
 
72
      /**
 
73
        Gets the data that was loaded.
 
74
 
 
75
        @return The data.
 
76
      */
 
77
      virtual ContainerType& getElements() = 0;
 
78
 
 
79
      /**
 
80
        Parses the the given input source @c is .
 
81
 
 
82
        @param is The InputSource
 
83
 
 
84
      */
 
85
      virtual void parse(InputSource& is) = 0;
 
86
 
 
87
      /**
 
88
        Destructor.
 
89
      */
 
90
      virtual ~IMSAlphabetParser() {}
 
91
    };
 
92
 
 
93
    template <typename AlphabetElementType, typename Container, typename InputSource>
 
94
    void IMSAlphabetParser<AlphabetElementType, Container, InputSource>::load(const std::string& fname)
 
95
    {
 
96
      std::ifstream ifs(fname.c_str());
 
97
      if (!ifs)
 
98
      {
 
99
        throw Exception::IOException(__FILE__, __LINE__, __PRETTY_FUNCTION__,fname);
 
100
      }
 
101
      this->parse(ifs);
 
102
    }
 
103
 
 
104
  } // namespace ims
 
105
 
 
106
} // namespace OpenMS
 
107
 
 
108
#endif // OPENMS_CHEMISTRY_MASSDECOMPOSITION_IMS_ALPHABETPARSER_H