Spectra
formula.h
1 
8 #ifndef DP_FORMULA_H
9 #define DP_FORMULA_H
10 
11 
12 #include <vector>
13 #include <string>
14 #include <sstream>
15 #include <utility>
16 #include "fileLocation.h"
17 
22 enum OpType {
23  LAST,
24  PREVIOUSLY,
25  GLOBALLY,
26  S_SINCE,
27  W_SINCE,
28  UP,
29  DOWN,
30  S_INTERVAL,
31  W_INTERVAL,
32  AND,
33  OR,
34  XOR,
35  NOT,
36  IMPLY,
37  ATOM /*< Boolean expression - should be a name of a variable */
38 };
39 
43 enum State {
44  CREATED, /*< After constructor */
45  INITIALIZED, /*< Operation was set, doesn't say anything about operands */
46  FIRST_OP, /*< One operator is set, doesn't say anything about the operation */
47  READY /*< Everything is set - operation and corresponding number of operands */
48 };
49 
59 class formula {
60 
61 private:
62  int id; /*< A UNIQUE id of formula - every it's subformula has a greater id value
63  *< Is always set in constructor
64  *< The main (root) formula has id == 0 */
65 
66  OpType operation; /*< Operator of this formula defined using enum OpType */
67 
68  std::vector<int> operands; /*< A vector of direct-subformulae ids
69  *< is empty for ATOM, permits 2+ operands for AND, OR and XOR */
70 
71  std::string content; /*< A string representation of the formula */
72 
73  std::string print; /*< A string used by ATOM formulae to store unmodified
74  *< name of the represented variable */
75 
76  State s; /*< A state of initialization of the formula using enum State */
77 
78  fileLocation start; /*< A location of first character of this formula in the specification file */
79 
80  fileLocation end; /*< A location of last character of this formula in the specification file */
81 
82 public:
83 
89  explicit formula(int id);
90 
96  void addOperand(int);
97 
105  std::string getContent();
106 
114  std::string getInitContent();
115 
121  bool isFullySet();
122 
128  bool canAddOperands();
129 
135  std::string printOpType();
136 
137 
144  void incrementIds();
145 
146  /*************************************** GET ***************************************/
147 
148  int getId();
149 
150  State getState();
151 
152  const fileLocation &getStart() const;
153 
154  const fileLocation &getEnd() const;
155 
156  OpType getOperation();
157 
158  std::vector<int> &getOperands();
159 
160  std::string getPrintText();
161 
162  /*************************************** SET ***************************************/
163 
164 
165  void setOperation(OpType);
166 
167 
176  void setContent(std::string);
177 
178 
179  void setPrint(std::string);
180 
181 
182  void setStart(const fileLocation &start);
183 
184 
185  void setEnd(const fileLocation &end);
186 
187 
196  bool operator< (const formula &other) const {
197  return id > other.id;
198  }
199 
206  bool operator== (const formula &other) const {
207  return id == other.id;
208  }
209 };
210 
211 
212 #endif //DP_FORMULA_H
bool operator<(const formula &other) const
Definition: formula.h:196
std::string getInitContent()
Definition: formula.cpp:176
Definition: fileLocation.h:15
bool isFullySet()
Definition: formula.cpp:132
formula(int id)
Definition: formula.cpp:15
bool operator==(const formula &other) const
Definition: formula.h:206
void setContent(std::string)
Definition: formula.cpp:156
std::string getContent()
Definition: formula.cpp:67
std::string printOpType()
Definition: formula.cpp:238
void addOperand(int)
Definition: formula.cpp:25
Definition: formula.h:59
bool canAddOperands()
Definition: formula.cpp:143
void incrementIds()
Definition: formula.cpp:280