geocat.h

Go to the documentation of this file.
00001 /**
00002  * \file geocat.h <mi32/geocat.h>
00003  * \brief Geographic Catalog (GEOCAT) class
00004  *
00005  * \if NODOC
00006  * $Id: geocat.h_v 1.14 2004/06/30 13:31:09 mju Exp $
00007  *
00008  * $Log: geocat.h_v $
00009  * Revision 1.14  2004/06/30 13:31:09  mju
00010  * Use spatref.
00011  *
00012  * Revision 1.13  2003/09/15 13:49:56  fileserver!dwilliss
00013  * Doxygen
00014  *
00015  * Revision 1.12  2000/10/13 14:57:47  dwilliss
00016  * Must use "friend class NAME", not "friend NAME"
00017  *
00018  * Revision 1.11  2000/09/20 17:47:51  mju
00019  * Add GetProjection() static method.
00020  *
00021  * Revision 1.10  2000/09/13 17:08:28  mju
00022  * Add "findnow" flag to GetObject().
00023  * Add iterator::showprogress().
00024  *
00025  * Revision 1.9  2000/08/16 16:48:02  mju
00026  * *** empty log message ***
00027  *
00028  * Revision 1.8  2000/08/07 20:35:29  mju
00029  * Redesign to always use regions.
00030  *
00031  * Revision 1.5  2000/07/19 22:05:06  dwilliss
00032  * Constructors don't need a GEOCAT passed any more.
00033  *
00034  * Revision 1.4  2000/07/19 17:38:56  dwilliss
00035  * ScanDirectory() now takes an optional StatusContext
00036  *
00037  * Revision 1.3  2000/07/19 16:22:08  dwilliss
00038  * Implementation mostly done.  API nearly final
00039  *
00040  * Revision 1.1  2000/07/17 14:16:42  dwilliss
00041  * Initial revision
00042  * \endif
00043 **/
00044 
00045 
00046 #ifndef INC_MI32_GEOCAT_H
00047 #define INC_MI32_GEOCAT_H
00048 
00049 #ifndef INC_MI32_STDDEFNS_H
00050 #include <mi32/stddefns.h>
00051 #endif
00052 
00053 #ifndef INC_MI32_MISTRING_H
00054 #include <mi32/mistring.h>
00055 #endif
00056 
00057 #ifndef INC_MI32_DATETIME_H
00058 #include <mi32/datetime.h>
00059 #endif
00060 
00061 #ifndef INC_MI32_FILEPATH_H
00062 #include <mi32/filepath.h>
00063 #endif
00064 
00065 #ifndef INC_MI32_RECT_H
00066 #include <mi32/rect.h>
00067 #endif
00068 
00069 #ifndef INC_MI32_POINT_H
00070 #include <mi32/point.h>
00071 #endif
00072 
00073 #ifndef INC_MI32_REGION2D_H
00074 #include <mi32/region2d.h>
00075 #endif
00076 
00077 #ifndef INC_MI32_RVCDBASE_H
00078 #include <mi32/rvcdbase.h>
00079 #endif
00080 
00081 #ifndef INC_MI32_SIMPLEAR_H
00082 #include <mi32/simplear.h>
00083 #endif
00084 
00085 
00086 class STATUSCONTEXT;
00087 
00088 #ifndef GENERATING_DOXYGEN_OUTPUT
00089 //! A class for keeping track of Database Cursors.
00090 //! Should eventually be an RVC class that does the
00091 //! same thing.
00092 class GEOCAT_ITERATOR_CURSOR;    
00093 #endif //!< GENERATING_DOXYGEN_OUTPUT
00094 
00095 //! GeoSpatial Catalog class.
00096 //!
00097 //! This class handles a catalog file.
00098 class GEOCAT {
00099    public:
00100 
00101       //! A file in the object catalog.
00102       class FILERECORD {
00103          public:
00104 
00105             //! Formats.  Only RVC for now.
00106             enum FORMAT {
00107                FORMAT_RVC= 0        //!< XXX Use defines from MIE instead
00108                };
00109 
00110             //! default constructor
00111             FILERECORD (
00112                );
00113 
00114             //! Copy constructor
00115             FILERECORD (
00116                const FILERECORD& rhs
00117                );
00118 
00119             //! Destructor
00120             ~FILERECORD (
00121                );
00122 
00123             //! Assignment from another FILERECORD
00124             FILERECORD& operator= (
00125                const FILERECORD& rhs
00126                );
00127 
00128             UINT32 GetFileID (
00129                ) const {
00130                return (m_ID);
00131                }
00132 
00133             //! Get the filename
00134             const FILEPATH& GetFilePath (
00135                ) const {
00136                return (m_filepath);
00137                }
00138 
00139             FORMAT GetFormat (
00140                ) const {
00141                return (m_Format);
00142                }
00143 
00144             FILEPATH::FILESYSTYPE GetMediaType (
00145                ) const {
00146                return (m_MediaType);
00147                }
00148 
00149             const DATETIME& GetTimeStamp (
00150                ) const {
00151                return (m_TimeStamp);
00152                }
00153 
00154             //! Set the filename.
00155             //! If the filepath passed in is relative, it's assumed to be
00156             //! relative to the catalog file.  
00157             void SetFilePath (
00158                const FILEPATH& filepath
00159                );
00160 
00161          private:
00162             #ifndef GENERATING_DOXYGEN_OUTPUT
00163             //! Used by GEOCAT::Write().
00164             void SetID (
00165                UINT32 id
00166                ) {
00167                m_ID = id;
00168                return;
00169                }
00170 
00171             //! Set timestamp, used by GEOCAT::Write().
00172             void SetTimeStamp (
00173                ) {
00174                time_t modtime;
00175                m_filepath.GetTimeModified(&modtime);
00176                m_TimeStamp = modtime;
00177                return;
00178                }
00179 
00180             UINT32 m_ID;
00181             FILEPATH m_filepath;
00182             DATETIME m_TimeStamp;
00183             FILEPATH::FILESYSTYPE m_MediaType;
00184             FORMAT m_Format;
00185 
00186             friend class GEOCAT;
00187             #endif // GENERATING_DOXYGEN_OUTPUT
00188          };
00189 
00190 
00191       //! An item in the object catalog.
00192       class OBJRECORD {
00193          public:
00194 
00195             //! Default constructor
00196             OBJRECORD (
00197                );
00198 
00199             //! Copy constructor
00200             OBJRECORD (
00201                const OBJRECORD& rhs
00202                );
00203 
00204             //! Destructor
00205             ~OBJRECORD (
00206                );
00207 
00208             //! Assignment from another OBJRECORD
00209             OBJRECORD& operator= (
00210                const OBJRECORD& rhs
00211                );
00212 
00213             //! Return the object description
00214             const MISTRING& GetDescription (
00215                ) const {
00216                return (m_desc);
00217                }
00218 
00219             //! Return the key field value for the FILE record related to this object
00220             INT32 GetFileID (
00221                ) const {
00222                return (m_FileID);
00223                }
00224 
00225             //! Return the full object name for this object.  This is a full name which
00226             //! may contain a path if the object is under a folder in the RVC file.
00227             const MISTRING& GetFullName (
00228                ) const {
00229                return (m_FullName);
00230                }
00231 
00232             //! Return the key field value for this object
00233             INT32 GetID (
00234                ) const {
00235                return (m_ID);
00236                }
00237 
00238             //! Return the object name for this object.
00239             const MISTRING& GetName (
00240                ) const {
00241                return (m_name);
00242                }
00243 
00244             //! Return the OBJTYPE of the object.
00245             INT32 GetObjType (
00246                ) const {
00247                return (m_otype);
00248                }
00249 
00250             //! Get bounding region for object.
00251             const REGION2D& GetRegion (
00252                ) const { return (m_Region); }
00253 
00254             //! Set the object description.
00255             void SetDescription (
00256                const UNICODE* desc
00257                ) { m_desc = desc; }
00258 
00259             //! Set the object description.
00260             void SetDescription (
00261                const MISTRING& desc
00262                ) { m_desc = desc; }
00263 
00264             //! Set the object's file ID.
00265             //! Warning:  The FILERECORD passed in MUST have been written 
00266             //! since writing the record gives it its unique ID.
00267             void SetFile (
00268                const FILERECORD& file
00269                ) { m_FileID = file.GetFileID(); }
00270 
00271             //! Set the full object name.
00272             //! The full name is the name plus object type tags and possibly
00273             //! folder path as returned from MfGetObjectName().
00274             void SetFullName (
00275                const UNICODE* name
00276                ) {
00277                m_FullName = name;
00278                return;
00279                }
00280 
00281             //! Set the full object name.
00282             //! The full name is the name plus object type tags and possibly
00283             //! folder path as returned from MfGetObjectName().
00284             void SetFullName (
00285                const MISTRING& name
00286                ) {
00287                m_FullName = name;
00288                return;
00289                }
00290 
00291             //! Set the object name (name only).
00292             void SetName (
00293                const UNICODE* name
00294                ) {
00295                m_name = name;
00296                return;
00297                }
00298 
00299             //! Set the object name (name only).
00300             void SetName (
00301                const MISTRING& name
00302                ) {
00303                m_name = name;
00304                return;
00305                }
00306 
00307             //! Set the object description
00308             //! (May not need this.  Use SetBasicInfo.)
00309             void SetObjectType (
00310                INT32 otype    //!< XXX Should become an enum when possible
00311                ) {
00312                m_otype = otype;
00313                return;
00314                }
00315 
00316          private:
00317             #ifndef GENERATING_DOXYGEN_OUTPUT
00318 
00319             void SetID (
00320                UINT32 id
00321                ) {
00322                m_ID = id;
00323                return;
00324                }
00325                
00326             UINT32 m_FileID;  
00327             UINT32 m_ID;      
00328             MISTRING m_name;
00329             MISTRING m_FullName;    //!< Full object name
00330             MISTRING m_desc;
00331             int m_otype;
00332             REGION2D m_Region;
00333 
00334             friend class GEOCAT;
00335             #endif // GENERATING_DOXYGEN_OUTPUT
00336          };
00337 
00338       //! Iterator for searching the catalog.
00339       class CONST_ITERATOR {
00340          public:
00341             //! Default constructor
00342             explicit CONST_ITERATOR (
00343                const GEOCAT *cat = 0
00344                ):
00345                m_cat(cat),
00346                m_Cursor(0),
00347                m_bIsEnd(true)
00348                { }
00349 
00350             //! Destructor
00351             ~CONST_ITERATOR (
00352                );
00353 
00354             //! Copy constructor
00355             CONST_ITERATOR (
00356                const CONST_ITERATOR& rhs
00357                );
00358          
00359             //! Assignment from CONST_ITERATOR
00360             CONST_ITERATOR& operator= (
00361                const CONST_ITERATOR& rhs
00362                );
00363 
00364             //! Dereference operator.  Returns reference to item
00365             const OBJRECORD& operator* (
00366                ) const {
00367                return (m_objrec);
00368                }
00369 
00370             //! Dereference operator.  Returns pointer to item
00371             const OBJRECORD* operator-> (
00372                ) const {
00373                return (&m_objrec);
00374                }
00375 
00376             //! Pre-increment operator.
00377             CONST_ITERATOR& operator++ (
00378                );
00379 
00380             //! Equality operator
00381             bool operator== (
00382                const CONST_ITERATOR& rhs
00383                ) const {
00384                return (m_cat == rhs.m_cat && (m_bIsEnd == rhs.m_bIsEnd || m_objrec.GetID() == rhs.m_objrec.GetID()));
00385                }
00386                
00387             //! Inequality operator
00388             bool operator!= (
00389                const CONST_ITERATOR& rhs
00390                ) const {
00391                return (!operator==(rhs));
00392                }
00393 
00394             //! Get "object" associated with current record.
00395             ERRVALUE GetObject (
00396                RVCOBJITEM& objitem,
00397                bool findnow = false
00398                ) const;
00399 
00400             //! Show progress within catalog.
00401             //! Also checks for "cancel" if enabled in status dialog/form.
00402             ERRVALUE ShowProgress (
00403                STATUSCONTEXT& scontext,            //!< Status context
00404                int line = 0                        //!< Line in progress dialog
00405                );
00406                
00407          private:
00408             #ifndef GENERATING_DOXYGEN_OUTPUT
00409 
00410             const GEOCAT* m_cat;
00411             GEOCAT_ITERATOR_CURSOR *m_Cursor;
00412             OBJRECORD m_objrec;
00413             bool m_bIsEnd;    //!< Set when we hit the end
00414 
00415             friend class GEOCAT;
00416             #endif // GENERATING_DOXYGEN_OUTPUT
00417          };
00418 
00419       // XXX If need non-const ITERATOR insert it here...
00420 
00421       //! Get CRS for objects used in catalogs.
00422       static const SPATREF::COORDREFSYS& GetCoordRefSys (
00423          );
00424       
00425       //! Default Constructor.
00426       //! Doesn't open anything.  Use Open or Make methods below.
00427       GEOCAT (
00428          );
00429 
00430       //! Destructor
00431       ~GEOCAT (
00432          );
00433 
00434       //! Return iterator pointing to first item in the catalog.
00435       CONST_ITERATOR Begin (
00436          ) const;
00437 
00438       //! Close the catalog
00439       ERRVALUE Close (
00440          );
00441 
00442       //! Returns an iterator which points one past the end.
00443       const CONST_ITERATOR& End (
00444          ) const {
00445          return (m_EndIterator);
00446          }
00447 
00448       //! Get path to geocatalog file.
00449       const FILEPATH& GetFilePath (
00450          ) const {
00451          return (m_filepath);
00452          }
00453 
00454       //! Retrieve the record for a given file given it's ID.
00455       //! Returns -1 if record not found.
00456       ERRVALUE GetFileRecord (
00457          UINT32 id,
00458          FILERECORD& FileRecord
00459          ) const;
00460 
00461       //! Retrieve the FILERECORD for a given OBJECTRECORD.
00462       //! Returns -1 if record not found.
00463       ERRVALUE GetFileRecord (
00464          const OBJRECORD& ObjRecord,      //!< Object to get File Record for
00465          FILERECORD& FileRecord
00466          ) const {
00467          return (GetFileRecord(ObjRecord.GetFileID(), FileRecord));
00468          }
00469 
00470       //! Retrieve the record for a given file given a filepath pointing to the file.
00471       //! Returns -1 if not found.
00472       ERRVALUE GetFileRecord (
00473          const FILEPATH& filepath,
00474          FILERECORD& record
00475          ) const;
00476 
00477       //! Retrieve the record for a given object given it's ID.
00478       //! Returns -1 if record not found.
00479       ERRVALUE GetObjRecord (
00480          UINT32 id,
00481          OBJRECORD& record
00482          ) const;
00483 
00484       //! Create a catalog file.
00485       ERRVALUE Make (
00486          const FILEPATH& catalog
00487          );
00488 
00489       //! Open a catalog file.
00490       //! Catalog files have the extention ".gsc" for GeoSpatial Catalog
00491       //! May skip open mode parameter.  Just open for read and the scan
00492       //! methods can change it to write as needed.
00493       ERRVALUE Open (
00494          const FILEPATH& catalog,
00495          bool bCreateIfNotFound = false
00496          );
00497       
00498       //! Does a prescan of the directory counting files to index
00499       ERRVALUE PrescanDirectory (
00500          const FILEPATH& dir,
00501          STATUSCONTEXT& StatusContext,
00502          bool bScanSubDirs = true
00503          ) const;
00504 
00505       //! Remove all references to given file from the catalog.
00506       //! If the file is really a directory, it will remove references
00507       //! to all files in the given directory.
00508       ERRVALUE Remove (
00509          const FILEPATH& file
00510          );
00511 
00512       //! Remove all references to given file from the catalog.
00513       ERRVALUE Remove (
00514          const FILERECORD& record
00515          );
00516 
00517       //! Remove the record for a given object.
00518       ERRVALUE Remove (
00519          const OBJRECORD& record
00520          );
00521 
00522       //! Scan all RVC files in a given directory.
00523       //! Also scans the catalog for any files which were in this
00524       //! directory but are not there any more and deletes them from
00525       //! the catalog.
00526       //! If you want to provide status, call PrescanDirectory() to
00527       //! initialize the StatusContext
00528       ERRVALUE ScanDirectory (
00529          const FILEPATH& dir,
00530          STATUSCONTEXT* StatusContext = 0,
00531          bool bScanSubDirs = true
00532          );
00533 
00534       //! Scans an RVC file and adds or updates it's records in the catalog.
00535       //! If already cataloged and time stamp agrees, it won't do anyting.
00536       ERRVALUE ScanFile (
00537          const FILEPATH& file
00538          );
00539 
00540       //! Write an object record.
00541       //! If a record for the given object's ID already exists, it is updated.
00542       //! If the record does not exist, a new record is created, and the record's
00543       //! ID is updated.
00544       ERRVALUE Write (
00545          OBJRECORD& record
00546          );
00547       
00548       //! Write a file record. 
00549       //! If a record for the given file's ID already exists, it's timestamp is updated.
00550       //! If the record does not exist, a new record is created, and the record's
00551       //! ID is updated.
00552       ERRVALUE Write (
00553          FILERECORD& record
00554          );
00555       
00556    private:
00557       #ifndef GENERATING_DOXYGEN_OUTPUT
00558 
00559       ERRVALUE Read (
00560          int RecNum,
00561          FILERECORD& record
00562          ) const;
00563 
00564       ERRVALUE Read (
00565          int RecNum,
00566          OBJRECORD& record
00567          ) const;
00568 
00569       ERRVALUE Read (
00570          GEOCAT_ITERATOR_CURSOR* cursor,
00571          OBJRECORD& record
00572          ) const;
00573 
00574       ERRVALUE ReadObjRecord (
00575          INT32 recnum,
00576          UINT32 recnumtype,
00577          OBJRECORD& record
00578          ) const;
00579 
00580       ERRVALUE ScanFolder (
00581          int fhandle,
00582          RVCINODENUM parentinode,
00583          const FILERECORD& FileRecords
00584          );
00585 
00586       ERRVALUE ScanObject (
00587          int fhandle,
00588          RVCINODENUM objinode,
00589          int objtype,
00590          const FILERECORD& FileRecords
00591          );
00592 
00593       RVCFILEHANDLE m_fhandle;               //!< RVC file handle
00594       int m_dbhandle;                        //!< Database object handle
00595       int m_OpenCount;
00596       int m_FileTableNum;
00597       int m_ObjTableNum;
00598       int m_RgnTableNum;
00599       UINT8* m_recbuf;
00600       INT32 m_BufSize;
00601       FILEPATH m_filepath;
00602       CONST_ITERATOR m_EndIterator;          //!< So we can inline the End() method for much greater efficiency
00603 
00604       SIMPLE_ARRAY<DBFIELDINFO> m_FileFields;
00605       SIMPLE_ARRAY<DBFIELDINFO> m_ObjFields;
00606       SIMPLE_ARRAY<DBFIELDINFO> m_RgnFields;
00607 
00608       // UNIMPLEMENTED / UNSUPPORTED
00609       GEOCAT (const GEOCAT&);
00610       GEOCAT& operator= (const GEOCAT&);
00611 
00612       //! Iterator gets access to private Read() method.
00613       friend class CONST_ITERATOR;
00614       #endif // GENERATING_DOXYGEN_OUTPUT
00615    };
00616 
00617 
00618 #endif
00619 

Generated on Tue Dec 14 13:18:22 2004 for TNTsdk by  doxygen 1.3.8-20040913