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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 215 - (show annotations) (download) (as text)
Wed Jan 25 02:08:29 2006 UTC (18 years, 4 months ago) by johnpye
File MIME type: text/x-chdr
File size: 3213 byte(s)
Improved display of relations by adding getRelationAsString(relative_to)
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 /**
24 This class has to be called 'Instanc' in C++ to avoid a name clash
25 with C. Maybe coulda done it with namespaces but didn't know how.
26
27 This class is renamed back to 'Instance' by SWIG, so use 'Instance'
28 when you're in Python.
29
30 The Right Way to implement this class would be as a base class
31 with lots of diffent subclasses for the different atom types.
32 Maybe even multiple inheritance.
33
34 But until the underlying C code is ported to C++ it's not going to be
35 worth the effort.
36 */
37 class Instanc{
38 private:
39 struct Instance *i;
40 SymChar name;
41 std::vector<Instanc> children;
42 void setName(SymChar);
43 static SymChar fixedsym;
44 static SymChar solvervarsym;
45 public:
46 Instanc();
47 Instanc(Instance *i);
48 Instanc(Instance *i, const SymChar &name);
49 Instanc(const Instanc &parent, const unsigned long &childnum);
50 Instanc(const Instanc&);
51 std::vector<Instanc> &getChildren();
52 Instanc getChild(const SymChar &) const;
53 const enum inst_t getKind() const;
54 const std::string getKindStr() const;
55 const Type getType() const;
56 const bool isAtom() const;
57 const bool isFixed() const;
58
59 const bool isFund() const;
60 const bool isConst() const;
61 const bool isCompound() const;
62 const bool isRelation() const;
63 const bool isWhen() const;
64 const bool isSet() const;
65 const bool isSetInt() const;
66 const bool isSetString() const;
67 const bool isSetEmpty() const; // set of of type 'empty', NB not same as SetInt::length()==0
68 const bool isArray() const;
69 const bool isDefined() const;
70 const bool isChildless() const;
71 const bool isBool() const;
72 const bool isInt() const;
73 const bool isSymbol() const;
74 const bool isReal() const;
75 const bool isAssigned() const;
76 const SymChar &getName() const;
77 const double getRealValue() const;
78 const bool isDimensionless() const;
79 const Dimensions getDimensions() const;
80 const bool getBoolValue() const;
81 const long getIntValue() const;
82 const SymChar getSymbolValue() const;
83 const std::string getValueAsString() const;
84 const std::string getRelationAsString(const Instanc &relative_to) const;
85 Plot getPlot() const;
86
87 const bool isPlottable() const;
88
89 void setFixed(const bool &val=true);
90 void setBoolValue(const bool&, const unsigned &depth=0);
91 void setRealValue(const double&, const unsigned &depth=0);
92 void setRealValueWithUnits(double, const char *, const unsigned &depth=0);
93
94 template<class T>
95 const ASCXX_Set<T> Instanc::getSetValue() const{
96 if(!isSet()){
97 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not set-valued",getName().toString());
98 return ASCXX_Set<T>();
99 }
100 if(!isConst() && !isDefined()){
101 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
102 return ASCXX_Set<T>();
103 }
104 return ASCXX_Set<T>(SetAtomList(i));
105 }
106
107 const enum set_kind getSetType() const;
108 void write();
109 Instance *getInternalType() const;
110 };
111
112 #endif
113

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