Simpatico  v1.10
TypeMap.h
1 #ifndef TOOLS_TYPE_MAP_H
2 #define TOOLS_TYPE_MAP_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 
13 #include <string>
14 #include <map>
15 
16 namespace Tools
17 {
18 
19  using namespace Util;
20 
26  class TypeMap
27  {
28 
29  public:
30 
34  TypeMap();
35 
39  ~TypeMap();
40 
47  void insert(int id, const std::string& name);
48 
54  void read(std::istream& in);
55 
59  int id(const std::string& name) const;
60 
64  const std::string& name(int id) const;
65 
69  int size() const;
70 
71  private:
72 
74  std::map<std::string, int> ids_;
75 
77  std::map<int, std::string> names_;
78 
79  };
80 
81  inline
82  int TypeMap::id(const std::string& name) const
83  {
84  std::map<std::string, int>::const_iterator iter = ids_.find(name);
85  if (iter == ids_.end()) {
86  UTIL_THROW("Type name not found");
87  }
88  return iter->second;
89  }
90 
91  inline
92  const std::string& TypeMap::name(int id) const
93  {
94  std::map<int, std::string>::const_iterator iter = names_.find(id);
95  if (iter == names_.end()) {
96  UTIL_THROW("Type id not found");
97  }
98  return iter->second;
99  }
100 
101  inline
102  int TypeMap::size() const
103  { return names_.size(); }
104 
105 }
106 #endif
Map between type names and type ids.
Definition: TypeMap.h:26
const std::string & name(int id) const
Get type name associated with an integer id.
Definition: TypeMap.h:92
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
int id(const std::string &name) const
Get type id associated with a type name.
Definition: TypeMap.h:82
Utility classes for scientific computation.
Definition: accumulators.mod:1
int size() const
Number of a pairs in map.
Definition: TypeMap.h:102
Single-processor classes for pre- and post-processing MD trajectories.