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