1 |
#ifndef ASCXX_INSTANCE_H |
2 |
#define ASCXX_INSTANCE_H |
3 |
|
4 |
#include <string> |
5 |
#include <vector> |
6 |
|
7 |
#include "symchar.h" |
8 |
#include "type.h" |
9 |
#include "set.h" |
10 |
#include "dimensions.h" |
11 |
|
12 |
class Plot; |
13 |
|
14 |
extern "C"{ |
15 |
#include <utilities/ascConfig.h> |
16 |
#include <utilities/error.h> |
17 |
#include <compiler/types.h> |
18 |
#include <compiler/instance_enum.h> |
19 |
#include <compiler/atomvalue.h> |
20 |
#include <compiler/plot.h> |
21 |
} |
22 |
|
23 |
typedef enum{ |
24 |
ASCXX_VAR_STATUS_UNKNOWN=0, ASCXX_VAR_FIXED, ASCXX_VAR_UNSOLVED, ASCXX_VAR_ACTIVE, ASCXX_VAR_SOLVED |
25 |
} VarStatus; |
26 |
|
27 |
/** |
28 |
This class has to be called 'Instanc' in C++ to avoid a name clash |
29 |
with C. Maybe coulda done it with namespaces but didn't know how. |
30 |
|
31 |
This class is renamed back to 'Instance' by SWIG, so use 'Instance' |
32 |
when you're in Python. |
33 |
|
34 |
The Right Way to implement this class would be as a base class |
35 |
with lots of diffent subclasses for the different atom types. |
36 |
Maybe even multiple inheritance. |
37 |
|
38 |
But until the underlying C code is ported to C++ it's not going to be |
39 |
worth the effort. |
40 |
*/ |
41 |
class Instanc{ |
42 |
private: |
43 |
struct Instance *i; |
44 |
SymChar name; |
45 |
std::vector<Instanc> children; |
46 |
void setName(SymChar); |
47 |
static SymChar fixedsym; |
48 |
static SymChar solvervarsym; |
49 |
public: |
50 |
Instanc(); |
51 |
Instanc(Instance *i); |
52 |
Instanc(Instance *i, const SymChar &name); |
53 |
Instanc(const Instanc &parent, const unsigned long &childnum); |
54 |
Instanc(const Instanc&); |
55 |
std::vector<Instanc> &getChildren(); |
56 |
Instanc getChild(const SymChar &) const; |
57 |
const enum inst_t getKind() const; |
58 |
const std::string getKindStr() const; |
59 |
const Type getType() const; |
60 |
const bool isAtom() const; |
61 |
const bool isFixed() const; |
62 |
|
63 |
const bool isFund() const; |
64 |
const bool isConst() const; |
65 |
const bool isCompound() const; |
66 |
const bool isRelation() const; |
67 |
const bool isWhen() const; |
68 |
const bool isSet() const; |
69 |
const bool isSetInt() const; |
70 |
const bool isSetString() const; |
71 |
const bool isSetEmpty() const; // set of of type 'empty', NB not same as SetInt::length()==0 |
72 |
const bool isArray() const; |
73 |
const bool isDefined() const; |
74 |
const bool isChildless() const; |
75 |
const bool isBool() const; |
76 |
const bool isInt() const; |
77 |
const bool isSymbol() const; |
78 |
const bool isReal() const; |
79 |
const bool isAssigned() const; |
80 |
const SymChar &getName() const; |
81 |
const double getRealValue() const; |
82 |
const bool isDimensionless() const; |
83 |
const Dimensions getDimensions() const; |
84 |
const bool getBoolValue() const; |
85 |
const long getIntValue() const; |
86 |
const SymChar getSymbolValue() const; |
87 |
const std::string getValueAsString() const; |
88 |
const std::string getRelationAsString(const Instanc &relative_to) const; |
89 |
Plot getPlot() const; |
90 |
|
91 |
const bool isPlottable() const; |
92 |
|
93 |
void setFixed(const bool &val=true); |
94 |
void setBoolValue(const bool&, const unsigned &depth=0); |
95 |
void setRealValue(const double&, const unsigned &depth=0); |
96 |
void setRealValueWithUnits(double, const char *, const unsigned &depth=0); |
97 |
|
98 |
template<class T> |
99 |
const ASCXX_Set<T> Instanc::getSetValue() const{ |
100 |
if(!isSet()){ |
101 |
ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not set-valued",getName().toString()); |
102 |
return ASCXX_Set<T>(); |
103 |
} |
104 |
if(!isConst() && !isDefined()){ |
105 |
ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString()); |
106 |
return ASCXX_Set<T>(); |
107 |
} |
108 |
return ASCXX_Set<T>(SetAtomList(i)); |
109 |
} |
110 |
|
111 |
const enum set_kind getSetType() const; |
112 |
void write(); |
113 |
Instance *getInternalType() const; |
114 |
|
115 |
void setVarStatus(const VarStatus &); ///< make this one private, just for friend Simulation? |
116 |
const VarStatus getVarStatus() const; |
117 |
|
118 |
void setLowerBound(const double &); |
119 |
void setUpperBound(const double &); |
120 |
void setNominal(const double &); |
121 |
const double getLowerBound() const; |
122 |
const double getUpperBound() const; |
123 |
const double getNominal() const; |
124 |
}; |
125 |
|
126 |
#endif |
127 |
|