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

Contents of /trunk/pygtk/instance.h

Parent Directory Parent Directory | Revision Log Revision Log


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

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