Hosted by: BerliOS Developer Logo

OpenMBV C++ Interface

BerliOS Project Page
/home/user/MBSimWindows/openmbv/openmbvcppinterface/openmbvcppinterface/simpleparameter.h
00001 /*
00002     OpenMBV - Open Multi Body Viewer.
00003     Copyright (C) 2009 Markus Friedrich
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #include <vector>
00021 #include <ostream>
00022 #include <openmbvcppinterface/group.h>
00023 
00024 #ifndef _OPENMBV_SIMPLEPARAMETER_H_
00025 #define _OPENMBV_SIMPLEPARAMETER_H_
00026 
00027 namespace OpenMBV {
00028 
00029   typedef SimpleParameter<double> ScalarParameter;
00030   typedef SimpleParameter<std::vector<double> > VectorParameter;
00031   typedef SimpleParameter<std::vector<std::vector<double> > > MatrixParameter;
00032 
00033   template<class T>
00034   class SimpleParameter {
00035     friend class Object;
00036     protected:
00037       T value;
00038       std::string paramStr;
00039       bool addParameter;
00040       SimpleParameter(const std::string& paramStr_) : value(T()), paramStr(paramStr_), addParameter(false) {}
00041     public:
00042       SimpleParameter(const T& value_) : value(value_), paramStr(""), addParameter(true) {}
00043       SimpleParameter(const std::string& paramStr_, const T& value_) : value(value_), paramStr(paramStr_), addParameter(true) {}
00044       friend std::ostream& operator<<(std::ostream &os, const SimpleParameter<T> p) {
00045         if(p.paramStr=="")
00046           os<<p.value;
00047         else
00048           os<<p.paramStr;
00049         return os;
00050       };
00051       std::string getParamStr() const { return paramStr; }
00052       T getValue() const { return value; }
00053       bool getAddParameter() { return addParameter; }
00054   };
00055 
00056   template<class T>
00057   std::ostream& operator<<(std::ostream &os, const std::vector<T> p) {
00058     os<<"[";
00059     for(size_t i=0; i<p.size()-1; i++)
00060       os<<p[i]<<";";
00061     os<<p[p.size()-1]<<"]";
00062     return os;
00063   }
00064 
00065 }
00066 
00067 #endif