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

HxFeature.h

00001 /*
00002  *  HxFeature
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 /* JB, 8May01 operator= added, const T _value: const removed */
00015 /* JV, 04Sep01: converted std namespace functions to Horus approach */
00016 
00017 #ifndef HxFeature_h
00018 #define HxFeature_h
00019 
00020 #include "HxToken.h"
00021 #include "HxException.h"
00022 #include "HxImageRep.h"
00023 
00024 class HxFeatureBase {
00025 public:
00027     virtual             ~HxFeatureBase() { };
00028 
00030     virtual 
00031     HxFeatureBase*      clone() const = 0;
00032 
00035     virtual
00036     HxString            getClassName() const = 0;
00037 
00038 
00040     virtual
00041     STD_OSTREAM&        put(STD_OSTREAM& os) const = 0;
00042 
00044     virtual
00045     bool                compare(const HxFeatureBase* feat) const = 0;
00046 
00047     
00048 protected:
00052                         HxFeatureBase() {};
00053 
00054 };
00055 
00056 
00057 template<class T>
00058 class HxFeature : public HxFeatureBase
00059 {
00060 public:
00062                         HxFeature(const T value);
00063 
00065     HxFeature<T>&       operator=(const HxFeature<T>& rhs) {
00066                             this->_value = rhs._value;
00067                             return *this;
00068                         }
00069                         
00071     virtual
00072     HxFeatureBase*      clone() const;
00073 
00075     T                   getvalue() const;
00076 
00079     virtual
00080     HxString            getClassName() const { return HxString(""); };
00081 
00083     virtual
00084     STD_OSTREAM&        put(STD_OSTREAM& os) const;
00085 
00086 
00089     virtual
00090     bool                compare(const HxFeatureBase* value) const;
00091 
00092 
00093 private:
00094 
00095     T                   _value;
00096 };
00097 
00098 template<class T>
00099 inline
00100 HxFeature<T>::HxFeature(const T value) : _value(value) {
00101 }
00102 
00103 template<class T>
00104 inline HxFeatureBase*
00105 HxFeature<T>::clone() const {
00106     return new HxFeature<T>(this->_value);
00107 }
00108 
00109 template<class T>
00110 inline T
00111 HxFeature<T>::getvalue() const {
00112     return _value;
00113 }
00114 
00115 
00116 template<class T>
00117 inline STD_OSTREAM&
00118 HxFeature<T>::put(STD_OSTREAM& os) const {
00119     os << _value;
00120     return os;
00121 }
00122 
00123 template<class T>
00124 inline bool 
00125 HxFeature<T>::compare(const HxFeatureBase* feat) const {
00126     
00127     const HxFeature<T>* ftPtr = dynamic_cast<const HxFeature<T> *>(feat);
00128     if (ftPtr == NULL)
00129         return false;
00130 
00131 #pragma warning (disable : 4800)
00132     return (ftPtr->getvalue() == _value);
00133 #pragma warning (default : 4800)
00134 }
00135 
00136 
00138 inline std::ostream& HxFeature<HxString>    ::put(std::ostream& os) const{
00139     os << "\"" << _value << "\"";
00140     return os;
00141 }
00142 
00143 inline std::ostream& HxFeature<HxImageRep>  ::put(std::ostream& os) const{
00144     os << "HxImageRep object";
00145     return os;
00146 }
00147 
00148 
00150 inline bool HxFeature<HxValue>::compare(const HxFeatureBase* feat) const {
00151     return 0;
00152 }
00153 
00155 HxString HxFeature<int>        ::getClassName() const { return HxString("int"); }
00156 HxString HxFeature<double>     ::getClassName() const { return HxString("double"); }
00157 HxString HxFeature<HxString>   ::getClassName() const { return HxString("string"); }
00158 
00159 
00160 #endif

Generated on Tue Feb 3 14:18:34 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001