00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef __INPUTDATA_H__
00050 #define __INPUTDATA_H__
00051
00052 #include <openfluid/core/TypeDefs.hpp>
00053 #include <openfluid/dllexport.hpp>
00054
00055
00056 namespace openfluid { namespace core {
00057
00058
00059 template <class T>
00060 class DLLEXPORT InputData
00061 {
00062 private :
00063
00064 typedef std::map<InputDataName_t,T> InputDataMap_t;
00065 InputDataMap_t m_Data;
00066
00067 public :
00068
00069 InputData();
00070
00071 ~InputData();
00072
00073 bool setValue(const InputDataName_t aName,const T aValue);
00074
00075 bool getValue(const InputDataName_t aName, T *aValue);
00076
00077 bool getValueAsDouble(const InputDataName_t aName, double *aValue);
00078
00079 bool getValueAsLong(const InputDataName_t aName, long *aValue);
00080
00081 bool isDataExist(const InputDataName_t aName) const;
00082
00083 std::vector<InputDataName_t> getInputDataNames() const;
00084
00085
00086 };
00087
00088
00089
00090
00091
00092
00093 template <class T>
00094 InputData<T>::InputData()
00095 {
00096
00097 }
00098
00099
00100
00101
00102
00103
00104 template <class T>
00105 InputData<T>::~InputData()
00106 {
00107
00108 }
00109
00110
00111
00112
00113
00114 template <class T>
00115 bool InputData<T>::setValue(const InputDataName_t aName,const T aValue)
00116 {
00117
00118 if (isDataExist(aName)) return false;
00119 else
00120 {
00121 m_Data[aName] = aValue;
00122 }
00123 return true;
00124 }
00125
00126
00127
00128
00129
00130
00131 template <class T>
00132 bool InputData<T>::getValue(const InputDataName_t aName, T *aValue)
00133 {
00134 typename InputDataMap_t::iterator it = m_Data.find(aName);
00135
00136 if (it != m_Data.end())
00137 {
00138 *aValue = it->second;
00139 return true;
00140 }
00141 else return false;
00142 }
00143
00144
00145
00146
00147
00148 template <class T>
00149 bool InputData<T>::getValueAsDouble(const InputDataName_t aName, double *aValue)
00150 {
00151 T TValue;
00152 typename InputDataMap_t::iterator it = m_Data.find(aName);
00153
00154 if (it != m_Data.end())
00155 {
00156 TValue = it->second;
00157
00158 std::istringstream iss(TValue);
00159 return !(iss >> (*aValue)).fail();
00160 }
00161 else return false;
00162 }
00163
00164
00165
00166
00167
00168
00169 template <class T>
00170 bool InputData<T>::getValueAsLong(const InputDataName_t aName, long *aValue)
00171 {
00172 T TValue;
00173 typename InputDataMap_t::iterator it = m_Data.find(aName);
00174
00175 if (it != m_Data.end())
00176 {
00177 TValue = it->second;
00178
00179 std::istringstream iss(TValue);
00180 return !(iss >> (*aValue)).fail();
00181 }
00182 else return false;
00183 }
00184
00185
00186
00187
00188
00189
00190 template <class T>
00191 bool InputData<T>::isDataExist(const InputDataName_t aName) const
00192 {
00193 return m_Data.find(aName) != m_Data.end();
00194 }
00195
00196
00197
00198
00199 template <class T>
00200 std::vector<InputDataName_t> InputData<T>::getInputDataNames() const
00201 {
00202 std::vector<InputDataName_t> TheNames;
00203
00204 typename InputDataMap_t::const_iterator it;
00205
00206 for (it = m_Data.begin() ; it != m_Data.end() ; ++it)
00207 {
00208 TheNames.push_back(it->first);
00209 }
00210
00211 return TheNames;
00212
00213 }
00214
00215 } }
00216
00217
00218
00219 #endif