00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "parameterlist.h"
00023 #include <sstream>
00024
00025 using namespace boost;
00026 using namespace zeitgeist;
00027 using namespace std;
00028
00029 ParameterList::ParameterList()
00030 {
00031 }
00032
00033 ParameterList::~ParameterList()
00034 {
00035 }
00036
00037 void
00038 ParameterList::AddValue(const boost::any& value)
00039 {
00040 mList.push_back(value);
00041 }
00042
00043 ParameterList&
00044 ParameterList::AddList()
00045 {
00046 mList.push_back(ParameterList());
00047 return *any_cast<ParameterList>(&mList.back());
00048 }
00049
00050 int
00051 ParameterList::GetSize() const
00052 {
00053 return static_cast<int>(mList.size());
00054 }
00055
00056 bool
00057 ParameterList::IsEmpty() const
00058 {
00059 return mList.empty();
00060 }
00061
00062 void
00063 ParameterList::Clear()
00064 {
00065 mList.clear();
00066 }
00067
00068 void ParameterList::Pop_Front()
00069 {
00070 if (! mList.empty())
00071 {
00072 mList.erase(mList.begin());
00073 }
00074 }
00075
00076 void ParameterList::Pop_Back()
00077 {
00078 if (! mList.empty())
00079 {
00080 mList.erase(mList.end());
00081 }
00082 }
00083
00084 ParameterList::TVector::const_iterator
00085 ParameterList::begin() const
00086 {
00087 return mList.begin();
00088 }
00089
00090 ParameterList::TVector::const_iterator
00091 ParameterList::end() const
00092 {
00093 return mList.end();
00094 }
00095
00096 ParameterList::TVector::const_iterator
00097 ParameterList::operator[] (int n) const
00098 {
00099 if (
00100 (n <0) ||
00101 (n >= static_cast<int>(mList.size()))
00102 )
00103 {
00104 return mList.end();
00105 }
00106
00107 return (mList.begin() + n);
00108 }
00109
00110 ParameterList::TVector::iterator
00111 ParameterList::begin()
00112 {
00113 return mList.begin();
00114 }
00115
00116 ParameterList::TVector::iterator
00117 ParameterList::end()
00118 {
00119 return mList.end();
00120 }
00121
00122 ParameterList::TVector::iterator
00123 ParameterList::operator[] (int n)
00124 {
00125 if (
00126 (n <0) ||
00127 (n >= static_cast<int>(mList.size()))
00128 )
00129 {
00130 return mList.end();
00131 }
00132
00133 return (mList.begin() + n);
00134 }
00135
00136 bool
00137 ParameterList::AdvanceValue(TVector::const_iterator& iter, std::string& value) const
00138 {
00139 char* character;
00140 if (GetValueInternal<char*, char*>(iter,character))
00141 {
00142 value = character;
00143 return true;
00144 }
00145
00146 string str;
00147 if (GetValueInternal<std::string,std::string>(iter,str))
00148 {
00149 value = str;
00150 return true;
00151 }
00152
00153
00154
00155 double d;
00156 if (
00157 (GetValueInternal<float,double>(iter,d)) ||
00158 (GetValueInternal<double,double>(iter,d))
00159 )
00160 {
00161 stringstream ss;
00162 ss << d;
00163 value = ss.str();
00164 return true;
00165 }
00166
00167 int i;
00168 if (GetValueInternal<int,int>(iter,i))
00169 {
00170 stringstream ss;
00171 ss << i;
00172 value = ss.str();
00173 return true;
00174 }
00175
00176 return false;
00177 }
00178
00179 bool
00180 ParameterList::AdvanceValue(TVector::const_iterator& iter, float& value) const
00181 {
00182 return
00183 (
00184 (GetValueInternal<float,float>(iter,value)) ||
00185 (GetValueInternal<double,float>(iter,value)) ||
00186 (GetValueInternal<int,float>(iter,value)) ||
00187 (ConvertStringValue<float>(iter, value))
00188 );
00189 }
00190
00191 bool
00192 ParameterList::AdvanceValue(TVector::const_iterator& iter, double& value) const
00193 {
00194 return
00195 (
00196 (GetValueInternal<double,double>(iter,value)) ||
00197 (GetValueInternal<float,double>(iter,value)) ||
00198 (GetValueInternal<int,double>(iter,value)) ||
00199 (ConvertStringValue<double>(iter, value))
00200 );
00201 }
00202
00203 bool
00204 ParameterList::AdvanceValue(TVector::const_iterator& iter, int& value) const
00205 {
00206 return
00207 (
00208 (GetValueInternal<int,int>(iter,value)) ||
00209 (GetValueInternal<unsigned int,int>(iter,value)) ||
00210 (ConvertStringValue<int>(iter, value))
00211 );
00212 }
00213
00214 bool
00215 ParameterList::AdvanceValue(TVector::const_iterator& iter, bool& value) const
00216 {
00217 if
00218 (
00219 (GetValueInternal<bool,bool>(iter,value)) ||
00220 (GetValueInternal<int,bool>(iter,value))
00221 )
00222 {
00223 return true;
00224 }
00225
00226 const any& param = (*iter);
00227 string str;
00228 if (param.type() == typeid(std::string))
00229 {
00230 str = boost::any_cast<std::string>(param);
00231 } else if (param.type() == typeid(char*))
00232 {
00233 str = boost::any_cast<char*>(param);
00234 } else
00235 {
00236 return false;
00237 }
00238
00239 if (str == "true")
00240 {
00241 value = true;
00242 return true;
00243 }
00244
00245 if (str == "false")
00246 {
00247 value = false;
00248 return true;
00249 }
00250
00251 return false;
00252 }
00253
00254 bool
00255 ParameterList::AdvanceValue(TVector::const_iterator& iter, unsigned int& value) const
00256 {
00257 return (
00258 (GetValueInternal<unsigned int,unsigned int>(iter,value)) ||
00259 (GetValueInternal<int,unsigned int>(iter,value)) ||
00260 (ConvertStringValue<unsigned int>(iter, value))
00261 );
00262 }
00263
00264 bool
00265 ParameterList::AdvanceValue(TVector::const_iterator& iter, salt::Vector3f& value) const
00266 {
00267 return GetVectorValue(iter, value);
00268 }
00269
00270 bool
00271 ParameterList::AdvanceValue(TVector::const_iterator& iter, salt::Vector2f& value) const
00272 {
00273 return GetVectorValue(iter, value);
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 namespace
00298 {
00299 const zeitgeist::ParameterList paramList;
00300 const boost::any anyDummyParamList(paramList);
00301
00302 const std::string str;
00303 const boost::any anyStr(str);
00304 };
00305
00306
00307
00308
00309
00310
00311