/[ascend]/branches/adrian/ascxx/instance.h
ViewVC logotype

Contents of /branches/adrian/ascxx/instance.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3018 - (show annotations) (download) (as text)
Mon Jul 20 12:22:06 2015 UTC (3 years, 3 months ago) by adrian
File MIME type: text/x-chdr
File size: 5181 byte(s)
Added dialog boxes for when and logrel types
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, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef ASCXX_INSTANCE_H
19 #define ASCXX_INSTANCE_H
20
21 #include "symchar.h"
22 #include "type.h"
23 #include "set.h"
24 #include "dimensions.h"
25
26 class Plot;
27
28 #include "config.h"
29 extern "C"{
30 #include <ascend/general/platform.h>
31 #include <ascend/utilities/error.h>
32 #include <ascend/compiler/expr_types.h>
33 #include <ascend/compiler/instance_enum.h>
34 #include <ascend/compiler/atomvalue.h>
35 #include <ascend/compiler/plot.h>
36 }
37
38 #include <string>
39 #include <vector>
40
41 typedef enum{
42 ASCXX_INST_STATUS_UNKNOWN=0, ASCXX_VAR_FIXED, ASCXX_VAR_UNSOLVED, ASCXX_VAR_ACTIVE, ASCXX_VAR_SOLVED
43 , ASCXX_REL_INACTIVE
44 } InstanceStatus;
45
46 /**
47 This class has to be called 'Instanc' in C++ to avoid a name clash
48 with C. Maybe coulda done it with namespaces but didn't know how.
49
50 This class is renamed back to 'Instance' by SWIG, so use 'Instance'
51 when you're in Python.
52
53 The Right Way to implement this class would be as a base class
54 with lots of diffent subclasses for the different atom types.
55 Maybe even multiple inheritance.
56
57 But until the underlying C code is ported to C++ or modularised in
58 some other way, it's not going to be worth the effort. We discussed
59 this in the mailing list.
60 */
61 class Instanc{
62 protected:
63 struct Instance *i;
64 SymChar name;
65 std::vector<Instanc> children;
66 void setName(SymChar);
67 static SymChar fixedsym;
68 static SymChar solvervarsym;
69 public:
70 Instanc();
71 Instanc(Instance *i);
72 Instanc(Instance *i, const SymChar &name);
73 Instanc(const Instanc &parent, const unsigned long &childnum);
74 Instanc(const Instanc&);
75 ~Instanc();
76 std::vector<Instanc> &getChildren();
77 Instanc getChild(const SymChar &) const;
78 Instanc getChild(const long &) const;
79 const enum inst_t getKind() const;
80 const std::string getKindStr() const;
81 const Type getType() const;
82 const bool isAtom() const;
83 const bool isFixed() const;
84 const bool isIncluded() const;
85
86 const bool isFund() const;
87 const bool isConst() const;
88 const bool isCompound() const;
89 const bool isRelation() const;
90 const bool isLogicalRelation() const;
91 const bool isWhen() const;
92 const bool isSet() const;
93 const bool isSetInt() const;
94 const bool isSetString() const;
95 const bool isSetEmpty() const; // set of of type 'empty', NB not same as SetInt::length()==0
96 const bool isArray() const;
97 const bool isDefined() const;
98 const bool isChildless() const;
99 const bool isBool() const;
100 const bool isInt() const;
101 const bool isSymbol() const;
102 const bool isReal() const;
103 const bool isAssigned() const;
104 const bool isModel() const;
105 const SymChar &getName() const;
106 const double getRealValue() const;
107 const bool isDimensionless() const;
108 const Dimensions getDimensions() const;
109 const bool getBoolValue() const;
110 const long getIntValue() const;
111 const SymChar getSymbolValue() const;
112
113 const std::string getWhenAsString(const Instanc &relative_to) const;
114 const std::string getLogrelAsString(const Instanc &relative_to) const;
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(const char *fname) 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 const std::vector<std::string> getAliases() const;
158
159 const double getResidual() const;
160 const bool getLogicalResidual() const;
161 };
162
163 #endif
164

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