OpenMS
IMSAlphabetParser.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Anton Pervukhin <Anton.Pervukhin@CeBiTec.Uni-Bielefeld.DE> $
7 // --------------------------------------------------------------------------
8 //
9 
10 #pragma once
11 
12 #include <fstream>
13 #include <istream>
14 #include <map>
15 #include <string>
16 
18 
19 namespace OpenMS
20 {
21 
22  namespace ims
23  {
24 
34  template <typename AlphabetElementType = double,
35  typename Container = std::map<std::string, AlphabetElementType>,
36  typename InputSource = std::istream>
38  {
39 public:
43  typedef Container ContainerType;
44 
52  void load(const std::string & fname);
53 
59  virtual ContainerType & getElements() = 0;
60 
66  virtual void parse(InputSource & is) = 0;
67 
69  virtual ~IMSAlphabetParser() {}
70  };
71 
72  template <typename AlphabetElementType, typename Container, typename InputSource>
74  {
75  std::ifstream ifs(fname.c_str());
76  if (!ifs)
77  {
78  throw Exception::IOException(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, fname);
79  }
80  this->parse(ifs);
81  }
82 
83  } // namespace ims
84 } // namespace OpenMS
85 
General IOException.
Definition: Exception.h:542
An abstract templatized parser to load the data that is used to initialize Alphabet objects.
Definition: IMSAlphabetParser.h:38
virtual ContainerType & getElements()=0
virtual ~IMSAlphabetParser()
Destructor.
Definition: IMSAlphabetParser.h:69
Container ContainerType
Definition: IMSAlphabetParser.h:43
virtual void parse(InputSource &is)=0
void load(const std::string &fname)
Definition: IMSAlphabetParser.h:73
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22