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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2823 - (show annotations) (download) (as text)
Tue Feb 17 06:38:36 2015 UTC (4 years, 8 months ago) by jpye
File MIME type: text/x-chdr
File size: 5030 byte(s)
restored files from non-svn backup

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 getValueAsString() const;
114 const std::string getRelationAsString(const Instanc &relative_to) const;
115 Plot getPlot() const;
116
117 const bool isPlottable() const;
118
119 void setFixed(const bool &val=true);
120 void setIncluded(const bool &val=true);
121 void setBoolValue(const bool&, const unsigned &depth=0);
122 void setIntValue(const long&, const unsigned &depth=0);
123 void setRealValue(const double&, const unsigned &depth=0);
124 void setRealValueWithUnits(double, const char *, const unsigned &depth=0);
125 void setSymbolValue(const SymChar &);
126
127 template<class T>
128 const ASCXX_Set<T> getSetValue() const{
129 if(!isSet()){
130 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not set-valued",getName().toString());
131 return ASCXX_Set<T>();
132 }
133 if(!isConst() && !isDefined()){
134 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
135 return ASCXX_Set<T>();
136 }
137 return ASCXX_Set<T>(SetAtomList(i));
138 }
139
140 const enum set_kind getSetType() const;
141 void write(FILE *fp) const;
142 Instance *getInternalType() const;
143
144 void setStatus(const InstanceStatus &); ///< make this one private, just for friend Simulation?
145 const InstanceStatus getStatus() const;
146
147 void setLowerBound(const double &);
148 void setUpperBound(const double &);
149 void setNominal(const double &);
150 const double getLowerBound() const;
151 const double getUpperBound() const;
152 const double getNominal() const;
153
154 const std::vector<Instanc> getClique() const;
155 const std::vector<std::string> getAliases() const;
156
157 const double getResidual() const;
158 const bool getLogicalResidual() const;
159 };
160
161 #endif
162

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