VR-Forces 4.0.4 Class Documentation
include/gdb/specMgr.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2008 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: specMgr.h,v $ $Revision: 1.17 $ $State: Exp $
00007 *******************************************************************************/
00008 #ifndef specMgr_H_
00009 #define specMgr_H_
00010 
00011 //
00012 // \file specMgr.h
00013 // \brief Contains the DtSpecificationManager class declaration and related functionality.
00014 //
00015 
00016 #include "gdb/gdbDefines.h"
00017 #include <vlutil/vlConfig.h>
00018 #include <vector>
00019 #include <stdio.h>
00020 
00021 //forward declarations
00022 class DtSpecification;
00023 
00024 // Make an explicit type for the specification IDs so that we can be sure 
00025 // we're working with the appropriate identifiers
00026 typedef unsigned int DtSpecificationID;
00027 
00028 //
00029 // DtSpecificationManager manages the specifications of the loaded terrain file 
00030 // for the terrain database.
00031 class DT_DLL_gdb DtSpecificationManager
00032 {
00033 public:
00034 
00035    // default constructor
00036    DtSpecificationManager();
00037 
00038    // additional constructor with number of 
00039    // specifications to expect to manage
00040    DtSpecificationManager(unsigned int numSpecifications);
00041 
00042    // destructor
00043    virtual ~DtSpecificationManager();
00044 
00045    // copy constructor
00046    DtSpecificationManager(const DtSpecificationManager& orig);
00047 
00048    // assignment operator
00049    DtSpecificationManager& operator=(const DtSpecificationManager& orig);
00050 
00051    // accessor function
00052    // If the specification manager is managing a specification with the 
00053    // given ID, then this function sets spec to the managed specification 
00054    // and returns true. 
00055    // If the specification is not being managed, then the function
00056    // returns false
00057    virtual bool specification(DtSpecificationID specID, 
00058       DtSpecification& spec) const;
00059 
00060    // Returns a reference to the managed specification..  
00061    // ASSUMES that the ID provided is valid.
00062    virtual DtSpecification& specification(DtSpecificationID specID);
00063    virtual const DtSpecification& specification(DtSpecificationID specID) const;
00064 
00065    // @return The specification ID that will be assigned to the next specification
00066    // to be added to the manager.  This is useful when planning on associating many
00067    // objects with a single specification.  The next ID can be gotten, and then used
00068    // while the specification is still being modified.  
00069    //
00070    // @note Users must be @b very careful in using this.  If the ID is to be used, the
00071    // user must ensure that no specifications are added to the manager before
00072    // their intended specification is, or the nextID will @b not be the one 
00073    // previously given.
00074    virtual DtSpecificationID nextID() const;
00075 
00076 
00077    // Adds a specification to be managed.  
00078    // If allowDuplicates is true, then the specification manager will add the 
00079    // specification even if it be considered a duplicate of an existing 
00080    // managed specification.  specID will be set to a new associated 
00081    // specification ID.  If allowDuplicate is false, specID will be set 
00082    // to the ID of the first specification it finds that passes the equality 
00083    // criteria.  If it doesn't find an equal specification, it adds it as 
00084    // a new specification and sets specID to the associated ID.
00085    // If for some reason, it cannot add the specification at all, it returns 
00086    // false and leaves specID untouched.
00087    virtual bool addSpecification(const DtSpecification& specificationToAdd,
00088                                  DtSpecificationID& specID,
00089                                  bool allowDuplicates = true);
00090 
00091    // Analyzes the managed specifications and removes multiple instances of 
00092    // the same specification.  All duplicate specifications will be collapsed 
00093    // and mapped to one specification ID. If the manager cannot remove the 
00094    // duplicates for any reason, it returns false.
00095    // Otherwise, it removes the duplicates and sets oldIDToNewIDMapping[OldID]
00096    // to be a the new specification ID that is associated with the original 
00097    // ID's specification.  This function guarantees that all original IDs will 
00098    // be valid indices into the oldIDToNewIDMapping.  The caller is responsible 
00099    // for deleting the memory allocated by this function for 
00100    // oldIDToNewIDMapping. (use delete[]).
00101    virtual bool removeDuplicates(int& numDuplicates,
00102                                  int& numEntries, 
00103                                  DtSpecificationID* oldIDToNewIDMapping);
00104 
00105    // \return A boolean indicating whether or not a specification like the specified
00106    // one already exists in the manager.  If so, the function returns true and 
00107    // the specID parameter is set to that specification's ID.  Otherwise, false
00108    // is returned.  
00109    //
00110    // @note A specification is "like" another if the spec is a superset of the
00111    // other specified specification.
00112    virtual bool aSpecificationLike(const DtSpecification& specification, 
00113                                    DtSpecificationID& specID) const;
00114 
00115    // Function to merge the contents of another specification manager
00116    // with this manager.  Creates copies of all the specifications in the manager to merge
00117    // in this manager.
00118    // \param specMgrToMerge A reference to a constant specification manager to merge in.
00119    // \param specificationIDMap A reference to a pointer to a specificationID.  This will
00120    //                           be allocated by the function and returned to the user who
00121    //                           will be responsible for deleting the memory when appropriate.
00122    //                           This array will contain the new specificationIDs mapped by the
00123    //                           old specification IDs.  i.e. map[oldID] = newID.
00124    // 
00125    // \return True if the merging is successful.
00126    // \return False otherwise
00127    virtual bool merge(const DtSpecificationManager& specMgrToMerge, 
00128                       DtSpecificationID*& specificationIDMap);
00129 
00130    // Returns the current number of specifications managed
00131    virtual unsigned int numberOfSpecifications() const;
00132 
00133    // Determines if a given specification ID is valid.  Returns true if the
00134    // ID is associated with a managed specification and false if it doesn't.
00135    virtual bool isValidID(DtSpecificationID specID) const;
00136 
00137    // debugging aid
00138    virtual void dump() const;
00139 
00140    // dumps the specification manager's content into a text  file so it can be 
00141    // viewed graphically using GraphViz.
00142    virtual void dump(FILE* fp) const;
00143 
00144    virtual int sizeInBytes() const;
00145 
00146 protected:
00147    // tests the invariants of the class.  
00148    // Should be called first in every const public member 
00149    // function and both first and last in every other function
00150    bool  testInvariant() const;
00151 
00152    // Adds the surface and sets surfID to be the 
00153    // associated surfID.  If it fails to add the surface - most likely
00154    // a memory issue - it returns false.
00155    bool addNewSpecification(const DtSpecification& specificationToAdd, 
00156                             DtSpecificationID& specID);
00157 
00158    // Looks for a duplicate surface of the specified surface 
00159    // in the managed surfaces.  If it finds one, it returns true 
00160    // and sets managedSurfID to the associated surfID.  If not, 
00161    // it returns false and leaves managedSurfID untouched.
00162    bool isDuplicate(const DtSpecification& specification, 
00163                     DtSpecificationID& managedSpecID) const;
00164 
00165    // Dynamically allocated array of Specifications. 
00166    std::vector<DtSpecification>  mySpecifications; 
00167 };
00168 
00169 #endif
00170 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)