cgma
|
00001 //- Class: TDUniqueId 00002 //- Owner: Tim Tautges 00003 //- Description: This tool data generates unique ids using a random number 00004 //- generator, and keeps an id in this object 00005 //- A NOTE ABOUT RANDOM NUMBER GENERATION USED IN THIS CLASS: 00006 //- A 3rd party random number generator is used in this class, to overcome limitations 00007 //- of the (16-bit) random number generator on windows systems. This generator is in 00008 //- the TRandomMersenne class; see that class for documentation of the actual RNG source. 00009 //- In this class (TDUniqueId), the random number generator is seeded DURING THE FIRST CALL 00010 //- TO GET A UNIQUE ID with the output of time(NULL). This "function-static" method is 00011 //- used to further randomize the seed to decrease the liklihood of getting duplicate uids. 00012 //- 00013 //- Checked By: 00014 //- Version: 00015 00016 #ifndef TD_UNIQUE_ID 00017 #define TD_UNIQUE_ID 00018 00019 #include "ToolData.hpp" 00020 #include "MemoryManager.hpp" 00021 #include "CubitDefines.h" 00022 #include "CGMGeomConfigure.h" 00023 #include <map> 00024 00025 template <class X> class DLIList; 00026 class ToolDataUser; 00027 class RefEntity; 00028 class TDUniqueId; 00029 00030 typedef std::multimap<long, TDUniqueId*> TDUIDList; 00031 00032 //This map is used when copying an entity. It maps the unique 00033 //id of the original to the unique id of the copy 00034 typedef std::map<long, long> COPYUIDMap; 00035 00036 class CUBIT_GEOM_EXPORT TDUniqueId : public ToolData 00037 { 00038 private: 00039 00040 int uniqueId; 00041 //- unique id of the owning entity 00042 00043 ToolDataUser *ownerEntity; 00044 //- back pointer to the owning entity (needed for sorted lists of 00045 //- TDUniqueId's) 00046 00047 static MemoryManager memoryManager; 00048 //- memory management object 00049 00050 static TDUIDList uniqueIdList; 00051 //- static list of all entities containing unique ids 00052 00053 static COPYUIDMap mapForCopying; 00054 //- maps original unique id to that on copy of entity 00055 00056 static int initialize(); 00057 //- initialize the random number generator 00058 00059 static TDUIDList &unique_id_list(); 00060 //- get a reference to the unique id map 00061 00062 public: 00063 00064 static int generate_unique_id(); 00065 00066 TDUniqueId(ToolDataUser *owner, const int id = 0); 00067 00068 virtual ~TDUniqueId(); 00069 //-constructor and destructor 00070 00071 //- clear copy map 00072 static void clear_copy_map(); 00073 00074 static int is_unique_id(const ToolData* td); 00075 00076 static int get_unique_id(ToolDataUser *owner, 00077 const CubitBoolean create_new = CUBIT_TRUE); 00078 //- get the unique id for owner, or create a new one 00079 00080 int unique_id(); /*{return uniqueId;};*/ 00081 void unique_id(const int id) {uniqueId = id;}; 00082 //- get/set functions for unique id 00083 00084 static int get_unique_id_for_copy( int original_id ); 00085 //- when copying an entity that has unique id, gets another 00086 //unique id for the copy 00087 00088 ToolDataUser *owner_entity() {return ownerEntity;}; 00089 void owner_entity(ToolDataUser *owner) {ownerEntity = owner;}; 00090 //- get/set functions for ownerEntity 00091 00092 static ToolDataUser *find_td_unique_id(const int temp_id, 00093 const RefEntity *related_entity = NULL); 00094 //- find the tdu with id temp_id (sorts the list if not sorted) 00095 00096 static int find_td_unique_id(const int temp_id, 00097 DLIList<ToolDataUser*> &td_list, 00098 const RefEntity *related_entity = NULL); 00099 //- find all tdus with id temp_id (sorts the list if not sorted); returns num found 00100 00101 SetDynamicMemoryAllocation(memoryManager) 00102 //- class specific new and delete operators 00103 00104 static void set_memory_allocation_increment(int increment = 0) 00105 {memoryManager.set_memory_allocation_increment(increment);} 00106 //- set block memory size increment 00107 00108 static void destroy_memory() 00109 {memoryManager.destroy_memory();} 00110 //- destroy all memory allocted to this object 00111 00112 }; 00113 00114 inline TDUIDList &TDUniqueId::unique_id_list() 00115 { 00116 return uniqueIdList; 00117 } 00118 #endif 00119 00120