roadrunner  2.6.0
Fast simulator for SBML models
SymbolForest.h
1 /*
2  * SymbolForest.h
3  *
4  * Created on: Jul 3, 2013
5  * Author: andy
6  */
7 
8 #ifndef SymbolForestH
9 #define SymbolForestH
10 
11 #include <sbml/math/ASTNode.h>
12 #include <map>
13 #include <cassert>
14 
15 namespace rrllvm
16 {
17 using std::string;
18 using std::map;
19 
37 {
38 public:
39  typedef std::map<std::string, const libsbml::ASTNode*> Map;
40  typedef std::map<std::string, const libsbml::ASTNode*>::const_iterator _const_iterator;
41 
48  {
49  public:
50 
51  const libsbml::ASTNode* second;
52 
53  const ConstIterator* operator->() const
54  {
55  return this;
56  }
57 
58  bool operator !=(const ConstIterator& other) const
59  {
60  return end != other.end;
61  }
62 
63  ConstIterator & operator= (const ConstIterator & o)
64  {
65  this->second = o.second;
66  this->end = o.end;
67  // by convention, always return *this
68  return *this;
69  }
70 
71  ConstIterator(const ConstIterator &o) : second(o.second), end(o.end)
72  {
73  }
74 
75 
76  private:
77 
81  friend class SymbolForest;
82 
86  ConstIterator(_const_iterator i) : second(i->second), end(false)
87  {
88  assert(second && "must have valid ASTNode pointer");
89  }
90 
94  ConstIterator() : second(0), end(true)
95  {
96  }
97 
98  // is the the end iterator.
99  bool end;
100  };
101 
102  std::map<std::string, const libsbml::ASTNode*> floatingSpecies;
103  std::map<std::string, const libsbml::ASTNode*> boundarySpecies;
104  std::map<std::string, const libsbml::ASTNode*> compartments;
105  std::map<std::string, const libsbml::ASTNode*> globalParameters;
106  std::map<std::string, const libsbml::ASTNode*> speciesReferences;
107 
114  const ConstIterator find(const std::map<std::string, const libsbml::ASTNode*>::key_type& x) const
115  {
116  _const_iterator result;
117 
118  if ((result = floatingSpecies.find(x)) != floatingSpecies.end())
119  {
120  return ConstIterator(result);
121  }
122  else if ((result = boundarySpecies.find(x)) != boundarySpecies.end())
123  {
124  return ConstIterator(result);
125  }
126  else if ((result = compartments.find(x)) != compartments.end())
127  {
128  return ConstIterator(result);
129  }
130  else if ((result = globalParameters.find(x)) != globalParameters.end())
131  {
132  return ConstIterator(result);
133  }
134  else if ((result = speciesReferences.find(x)) != speciesReferences.end())
135  {
136  return ConstIterator(result);
137  }
138  else
139  {
140  return _end;
141  }
142  }
143 
144  const ConstIterator& end() const
145  {
146  return _end;
147  }
148 
149 private:
150  ConstIterator _end;
151 
152 };
153 
154 
155 } /* namespace rr */
156 #endif /* LLVMSymbolForestH */
syntatically the same as a std::map<std::string, const libsbml::ASTNode*>::const_iterator
Definition: SymbolForest.h:48
Similar to a symbol table, except instead of a name / value, we have a name / tree,...
Definition: SymbolForest.h:37
const ConstIterator find(const std::map< std::string, const libsbml::ASTNode * >::key_type &x) const
find and end are designed to work identically to the std::map::find.
Definition: SymbolForest.h:114