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

Contents of /trunk/pygtk/solverparameter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

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