vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
abstractfile.h
Go to the documentation of this file.
1 #ifndef ABSTRACTFILE_H_
2 #define ABSTRACTFILE_H_
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include "configuration.h"
8 #include "lsystemexception.h"
9 
10 using std::string;
11 
12 namespace AP_LSystem {
17 {
18 protected:
19  unsigned int m_Type;
20  string m_Name;
21  string m_Axiom;
22 
23  std::vector<string> m_Rules;
24  std::vector<string> m_Homomorphisms;
25  std::vector<string> m_Subsytems;
26 
41  void addType( std::string & type )
42  {
43  if(type == "0L")
44  {
45  m_Type |= LS_0L;
46  }
47  else if(type == "1LL")
48  {
49  m_Type |= LS_1LL;
50  }
51  else if(type == "1LR")
52  {
53  m_Type |= LS_1LR;
54  }
55  else if(type == "2L")
56  {
57  m_Type |= LS_2L;
58  }
59  else if(type == "IL")
60  {
61  m_Type |= LS_IL;
62  }
63  else if(type == "DETERMINISTIC")
64  {
66  }
67  else if(type == "STOCHASTIC")
68  {
70  }
71  else if(type == "PARAMETRIC")
72  {
74  }
75  else
76  {
77  throw ParsingException("unknown lsystem type");
78  }
79  }
80 public:
85 
90  virtual void open( std::string & filename) = 0;
91 
97  void substitute(std::map<string, string> & pairs)
98  {
99  unsigned int i;
100  std::vector<string>::iterator rule;
101  std::map<std::string,std::string>::iterator subst;
102 
103  // substitute occurences in m_Axiom
104  for(subst = pairs.begin(); subst != pairs.end(); subst++)
105  {
106  i=0;
107  while((i = m_Axiom.find(subst->first,i))&&(i != std::string::npos))
108  {
109  m_Axiom.replace(i,subst->first.length(),subst->second);
110  i += subst->second.length();
111  }
112  }
113 
114  // substitute occurences in m_Rules
115  for(rule = m_Rules.begin();rule != m_Rules.end(); rule++)
116  {
117  for(subst = pairs.begin(); subst != pairs.end(); subst++)
118  {
119  i=0;
120  while((i = rule->find(subst->first,i))&&(i != std::string::npos))
121  {
122  rule->replace(i,subst->first.length(),subst->second);
123  i += subst->second.length();
124  }
125  }
126  }
127 
128  for(rule = m_Homomorphisms.begin();rule != m_Homomorphisms.end(); rule++)
129  {
130  for(subst = pairs.begin(); subst != pairs.end(); subst++)
131  {
132  i=0;
133  while((i = rule->find(subst->first,i))&&(i != std::string::npos))
134  {
135  rule->replace(i,subst->first.length(),subst->second);
136  i += subst->second.length();
137  }
138  }
139  }
140  }
141 
146  virtual std::vector<string> * getHomomorphisms()
147  {
148  return &m_Homomorphisms;
149  }
150 
155  virtual std::vector<string> * getRules()
156  {
157  return &m_Rules;
158  }
159 
164  virtual std::vector<string> * getSubsystems()
165  {
166  return &m_Subsytems;
167  }
168 
173  std::string & getAxiom()
174  {
175  return m_Axiom;
176  }
177 
182  unsigned int type()
183  {
184  return m_Type;
185  }
186 
191  std::string & name()
192  {
193  return m_Name;
194  }
195 };
196 }
197 
198 #endif // ABSTRACTFILE_H