mi32/vectiter.h

Go to the documentation of this file.
00001 /**
00002  * \file vectiter.h <mi32/vectiter.h>
00003  * \brief Defintions for VECTOR_..._ITERATOR classes
00004  *
00005  * \if NODOC
00006  * $Id: vectiter.h_v 1.8 2005/01/14 21:37:58 mju Exp $
00007  *
00008  * $Log: vectiter.h_v $
00009  * Revision 1.8  2005/01/14 21:37:58  mju
00010  * Add cast to get rid of warning.
00011  *
00012  * Revision 1.7  2003/09/15 13:49:56  fileserver!dwilliss
00013  * Doxygen
00014  *
00015  * Revision 1.6  2002/02/08 23:04:14  scowan
00016  * Changed to use vector class.
00017  *
00018  * Revision 1.5  2002/01/23 22:26:42  scowan
00019  * Added label iterator.
00020  *
00021  * Revision 1.4  2000/09/20 21:47:55  mju
00022  * In op++ check for index past end before accessing item.
00023  *
00024  * Revision 1.3  2000/07/10 19:34:27  mju
00025  * Now uses SpatialTree if available.
00026  *
00027  * Revision 1.2  2000/06/20 14:34:54  mju
00028  * Fix BITARRAY_ITERATOR.
00029  *
00030  * Revision 1.1  2000/06/08 13:21:29  mju
00031  * Initial revision
00032  *
00033  * \endif
00034 **/
00035 
00036 #ifndef  INC_MI32_VECTITER_H
00037 #define  INC_MI32_VECTITER_H
00038 
00039 #ifndef  INC_RVC_VECTOR_H
00040 #include <rvc/vector.h>
00041 #endif
00042 
00043 #ifndef  INC_MI32_ELEMTYPE_H
00044 #include <mi32/elemtype.h>
00045 #endif
00046 
00047 #ifndef  INC_MI32_RECT_H
00048 #include <mi32/rect.h>
00049 #endif
00050 
00051 #ifndef  INC_MI32_BITSET_H
00052 #include <mi32/bitset.h>
00053 #endif
00054 
00055 
00056 class BITARRAY_ITERATOR {
00057 public:
00058 
00059    BITARRAY_ITERATOR (
00060       const UINT8* bitarray,           //!< Bit array to iterate through
00061       INT32 numitems,                  //!< Number of items (not bytes) in bit array
00062       bool testval                     //!< Value to test for
00063       ):
00064       m_bitarray(bitarray),
00065       m_testbit(testval?1:0),
00066       m_skipbyte(testval?0:255)
00067       {
00068       SetNumItems(numitems);
00069       Reset();
00070       }
00071 
00072    BITARRAY_ITERATOR& operator++ (
00073       ) {
00074       ++m_curitem;
00075       if (m_curitem >= m_numitems) return (*this);
00076       if (m_bitarray == 0) {
00077          if (m_testbit == 1) m_curitem = m_numitems;
00078          return (*this);
00079          }
00080 
00081       INT32 idx = m_curitem / 8;
00082       int i = (m_curitem % 8);
00083       if (i != 0 || m_bitarray[idx] != m_skipbyte) {
00084          UINT8 byte = static_cast<UINT8>(m_bitarray[idx] >> i);
00085          for (; (i < 8); ++i) {
00086             if ((byte & 1) == m_testbit) return (*this);
00087             ++m_curitem;
00088             byte >>= 1;
00089             }
00090          }
00091       for (++idx; (idx < m_maxindex && m_bitarray[idx] == m_skipbyte); ++idx) ;
00092       m_curitem = idx * 8;
00093       if (idx < m_maxindex) {
00094          UINT8 byte = m_bitarray[idx];
00095          for (i = 0; (i < 8); ++i) {
00096             if ((byte & 1) == m_testbit) {
00097                m_curitem += i;
00098                break;
00099                }
00100             byte >>= 1;
00101             }
00102          }
00103       return (*this);
00104       }
00105 
00106    //! Dereference operator - returns current item.
00107    INT32 operator* (
00108       ) const {
00109       return (m_curitem);
00110       }
00111 
00112    //! Cast to INT32 - returns current item.
00113    operator INT32 (
00114       ) const {
00115       return (m_curitem);
00116       }
00117 
00118    INT32 GetNumItems (
00119       ) const {
00120       return (m_numitems);
00121       }
00122 
00123    //! Determine if done iterating through items.
00124    bool IsDone (
00125       ) const {
00126       return (m_curitem >= m_numitems);
00127       }
00128 
00129    //! Reset iterator to first selected item.
00130    void Reset (
00131       ) {
00132       m_curitem = -1;
00133       operator++();
00134       return;
00135       }
00136 
00137    //! Set iterator to end.
00138    void SetDone (
00139       ) {
00140       m_curitem = m_numitems;
00141       return;
00142       }
00143 
00144    //! Set number of items in bit array.
00145    //! Does not change current iterator position.
00146    void SetNumItems (
00147       INT32 numitems
00148       ) {
00149       if (m_bitarray != 0 || m_testbit == 0) {
00150          m_numitems = numitems;
00151          m_maxindex = (numitems + 7) / 8;
00152          }
00153       else {
00154          //! NULL bitarray is all "false" so if want "true" then no items to iterate through
00155          m_numitems = -1;
00156          }
00157       return;
00158       }
00159 
00160    //! Set bit value to test for.
00161    //! Does not reset the iterator position.
00162    void SetTestValue (
00163       bool testval
00164       ) {
00165       m_testbit = (testval) ? 1 : 0;
00166       m_skipbyte = (testval) ? 0 : 255;
00167       return;
00168       }
00169 
00170 private:
00171    #ifndef GENERATING_DOXYGEN_OUTPUT
00172    const UINT8* m_bitarray;
00173    UINT8 m_testbit;
00174    UINT8 m_skipbyte;
00175    INT32 m_maxindex;
00176    INT32 m_numitems;
00177    INT32 m_curitem;
00178 
00179    BITARRAY_ITERATOR (
00180       const BITARRAY_ITERATOR& rhs
00181       );
00182    BITARRAY_ITERATOR& operator= (
00183       const BITARRAY_ITERATOR& rhs
00184       );
00185    #endif // GENERATING_DOXYGEN_OUTPUT
00186    };
00187 
00188 
00189 //! Base class for vector element iterators.
00190 class VECTOR_ELEM_ITERATOR {
00191 public:
00192    // CONSTRUCTION / DESTRUCTION
00193 
00194    #ifndef GENERATING_DOXYGEN_OUTPUT   
00195    class FILTER;
00196    #endif //!< GENERATING_DOXYGEN_OUTPUT
00197 
00198    explicit VECTOR_ELEM_ITERATOR (
00199       const RVC::VECTOR& VectorObj,
00200       ELEMTYPE elemtype,
00201       const DRECT2D* extents,
00202       const UINT8* bitarray,
00203       bool bittestval,
00204       FILTER* FilterFunc
00205       );
00206 
00207    virtual ~VECTOR_ELEM_ITERATOR (
00208       ) = 0;
00209 
00210    // OPERATORS
00211 
00212    //! Dereference operator - Returns current element.
00213    INT32 operator* (
00214       ) const {
00215       return (m_bititer);
00216       }
00217 
00218    //! Cast to INT32 - Returns current element.
00219    operator INT32 (
00220       ) const {
00221       return (m_bititer);
00222       }
00223 
00224    // METHODS
00225 
00226    //! Determine if at end of elements.
00227    bool IsDone (
00228       ) const {
00229       return (m_bititer.IsDone());
00230       }
00231 
00232    //! Set value to test for in bit array.
00233    void SetTestValue (
00234       bool testval
00235       ) {
00236       m_bititer.SetTestValue(testval);
00237       return;
00238       }
00239 
00240 protected:
00241    // MEMBERS
00242    const RVC::VECTOR& m_VectorObj;
00243    ELEMTYPE m_elemtype;
00244    bool m_UseExtents;
00245    bool m_UseSpatialTree;
00246    DRECT2D m_Extents;
00247    BITARRAY_ITERATOR m_bititer;
00248    FILTER* m_FilterFunc;
00249    BITSET m_streeset;                     //!< Set of elements from SpatialTree
00250 
00251    // METHODS
00252 
00253    void CheckUseExtents (
00254       );
00255 
00256 private:
00257    #ifndef GENERATING_DOXYGEN_OUTPUT
00258    // UNIMPLEMENTED
00259    VECTOR_ELEM_ITERATOR (
00260       const VECTOR_ELEM_ITERATOR& rhs
00261       );
00262    VECTOR_ELEM_ITERATOR& operator= (
00263       const VECTOR_ELEM_ITERATOR& rhs
00264       );
00265    #endif // GENERATING_DOXYGEN_OUTPUT
00266    };
00267 
00268 
00269 class VECTOR_ELEM_ITERATOR::FILTER {
00270    public:
00271       virtual int IteratorFilter (
00272          INT32 ElemNum
00273          ) = 0;
00274    }; 
00275 
00276 
00277 //! Class for iterating through all points in a vector object with optional
00278 //! use of extents rectangle and filter function.
00279 class VECTOR_POINT_ITERATOR : public VECTOR_ELEM_ITERATOR {
00280 public:
00281    // CONSTRUCTION / DESTRUCTION
00282 
00283    explicit VECTOR_POINT_ITERATOR (
00284       const RVC::VECTOR& VectorObj,
00285       const DRECT2D* extents = 0,
00286       const UINT8* bitarray = 0,
00287       bool bittestval = false,
00288       VECTOR_ELEM_ITERATOR::FILTER* FilterFunc = 0
00289       );
00290 
00291    virtual ~VECTOR_POINT_ITERATOR (
00292       );
00293 
00294    // OPERATORS
00295 
00296    VECTOR_POINT_ITERATOR& operator++ (
00297       );
00298 
00299    // METHODS
00300 
00301    //! Get current element header if available.
00302    //! The header is only available if it is needed by the iterator.  This typically
00303    //! occurs if the extents rectangle does not contain the entire vector object extents.
00304    //! In this case it can be significantly more efficient to use the available header
00305    //! rather than reading it from the file again.
00306    //!
00307    //! @return Current element header or NULL if not available.
00308    const RVCVECTPOINT* GetElemInfo (
00309       ) const {
00310       return (m_ElemInfoPtr);
00311       }
00312 
00313    //! Reset to first element.
00314    void Reset (
00315       );
00316 
00317 private:
00318    #ifndef GENERATING_DOXYGEN_OUTPUT
00319    // MEMBERS
00320    RVCVECTPOINT m_ElemInfo;
00321    RVCVECTPOINT *m_ElemInfoPtr;
00322 
00323    // METHODS
00324 
00325    bool TestCurrent ();
00326 
00327    // UNIMPLEMENTED
00328    VECTOR_POINT_ITERATOR (
00329       const VECTOR_POINT_ITERATOR& rhs
00330       );
00331    VECTOR_POINT_ITERATOR& operator= (
00332       const VECTOR_POINT_ITERATOR& rhs
00333       );
00334    #endif // GENERATING_DOXYGEN_OUTPUT
00335    };
00336 
00337 
00338 //! Class for iterating through all nodes in a vector object with optional
00339 //! use of extents rectangle and filter function.
00340 class VECTOR_NODE_ITERATOR : public VECTOR_ELEM_ITERATOR {
00341 public:
00342    // CONSTRUCTION / DESTRUCTION
00343 
00344    explicit VECTOR_NODE_ITERATOR (
00345       const RVC::VECTOR& VectorObj,
00346       const DRECT2D* extents = 0,
00347       const UINT8* bitarray = 0,
00348       bool bittestval = false,
00349       VECTOR_ELEM_ITERATOR::FILTER* FilterFunc = 0
00350       );
00351 
00352    virtual ~VECTOR_NODE_ITERATOR (
00353       );
00354 
00355    // OPERATORS
00356 
00357    VECTOR_NODE_ITERATOR& operator++ (
00358       );
00359 
00360    // METHODS
00361 
00362    //! Get current element header if available.
00363    //! The header is only available if it is needed by the iterator.  This typically
00364    //! occurs if the extents rectangle does not contain the entire vector object extents.
00365    //! In this case it can be significantly more efficient to use the available header
00366    //! rather than reading it from the file again.
00367    //!
00368    //! @return Current element header or NULL if not available.
00369    const RVCVECTNODE* GetElemInfo (
00370       ) const {
00371       return (m_ElemInfoPtr);
00372       }
00373 
00374    //! Reset to first element.
00375    void Reset (
00376       );
00377 
00378 private:
00379    #ifndef GENERATING_DOXYGEN_OUTPUT
00380    // MEMBERS
00381    RVCVECTNODE m_ElemInfo;
00382    RVCVECTNODE *m_ElemInfoPtr;
00383 
00384    // METHODS
00385 
00386    bool TestCurrent ();
00387 
00388    // UNIMPLEMENTED
00389    VECTOR_NODE_ITERATOR (
00390       const VECTOR_NODE_ITERATOR& rhs
00391       );
00392    VECTOR_NODE_ITERATOR& operator= (
00393       const VECTOR_NODE_ITERATOR& rhs
00394       );
00395    #endif // GENERATING_DOXYGEN_OUTPUT
00396    };
00397 
00398 
00399 //! Class for iterating through all lines in a vector object with optional
00400 //! use of extents rectangle and filter function.
00401 class VECTOR_LINE_ITERATOR : public VECTOR_ELEM_ITERATOR {
00402 public:
00403    // CONSTRUCTION / DESTRUCTION
00404 
00405    explicit VECTOR_LINE_ITERATOR (
00406       const RVC::VECTOR& VectorObj,
00407       const DRECT2D* extents = 0,
00408       const UINT8* bitarray = 0,
00409       bool bittestval = false,
00410       VECTOR_ELEM_ITERATOR::FILTER* FilterFunc = 0
00411       );
00412 
00413    virtual ~VECTOR_LINE_ITERATOR (
00414       );
00415 
00416    // OPERATORS
00417 
00418    VECTOR_LINE_ITERATOR& operator++ (
00419       );
00420 
00421    // METHODS
00422 
00423    //! Get current element header if available.
00424    //! The header is only available if it is needed by the iterator.  This typically
00425    //! occurs if the extents rectangle does not contain the entire vector object extents.
00426    //! In this case it can be significantly more efficient to use the available header
00427    //! rather than reading it from the file again.
00428    //!
00429    //! @return Current element header or NULL if not available.
00430    const RVCVECTLINE* GetElemInfo (
00431       ) const {
00432       return (m_ElemInfoPtr);
00433       }
00434 
00435    //! Reset to first element.
00436    void Reset (
00437       );
00438 
00439 private:
00440    #ifndef GENERATING_DOXYGEN_OUTPUT
00441    // MEMBERS
00442    RVCVECTLINE m_ElemInfo;
00443    RVCVECTLINE *m_ElemInfoPtr;
00444 
00445    // METHODS
00446 
00447    bool TestCurrent ();
00448 
00449    // UNIMPLEMENTED
00450    VECTOR_LINE_ITERATOR (
00451       const VECTOR_LINE_ITERATOR& rhs
00452       );
00453    VECTOR_LINE_ITERATOR& operator= (
00454       const VECTOR_LINE_ITERATOR& rhs
00455       );
00456    #endif // GENERATING_DOXYGEN_OUTPUT
00457    };
00458 
00459 
00460 //! Class for iterating through all polygons in a vector object with optional
00461 //! use of extents rectangle and filter function.
00462 class VECTOR_POLYGON_ITERATOR : public VECTOR_ELEM_ITERATOR {
00463 public:
00464    // CONSTRUCTION / DESTRUCTION
00465 
00466    explicit VECTOR_POLYGON_ITERATOR (
00467       const RVC::VECTOR& VectorObj,
00468       const DRECT2D* extents = 0,
00469       const UINT8* bitarray = 0,
00470       bool bittestval = false,
00471       VECTOR_ELEM_ITERATOR::FILTER* FilterFunc = 0,
00472       bool SkipIslands = false
00473       );
00474 
00475    virtual ~VECTOR_POLYGON_ITERATOR (
00476       );
00477 
00478    // OPERATORS
00479 
00480    VECTOR_POLYGON_ITERATOR& operator++ (
00481       );
00482 
00483    // METHODS
00484 
00485    //! Get current element header if available.
00486    //! The header is only available if it is needed by the iterator.  This typically
00487    //! occurs if the extents rectangle does not contain the entire vector object extents.
00488    //! In this case it can be significantly more efficient to use the available header
00489    //! rather than reading it from the file again.
00490    //!
00491    //! @return Current element header or NULL if not available.
00492    const RVCVECTPOLY* GetElemInfo (
00493       ) const {
00494       return (m_ElemInfoPtr);
00495       }
00496 
00497    //! Reset to first element.
00498    void Reset (
00499       );
00500 
00501 private:
00502    #ifndef GENERATING_DOXYGEN_OUTPUT
00503    // MEMBERS
00504    RVCVECTPOLY m_ElemInfo;
00505    RVCVECTPOLY *m_ElemInfoPtr;
00506    bool m_SkipIslands;
00507 
00508    // METHODS
00509 
00510    bool TestCurrent ();
00511 
00512    // UNIMPLEMENTED
00513    VECTOR_POLYGON_ITERATOR (
00514       const VECTOR_POLYGON_ITERATOR& rhs
00515       );
00516    VECTOR_POLYGON_ITERATOR& operator= (
00517       const VECTOR_POLYGON_ITERATOR& rhs
00518       );
00519    #endif // GENERATING_DOXYGEN_OUTPUT
00520    };
00521 
00522 
00523 //! Class for iterating through all polygons in a vector object with optional
00524 //! use of extents rectangle and filter function.
00525 class VECTOR_LABEL_ITERATOR : public VECTOR_ELEM_ITERATOR {
00526    public:
00527       // CONSTRUCTION / DESTRUCTION
00528 
00529       explicit VECTOR_LABEL_ITERATOR (
00530          const RVC::VECTOR& VectorObj,
00531          const DRECT2D* extents = 0,
00532          const UINT8* bitarray = 0,
00533          bool bittestval = false,
00534          VECTOR_ELEM_ITERATOR::FILTER* FilterFunc = 0
00535          );
00536 
00537       virtual ~VECTOR_LABEL_ITERATOR (
00538          );
00539 
00540       // OPERATORS
00541 
00542       VECTOR_LABEL_ITERATOR& operator++ (
00543          );
00544 
00545       // METHODS
00546 
00547       //! Get current element header if available.
00548       //! The header is only available if it is needed by the iterator.  This typically
00549       //! occurs if the extents rectangle does not contain the entire vector object extents.
00550       //! In this case it can be significantly more efficient to use the available header
00551       //! rather than reading it from the file again.
00552       //!
00553       //! @return Current element header or NULL if not available.
00554       const RVC::VECTOR::LABEL* GetElemInfo (
00555          ) const {
00556          return (m_ElemInfoPtr);
00557          }
00558 
00559       //! Reset to first element.
00560       void Reset (
00561          );
00562 
00563    private:
00564    #ifndef GENERATING_DOXYGEN_OUTPUT
00565       // MEMBERS
00566       RVC::VECTOR::LABEL m_ElemInfo;
00567       RVC::VECTOR::LABEL* m_ElemInfoPtr;
00568 
00569       // METHODS
00570 
00571       bool TestCurrent ();
00572 
00573       // UNIMPLEMENTED
00574       VECTOR_LABEL_ITERATOR (const VECTOR_LABEL_ITERATOR& rhs);
00575       VECTOR_LABEL_ITERATOR& operator= (const VECTOR_LABEL_ITERATOR& rhs);
00576    #endif // GENERATING_DOXYGEN_OUTPUT
00577    };
00578 
00579 
00580 #endif   //!< INC_MI32_VECTITER_H

Generated on Thu Apr 26 04:45:27 2007 for TNTsdk by  doxygen 1.5.2