/[ascend]/trunk/pygtk/solverparameter.cpp
ViewVC logotype

Contents of /trunk/pygtk/solverparameter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 900 - (show annotations) (download) (as text)
Wed Oct 25 06:03:04 2006 UTC (13 years, 11 months ago) by johnpye
File MIME type: text/x-c++src
File size: 3978 byte(s)
The 'sim' object is correctly accessible from script methods now, even if run during on_load.
Added 'getSimulation' to registry.cpp, added 'runDefaultMethod' to Simulation, added 'getMethod' to Type.
Running of 'on_load' is instigated at the Python level now, so that relevent python variables are set at simulations are built, etc. This appears to have cause some changes to the way the solver behaves, possibly.
Added SearchProcList to exports in libascend.

1 #include "solverparameter.h"
2
3 #include <stdexcept>
4 #include <vector>
5 #include <string>
6 using namespace std;
7
8 SolverParameter::SolverParameter(slv_parameter *p) : p(p){
9 // created new SolverParameter wrapper
10 }
11
12 const std::string
13 SolverParameter::getName() const{
14 if(!p->name){
15 return "";
16 }
17 return string(p->name);
18 }
19
20 const std::string
21 SolverParameter::getDescription() const{
22 return string(p->description);
23 }
24
25 const std::string
26 SolverParameter::getLabel() const{
27 return string(p->interface_label);
28 }
29
30 const int &
31 SolverParameter::getNumber() const{
32 return p->number;
33 }
34
35 const int &
36 SolverParameter::getPage() const{
37 return p->display;
38 }
39
40 // Parameter type tests
41
42 const bool
43 SolverParameter::isBool() const{
44 return p->type == bool_parm;
45 }
46
47 const bool
48 SolverParameter::isInt() const{
49 return p->type == int_parm;
50 }
51
52 const bool
53 SolverParameter::isReal() const{
54 return p->type == real_parm;
55 }
56
57 const bool
58 SolverParameter::isStr() const{
59 return p->type == char_parm;
60 }
61
62 // Integer parameters
63
64 const int &
65 SolverParameter::getIntValue() const{
66 if(!isInt()){
67 throw runtime_error("Not an integer parameter");
68 }
69 return p->info.i.value;
70 }
71
72 const int &
73 SolverParameter::getIntLowerBound() const{
74 if(!isInt()){
75 throw runtime_error("Not an integer parameter");
76 }
77 return p->info.i.low;
78 }
79
80 const int &
81 SolverParameter::getIntUpperBound() const{
82 if(!isInt()){
83 throw runtime_error("Not an integer parameter");
84 }
85 return p->info.i.high;
86 }
87
88 void
89 SolverParameter::setIntValue(const int &val){
90 if(!isInt()){
91 throw runtime_error("Not an integer parameter");
92 }
93 if(isBounded() && (val > getIntUpperBound() || val < getIntLowerBound())){
94 throw runtime_error("Out of bounds");
95 }
96 p->info.i.value = val;
97 }
98
99 // Boolean parameters
100
101 const bool
102 SolverParameter::getBoolValue() const{
103 if(!isBool()){
104 throw runtime_error("Not an boolean parameter");
105 }
106 return p->info.b.value !=0;
107 }
108
109 void
110 SolverParameter::setBoolValue(const bool &val){
111 if(!isBool()){
112 throw runtime_error("Not a boolean parameter");
113 }
114 p->info.b.value = val;
115 }
116
117 // Real parameters
118
119 const double &
120 SolverParameter::getRealValue() const{
121 if(!isReal()){
122 throw runtime_error("Not an real parameter");
123 }
124 return p->info.r.value;
125 }
126
127 const double &
128 SolverParameter::getRealLowerBound() const{
129 if(!isReal()){
130 throw runtime_error("Not an real parameter");
131 }
132 return p->info.r.low;
133 }
134
135 const double &
136 SolverParameter::getRealUpperBound() const{
137 if(!isReal()){
138 throw runtime_error("Not an real parameter");
139 }
140 return p->info.r.high;
141 }
142
143 void
144 SolverParameter::setRealValue(const double &val){
145 if(!isReal()){
146 throw runtime_error("Not a real parameter");
147 }
148 if(isBounded() && (val > getRealUpperBound() || val < getRealLowerBound())){
149 throw runtime_error("Out of bounds");
150 }
151 p->info.r.value = val;
152 }
153
154 // String parameters
155
156 const string
157 SolverParameter::getStrValue() const{
158 if(!isStr()){
159 throw runtime_error("Not a string parameter");
160 }
161 return string(p->info.c.value);
162 }
163
164 const vector<string>
165 SolverParameter::getStrOptions() const{
166 if(!isStr()){
167 throw runtime_error("Not a string parameter");
168 }
169 vector<string> v;
170 for(int i=0; i< p->info.c.high; ++i){
171 v.push_back(p->info.c.argv[i]);
172 }
173 return v;
174 };
175
176 void
177 SolverParameter::setStrOption(const int &opt){
178 if(!isStr()){
179 throw runtime_error("Not a string parameter");
180 }
181 if(opt < 0 || opt > p->info.c.high){
182 throw runtime_error("Invalid option index");
183 }
184 slv_set_char_parameter(&(p->info.c.value),p->info.c.argv[opt]);
185 }
186
187 void
188 SolverParameter::setStrValue(const std::string &str){
189 if(!isStr()){
190 throw runtime_error("Not a string parameter");
191 }
192 slv_set_char_parameter( &(p->info.c.value),str.c_str() );
193 }
194
195 // To String
196
197 const string
198 SolverParameter::toString() const{
199 return "STRING";
200 }
201
202 // Bounded?
203
204 const bool
205 SolverParameter::isBounded() const{
206 if(isInt() && getIntLowerBound() < getIntUpperBound()){
207 return true;
208 }else if(isReal() && getRealLowerBound() < getRealUpperBound()){
209 return true;
210 }
211 return false;
212 }
213
214
215

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