Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxFeatureMap.h

00001 /*
00002  *  HxFeatureMap
00003  *
00004  *  Copyright (c) 2000, TNO TPD, The Netherlands.
00005  *  All rights reserved. No part of this software may be handed to or used by persons 
00006  *  or organisation outside Kenniscentrum Watergraafsmeer (UvA-ISIS, TNO TPD) without 
00007  *  the written permission of TNO TPD.
00008  *
00009  *  Author(s):
00010  *      Jan Baan (baan@tpd.tno.nl)
00011  *
00012  */
00013 
00014 /* JV/DK, 20Dec00: changed getIds(vector) into getTypes. */
00015 /* JB/JV, 8 May01: push(HxFeatureBase) added */
00016 /* JV, 04Sep01: converted std namespace functions to Horus approach*/
00017 
00018 #ifndef HxFeatureMap_h
00019 #define HxFeatureMap_h
00020 
00021 #pragma warning( disable : 4786 ) 
00022 
00023 #include <string>
00024 #include <iostream>
00025 #include <map>
00026 #include <vector>
00027 #include "HxFeature.h"
00028 #include "HxString.h"
00029 #include "HxIo.h"
00030 //using namespace std;
00031 
00032 typedef std::map<HxString,HxFeatureBase*> FEATUREMAP;
00033 
00034 enum HxFeatureResult {  
00035         HxFeatureOK = 0,
00036         HxFeatureNotExist,
00037         HxFeatureExist,
00038         HxFeatureOtherType,
00039         HxFeaturePushValue
00040 };
00041 
00042 
00043 class HxFeatureMap
00044 {
00045 public:
00046     typedef FEATUREMAP::const_iterator const_iterator;
00047 
00049                     HxFeatureMap();
00050 
00052                     HxFeatureMap(const HxFeatureMap&);
00053 
00055                     //HxFeatureMap(const string& str);
00056                     
00057                     HxFeatureMap(const std::vector<HxString>& ids, const std::vector<HxString>& format, const HxString& values);
00058 
00060                     ~HxFeatureMap();
00061 
00063     HxFeatureMap&   operator=(const HxFeatureMap& rhs);
00064 
00066     HxFeatureMap*   clone() const;
00067 
00069     bool            exist(const HxString& id, const HxFeatureBase** val = NULL) const;
00070 
00072     HxString            getClassName(const HxString& id) const;
00073  
00075     STD_OSTREAM&        put(STD_OSTREAM& os = STD_COUT, const std::vector<HxString>& ids = std::vector<HxString>()) const;
00076  
00077     
00079     std::vector<HxString>   getIds() const;
00080 
00082     std::vector<HxString>   getTypes() const;
00083 
00085     const
00086     HxFeatureBase*  get(const HxString& id) const;
00087     
00096     template<class T>
00097     HxFeatureResult get(const HxString& id, T& val) const
00098                     {
00099                         if(!exist(id)) return HxFeatureNotExist;
00100                         
00101                         const HxFeature<T>* ftPtr = dynamic_cast<HxFeature<T> *>( _map.find(id)->second);
00102                         if(ftPtr == 0) return HxFeatureOtherType;
00103                         
00104                         val = ftPtr->getvalue();
00105                         return HxFeatureOK;
00106                     }
00107     
00114     template<class T>
00115     HxFeatureResult push(const HxString &id, const T& val)
00116                     {       
00117                         if(exist(id)) return HxFeatureExist;
00118                         
00119                         HxFeature<T> *ftPtr = new HxFeature<T>(val);
00120                         _map[id] = ftPtr;
00121                         return HxFeatureOK;     
00122                     }
00123     HxFeatureResult push(const HxString & id, HxFeatureBase* feat)
00124                     {   
00125                         if(exist(id)) return HxFeatureExist;
00126                         _map[id] = feat;
00127                         return HxFeatureOK;
00128                     }
00129                     
00130     
00136     template<class T>
00137     HxFeatureResult replace(const HxString &id, const T& val) 
00138                     {
00139                         if(!exist(id)) return HxFeatureNotExist;
00140                         delete _map[id];
00141                         HxFeature<T> *ftPtr = new HxFeature<T>(val);
00142                         _map[id] = ftPtr;
00143                         return HxFeatureOK;
00144 
00145                     }
00146     
00148     template<class T>
00149     bool            compare(const HxString& id, const T& val) const
00150                     {
00151                         const HxFeatureBase* fb;
00152                         if(!exist(id,&fb)) {
00153                             return false;
00154                         } else {
00155                             HxFeature<T> fval(val);
00156                             return fb->compare(&fval);
00157                         }
00158                     }
00159 
00161     const_iterator  begin() const { return _map.begin(); }
00162 
00164     const_iterator  end() const { return _map.end(); }
00165 
00166 private:
00167     
00168     FEATUREMAP      _map;
00169     
00170 };
00171 
00172 
00173 inline HxFeatureMap& 
00174 HxFeatureMap::operator=(const HxFeatureMap& rhs)
00175 {
00176     _map=rhs._map;      
00177     return *this;
00178 }
00179 
00180 inline HxFeatureMap*
00181 HxFeatureMap::clone() const {
00182     return new HxFeatureMap(*this);
00183 }
00184 
00185 inline HxString
00186 HxFeatureMap::getClassName(const HxString& id) const
00187 {
00188     const HxFeatureBase* fb;
00189     if(!exist(id,&fb))
00190         return HxString("NOTEXIST");
00191     
00192     return fb->getClassName();
00193     //return _map.find(id)->second->getClassName(); 
00194 }
00195 
00196 
00197 
00198 inline const HxFeatureBase*
00199 HxFeatureMap::get(const HxString& id) const
00200 {
00201     const HxFeatureBase *fb;
00202     if(!exist(id,&fb))
00203         return NULL;
00204 
00205     return fb;
00206     //return _map.find(id)->second;
00207 }
00208     
00209 
00210 #endif

Generated on Mon Jan 27 15:48:42 2003 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001