Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

parameterlist.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: parameterlist.cpp,v 1.8 2004/12/19 14:06:42 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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     // try to generate a string from a float, double or int
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   The following declarations are here to force the compiler to
00278   generate a type_info object for the template classes
00279   boost::holder<>. Several plugins, e.g. PerfectVisionPerceptor and
00280   SexpParser rely on the runtime type information to generate and
00281   parse ParameterLists.
00282 
00283   If these declarations are omitted the linker does not resolve the
00284   separately generated type_info classes for each module and a
00285   comparison between otherwise identical types fails.
00286 
00287   Strictly it would be sufficient to typedef two instances of the
00288   boost::holder<> class. But as this class is an implementation detail
00289   of boost I chose the more portable way and went with it's public
00290   wrapper boost:any.
00291 
00292   The following declarations are unfortunately needed for all
00293   structured types used inside a TParameterList. Currently this only
00294   is std::string and the TParameterList itself to allow nesting of
00295   parameter lists.
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 

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4