MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00005 00010 //---------------------------------------------------------------------------------- 00011 #ifndef __mlMultiFields_H 00012 #define __mlMultiFields_H 00013 00014 #ifndef __MLToolsSystem_H 00015 #include "MLToolsSystem.h" 00016 #endif 00017 00018 #ifndef __mlField_H 00019 #include <mlField.h> 00020 #endif 00021 00022 ML_START_NAMESPACE 00023 00024 //------------------------------------------------------------------------- 00026 //------------------------------------------------------------------------- 00027 00028 //------------------------------------------------------------------------- 00030 //------------------------------------------------------------------------- 00031 template <class DATATYPE> inline std::ostream& operator<<(std::ostream& s, const std::vector<DATATYPE>& vec) 00032 { 00033 ML_TRACE_IN("MultiField::operator<<"); 00034 00035 s.precision(8); 00036 for (size_t i = 0; i < vec.size(); i++) { 00037 s << vec[i] << " "; 00038 } 00039 return s; 00040 } 00041 00042 //------------------------------------------------------------------------- 00044 //------------------------------------------------------------------------- 00045 template <class DATATYPE> inline std::istream& operator>>(std::istream& s, std::vector<DATATYPE>& vec) 00046 { 00047 ML_TRACE_IN("MultiField::operator>>"); 00048 00049 vec.clear(); 00050 DATATYPE i=0; 00051 while (s >> i) { 00052 vec.push_back(i); 00053 } 00054 return s; 00055 } 00056 00057 00058 //---------------------------------------------------------------------------------- 00060 //---------------------------------------------------------------------------------- 00061 template <class DATATYPE> class MultiField : public Field { 00062 00063 public: 00064 //---------------------------------------------------------------------------- 00068 //---------------------------------------------------------------------------- 00069 inline MultiField(const std::string &name="") : Field(name) 00070 { 00071 ML_TRACE_IN("MultiField::MultiField()"); 00072 } 00073 00074 //---------------------------------------------------------------------------- 00079 //---------------------------------------------------------------------------- 00080 inline void setStringValue(const std::string &value) 00081 { 00082 ML_TRACE_IN("MultiField::setStringValue()"); 00083 00084 ML_TRY 00085 { 00086 std::istringstream ist(value); 00087 ist >> _fields; 00088 Field::touch(); 00089 } 00090 ML_CATCH_RETHROW 00091 } 00092 00093 //---------------------------------------------------------------------------- 00095 //---------------------------------------------------------------------------- 00096 inline void setMultiField(const std::vector<DATATYPE> &value) 00097 { 00098 ML_TRACE_IN("MultiField::setMultiField()"); 00099 00100 ML_TRY 00101 { 00102 _fields = value; 00103 Field::touch(); 00104 } 00105 ML_CATCH_RETHROW 00106 } 00107 00108 //---------------------------------------------------------------------------- 00112 //---------------------------------------------------------------------------- 00113 inline void setMultiField(const DATATYPE values[], size_t numValues) 00114 { 00115 ML_TRACE_IN("MultiField::setMultiField()"); 00116 00117 ML_TRY 00118 { 00119 if (NULL == values){ 00120 ML_PRINT_FATAL_ERROR("MultiField::setMultiField", 00121 ML_BAD_POINTER_OR_0, 00122 "Ignoring function call"); 00123 } 00124 else{ 00125 // Be sure that vector has enough entries. 00126 _fields.resize(numValues); 00127 00128 // Copy values into field vector. 00129 for (size_t c=0; c < numValues; ++c){ _fields[c] = values[c]; } 00130 00131 // Sent change signal to observers. 00132 Field::touch(); 00133 } 00134 } 00135 ML_CATCH_RETHROW 00136 } 00137 00138 //---------------------------------------------------------------------------- 00146 //---------------------------------------------------------------------------- 00147 inline void getMultiField(DATATYPE values[], size_t numValues) 00148 { 00149 ML_TRACE_IN("MultiField::getMultiField()"); 00150 00151 ML_TRY 00152 { 00153 if (NULL == values){ 00154 ML_PRINT_FATAL_ERROR("MultiField::getMultiField", 00155 ML_BAD_POINTER_OR_0, 00156 "Ignoring function call"); 00157 } 00158 else{ 00159 // Read at most the number of values available in the fields. 00160 if (numValues > _fields.size()){ numValues = _fields.size(); } 00161 00162 // Copy values to return array. 00163 for (size_t c=0; c < numValues; ++c){ values[c] = _fields[c]; } 00164 } 00165 } 00166 ML_CATCH_RETHROW 00167 } 00168 00169 //---------------------------------------------------------------------------- 00171 //---------------------------------------------------------------------------- 00172 inline std::string getStringValue() const 00173 { 00174 ML_TRACE_IN("MultiField::getStringValue()"); 00175 00176 ML_TRY 00177 { 00178 std::ostringstream ost; 00179 ost << _fields; 00180 return ost.str(); 00181 } 00182 ML_CATCH_RETHROW 00183 } 00184 00185 //---------------------------------------------------------------------------- 00187 //---------------------------------------------------------------------------- 00188 inline const std::vector<DATATYPE>& getMultiField() const 00189 { 00190 ML_TRACE_IN_TIME_CRITICAL("MultiField::getMultiField()"); 00191 00192 return _fields; 00193 } 00194 00195 //---------------------------------------------------------------------------- 00197 //---------------------------------------------------------------------------- 00198 inline std::vector<DATATYPE>& getNonConstMultiField() 00199 { 00200 ML_TRACE_IN_TIME_CRITICAL("MultiField::getNonConstMultiField()"); 00201 00202 return _fields; 00203 } 00204 00205 //---------------------------------------------------------------------------- 00207 //---------------------------------------------------------------------------- 00208 inline size_t getSize() const 00209 { 00210 ML_TRACE_IN_TIME_CRITICAL("MultiField::getSize()"); 00211 00212 return _fields.size(); 00213 } 00214 00215 private: 00217 std::vector<DATATYPE> _fields; 00218 }; 00219 00220 //------------------------------------------------------------------------- 00221 // Instantiations of different multi fields 00222 //------------------------------------------------------------------------- 00223 00224 #if !defined(_WIN32) && !defined(WIN32) && !defined(MACOS) 00225 00226 // Needed to force instantiation of these types, because under linux 00227 // otherwise link problems may occur, because symbols of these specializations 00228 // otherwise are not created. See Stroustrup, 13, 2.7. 00229 template class MultiField<MLdouble>; 00230 template class MultiField<MLfloat>; 00231 template class MultiField<MLint>; 00232 template class MultiField<MLint32>; 00233 template class MultiField<MLuint32>; 00234 00235 #endif 00236 00237 00238 #ifdef WIN32 00239 00240 #pragma warning( push ) 00241 00245 #pragma warning(disable : 4275 ) 00246 #endif 00247 00248 //------------------------------------------------------------------------- 00249 //------------------------------------------------------------------------- 00250 // Instantiations of different multi fields 00251 //------------------------------------------------------------------------- 00253 class MLTOOLS_EXPORT DoubleMultiField : public MultiField<MLdouble> 00254 { 00255 public: 00257 DoubleMultiField(const std::string &name=""); 00258 00261 ML_CLASS_HEADER(DoubleMultiField); 00262 }; 00263 00264 //------------------------------------------------------------------------- 00266 //------------------------------------------------------------------------- 00267 class MLTOOLS_EXPORT FloatMultiField : public MultiField<MLfloat> 00268 { 00269 public: 00271 FloatMultiField(const std::string &name=""); 00272 00275 ML_CLASS_HEADER(FloatMultiField); 00276 }; 00277 00278 //------------------------------------------------------------------------- 00280 //------------------------------------------------------------------------- 00281 class MLTOOLS_EXPORT IntMultiField : public MultiField<MLint> 00282 { 00283 public: 00285 IntMultiField(const std::string &name=""); 00286 00289 ML_CLASS_HEADER(IntMultiField); 00290 }; 00291 00292 //------------------------------------------------------------------------- 00294 //------------------------------------------------------------------------- 00295 class MLTOOLS_EXPORT Int32MultiField : public MultiField<MLint32> 00296 { 00297 public: 00299 Int32MultiField(const std::string &name=""); 00300 00303 ML_CLASS_HEADER(Int32MultiField); 00304 }; 00305 00306 //------------------------------------------------------------------------- 00308 //------------------------------------------------------------------------- 00309 class MLTOOLS_EXPORT UInt32MultiField : public MultiField<MLuint32> 00310 { 00311 public: 00313 UInt32MultiField(const std::string &name=""); 00314 00317 ML_CLASS_HEADER(UInt32MultiField); 00318 }; 00319 00320 #ifdef WIN32 00321 00322 #pragma warning( pop ) 00323 #endif 00324 00325 ML_END_NAMESPACE 00326 00327 #endif //__mlMultiFields_H