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

VxSegment.h

00001 /*
00002  *  VxSegment
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: added comparison function lesser for segments.
00017  * JV, 04Sep01: added intersect function
00018  * JV, 04Sep01: converted std namespace functions to Horus approach
00019  */
00020 
00021 
00022 #ifndef VxSegment_h
00023 #define VxSegment_h
00024 
00025 #include "HxFeatureMap.h"
00026 #include "HxIo.h"
00027 //using namespace std;
00028 
00029 class VxSegment
00030 {
00031 public:
00032 
00034                             VxSegment();
00035 
00037                             VxSegment(const int start, const int end);
00038 
00040                             VxSegment(const std::vector<HxString>& ids, const std::vector<HxString>& types, const HxString& str);
00041 
00043                             VxSegment(const VxSegment&);
00044 
00046     virtual                 ~VxSegment();
00047 
00049     VxSegment&              operator=(const VxSegment& rhs);
00050 
00052     VxSegment*              clone();
00053 
00055     int                     start() const;
00056 
00058     int                     end()   const;
00059 
00061     int                     length()  const;
00062 
00063 
00067     template<class T>
00068     HxFeatureResult         push(const HxString &id, const T& val)
00069                             {
00070                                 return _data->_fMap.push(id,val);
00071                             }
00072 
00073     HxFeatureResult         push(const HxString &id, HxFeatureBase* feat)
00074                             {
00075                                 return _data->_fMap.push(id,feat);
00076                             }
00077 
00082     template<class T>
00083     HxFeatureResult         get(const HxString& id, T& val) const
00084                             {
00085                                 return _data->_fMap.get(id,val);
00086                             }
00087 
00089     template<class T>
00090     bool                    compare(const HxString& id, const T& val) const
00091                             {
00092                                 return _data->_fMap.compare(id,val);
00093                             }
00094 
00095 
00097     const HxFeatureBase*    get(const HxString& id) const;
00098 
00101     std::vector<HxString>   getIds() const;
00102 
00105     std::vector<HxString>   getTypes() const;
00106     
00108     STD_OSTREAM&            put(STD_OSTREAM& os = STD_COUT, const std::vector<HxString>& fm = std::vector<HxString>()) const;
00109 
00113     VxSegment               intersect(const VxSegment& seg) const;
00114 private:
00115     void                    scanString(const std::vector<HxString>& ids, const std::vector<HxString>& types, const HxString& str);
00116 
00117     struct VxSegmentRep {
00118         int                 _start, _end;
00119         HxFeatureMap        _fMap;
00120         int                 refCount;
00121         VxSegmentRep()      { refCount = 1;}
00122     };
00123 
00124     VxSegmentRep*           _data;
00125 };
00126 
00132     bool                    lesser(const VxSegment s1, const VxSegment s2);
00133                             
00134 
00135 inline
00136 STD_OSTREAM& operator<<(STD_OSTREAM& os, const VxSegment seg) {
00137     return seg.put(os);
00138 }
00139 
00140 inline
00141 VxSegment::VxSegment() 
00142 // : _start(-1), _end(-1)
00143 {
00144     _data = new VxSegmentRep();
00145     _data->_start=-1;
00146     _data->_end=-1;
00147 }
00148 
00149 inline
00150 VxSegment::VxSegment(const int start, const int end)
00151 //: _start(start), _end(end) 
00152 {
00153     _data = new VxSegmentRep();
00154     _data->_start=start;
00155     _data->_end=end;
00156 }
00157 
00158 inline
00159 VxSegment::VxSegment(const std::vector<HxString>& ids, const std::vector<HxString>& types, const HxString& str) {
00160     _data = new VxSegmentRep(); 
00161     scanString(ids, types, str);
00162 }
00163 
00164 inline
00165 VxSegment::VxSegment(const VxSegment& his)
00166     : _data(his._data)
00167 // : _start(his._start), _end(his._end), _fMap(his._fMap) 
00168 {
00169     _data->refCount++;  
00170 }
00171 
00172 inline
00173 VxSegment::~VxSegment() {
00174     _data->refCount--;
00175     if (_data->refCount == 0)   
00176         delete _data;
00177 }
00178 
00179 inline VxSegment& 
00180 VxSegment::operator=(const VxSegment& rhs)
00181 {
00182     if (--_data->refCount<= 0 && _data != rhs._data)
00183         delete _data;
00184     (_data=rhs._data)->refCount++;     
00185     return *this;
00186 }
00187 
00188 inline
00189 VxSegment*
00190 VxSegment::clone() {
00191     return new VxSegment(*this);
00192 }
00193 
00194 inline int
00195 VxSegment::start() const { 
00196     return _data->_start; 
00197 }
00198 
00199 inline int
00200 VxSegment::end() const { 
00201     return _data->_end; 
00202 }
00203 
00204 inline int 
00205 VxSegment::length() const {
00206     return (_data->_end-_data->_start+1);
00207 }
00208 
00209 inline const HxFeatureBase*
00210 VxSegment::get(const HxString& id) const
00211 {
00212     return _data->_fMap.get(id);
00213 }
00214     
00215 inline std::vector<HxString>
00216 VxSegment::getIds() const
00217 {
00218     return _data->_fMap.getIds();
00219 }
00220     
00221 inline std::vector<HxString>
00222 VxSegment::getTypes() const
00223 {
00224     return _data->_fMap.getTypes();
00225 }
00226 
00227 #endif

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