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

Contents of /trunk/pygtk/instance.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1960 - (show annotations) (download) (as text)
Mon Nov 17 12:15:56 2008 UTC (15 years, 6 months ago) by jpye
File MIME type: text/x-chdr
File size: 5006 byte(s)
Add setIntValue to Python wrapper for Instance class.
Added getModule method for Type, planned for use with canvas-based modeller.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef ASCXX_INSTANCE_H
21 #define ASCXX_INSTANCE_H
22
23 #include "symchar.h"
24 #include "type.h"
25 #include "set.h"
26 #include "dimensions.h"
27
28 class Plot;
29
30 #include "config.h"
31 extern "C"{
32 #include <utilities/ascConfig.h>
33 #include <utilities/error.h>
34 #include <compiler/expr_types.h>
35 #include <compiler/instance_enum.h>
36 #include <compiler/atomvalue.h>
37 #include <compiler/plot.h>
38 }
39
40 #include <string>
41 #include <vector>
42
43 typedef enum{
44 ASCXX_INST_STATUS_UNKNOWN=0, ASCXX_VAR_FIXED, ASCXX_VAR_UNSOLVED, ASCXX_VAR_ACTIVE, ASCXX_VAR_SOLVED
45 , ASCXX_REL_INACTIVE
46 } InstanceStatus;
47
48 /**
49 This class has to be called 'Instanc' in C++ to avoid a name clash
50 with C. Maybe coulda done it with namespaces but didn't know how.
51
52 This class is renamed back to 'Instance' by SWIG, so use 'Instance'
53 when you're in Python.
54
55 The Right Way to implement this class would be as a base class
56 with lots of diffent subclasses for the different atom types.
57 Maybe even multiple inheritance.
58
59 But until the underlying C code is ported to C++ or modularised in
60 some other way, it's not going to be worth the effort. We discussed
61 this in the mailing list.
62 */
63 class Instanc{
64 protected:
65 struct Instance *i;
66 SymChar name;
67 std::vector<Instanc> children;
68 void setName(SymChar);
69 static SymChar fixedsym;
70 static SymChar solvervarsym;
71 public:
72 Instanc();
73 Instanc(Instance *i);
74 Instanc(Instance *i, const SymChar &name);
75 Instanc(const Instanc &parent, const unsigned long &childnum);
76 Instanc(const Instanc&);
77 ~Instanc();
78 std::vector<Instanc> &getChildren();
79 Instanc getChild(const SymChar &) const;
80 Instanc getChild(const long &) const;
81 const enum inst_t getKind() const;
82 const std::string getKindStr() const;
83 const Type getType() const;
84 const bool isAtom() const;
85 const bool isFixed() const;
86 const bool isIncluded() const;
87
88 const bool isFund() const;
89 const bool isConst() const;
90 const bool isCompound() const;
91 const bool isRelation() const;
92 const bool isLogicalRelation() const;
93 const bool isWhen() const;
94 const bool isSet() const;
95 const bool isSetInt() const;
96 const bool isSetString() const;
97 const bool isSetEmpty() const; // set of of type 'empty', NB not same as SetInt::length()==0
98 const bool isArray() const;
99 const bool isDefined() const;
100 const bool isChildless() const;
101 const bool isBool() const;
102 const bool isInt() const;
103 const bool isSymbol() const;
104 const bool isReal() const;
105 const bool isAssigned() const;
106 const bool isModel() const;
107 const SymChar &getName() const;
108 const double getRealValue() const;
109 const bool isDimensionless() const;
110 const Dimensions getDimensions() const;
111 const bool getBoolValue() const;
112 const long getIntValue() const;
113 const SymChar getSymbolValue() const;
114
115 const std::string getValueAsString() const;
116 const std::string getRelationAsString(const Instanc &relative_to) const;
117 Plot getPlot() const;
118
119 const bool isPlottable() const;
120
121 void setFixed(const bool &val=true);
122 void setIncluded(const bool &val=true);
123 void setBoolValue(const bool&, const unsigned &depth=0);
124 void setIntValue(const long&, const unsigned &depth=0);
125 void setRealValue(const double&, const unsigned &depth=0);
126 void setRealValueWithUnits(double, const char *, const unsigned &depth=0);
127 void setSymbolValue(const SymChar &);
128
129 template<class T>
130 const ASCXX_Set<T> getSetValue() const{
131 if(!isSet()){
132 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not set-valued",getName().toString());
133 return ASCXX_Set<T>();
134 }
135 if(!isConst() && !isDefined()){
136 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
137 return ASCXX_Set<T>();
138 }
139 return ASCXX_Set<T>(SetAtomList(i));
140 }
141
142 const enum set_kind getSetType() const;
143 void write(FILE *fp) const;
144 Instance *getInternalType() const;
145
146 void setStatus(const InstanceStatus &); ///< make this one private, just for friend Simulation?
147 const InstanceStatus getStatus() const;
148
149 void setLowerBound(const double &);
150 void setUpperBound(const double &);
151 void setNominal(const double &);
152 const double getLowerBound() const;
153 const double getUpperBound() const;
154 const double getNominal() const;
155
156 const std::vector<Instanc> getClique() const;
157
158 const double getResidual() const;
159 const bool getLogicalResidual() const;
160 };
161
162 #endif
163

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