/[ascend]/trunk/pygtk/interface/instance.h
ViewVC logotype

Contents of /trunk/pygtk/interface/instance.h

Parent Directory Parent Directory | Revision Log Revision Log


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

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22