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

Contents of /trunk/pygtk/solverparameters.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1228 - (show annotations) (download) (as text)
Thu Jan 25 06:57:40 2007 UTC (12 years, 9 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2014 byte(s)
Added getParameter by name in SolverParameters.
Fixed up refences to signal-related header files.
Fixed up various warnings from -pedantic compilation.
Identified an apparent bug with RelationCalcGradient (unsafe version).
Added support for compilation of a standalone C++ program (idatest) in SCons build.
1 #include "solverparameters.h"
2 #include "solverparameteriterator.h"
3
4 #include <iostream>
5 #include <sstream>
6 #include <stdexcept>
7 using namespace std;
8
9 //-------------------------------
10 // SolverParameters
11
12 SolverParameters::SolverParameters(const slv_parameters_t &p) : p(p){
13 cerr << "CREATED SOLVERPARAMETERS" << endl;
14 }
15
16 SolverParameters::SolverParameters(){
17 /* cerr << "CONSTRUCTED SOLVERPARAMETERS NULL" << endl; */
18 }
19
20 SolverParameters::SolverParameters(const SolverParameters &old) : p(old.p){
21 // copy constructor
22 }
23
24 const string
25 SolverParameters::toString() const{
26 stringstream ss;
27 ss << "SOLVERPARAMETERS:TOSTRING:" << endl;
28 ss << "Number of parameters: " << p.num_parms << endl;
29
30 iterator i;
31 for(i = begin(); i<end(); ++i){
32 SolverParameter p = *i;
33 #if 0
34 ss << p.getLabel() << " [" << p.getDescription() << "]: ";
35 #else
36 ss << p.getName() << ": ";
37 #endif
38 if(p.isInt()){
39 ss << p.getIntValue();
40 }else if(p.isReal()){
41 ss << p.getRealValue();
42 }else if(p.isBool()){
43 ss << (p.getBoolValue() ? "true" : "false");
44 }else if(p.isStr()){
45 ss << p.getStrValue();
46 }else{
47 throw runtime_error("Unhandled case");
48 }
49 ss << endl;
50 }
51 return ss.str();
52 }
53
54 const SolverParameterIterator
55 SolverParameters::begin() const{
56 return SolverParameterIterator(p.parms);
57 }
58
59 const SolverParameterIterator
60 SolverParameters::end() const{
61 return SolverParameterIterator(p.parms+p.num_parms);
62 }
63
64 const int
65 SolverParameters::getLength() const{
66 return p.num_parms;
67 }
68
69 SolverParameter
70 SolverParameters::getParameter(const int &index) const{
71 return SolverParameter(&(p.parms[index]));
72 }
73
74 SolverParameter
75 SolverParameters::getParameter(const string &name) const{
76 for(int i=0;i<p.num_parms;++i){
77 //cerr << "Looking at " << p.parms[i].name << endl;
78 if(p.parms[i].name==name){
79 return SolverParameter(&(p.parms[i]));
80 }
81 }
82 stringstream ss;
83 ss << "Invalid parameter name '" << name << "'";
84 throw runtime_error(ss.str());
85 }
86
87 slv_parameters_t &
88 SolverParameters::getInternalType(){
89 return p;
90 }
91

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