Simpatico  v1.10
TypeMap.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "TypeMap.h"
9 #include <util/param/Label.h>
10 
11 namespace Tools
12 {
13 
14  using namespace Util;
15 
20  {}
21 
26  {}
27 
28  void TypeMap::insert(int id, const std::string& name)
29  {
30  std::map<std::string, int>::const_iterator id_iter = ids_.find(name);
31  if (id_iter != ids_.end()) {
32  UTIL_THROW("Name already present");
33  }
34  std::map<int, std::string>::const_iterator name_iter = names_.find(id);
35  if (name_iter != names_.end()) {
36  UTIL_THROW("Id already present");
37  }
38  ids_.insert(std::pair<std::string, int>(name, id));
39  names_.insert(std::pair<int, std::string>(id, name));
40  }
41 
42  void TypeMap::read(std::istream& in)
43  {
44  int nType = 0;
45  int id;
46  std::string name;
47  in >> Label("nType") >> nType;
48  in >> Label("types");
49  for (int i = 0; i < nType; ++i) {
50  in >> id >> name;
51  insert(id, name);
52  }
53  }
54 
55 }
void read(std::istream &in)
Read pairs from file.
Definition: TypeMap.cpp:42
void insert(int id, const std::string &name)
Add typeId / type name pair to the container.
Definition: TypeMap.cpp:28
TypeMap()
Constructor.
Definition: TypeMap.cpp:19
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
Single-processor classes for pre- and post-processing MD trajectories.
A label string in a file format.
Definition: Label.h:36
~TypeMap()
Destructor.
Definition: TypeMap.cpp:25