cgma
|
00001 //------------------------------------------------------------------------- 00002 // Copyright Notice 00003 // 00004 // Copyright (c) 1996 00005 // by Malcolm J. Panthaki, DBA, and the University of New Mexico. 00006 //------------------------------------------------------------------------- 00007 // 00008 //------------------------------------------------------------------------- 00009 // Filename : ModelQueryEngine.hpp 00010 // 00011 // Purpose : This class provides the interface to query the model. 00012 // 00013 // Special Notes : This is a singleton class. 00014 // 00015 // The primary objects that this class deals with, at the 00016 // interface, are TopologyEntity's. These are entities 00017 // that are represented as nodes in the DAG. Each node of 00018 // the DAG contains a pointer to a TopologyEntity. 00019 // 00020 // All of the query functions rely on the "type" of 00021 // objects. Some of them rely on the relationships 00022 // between different "type"s of objects. Currently all 00023 // such relationships, i.e. the entity relation diagram 00024 // (ERD) of the different TopologyEntity classes is maintained 00025 // by a class called ModelERD. 00026 // 00027 // Creator : Xuechen Liu 00028 // 00029 // Creation Date : 06/08/96 00030 // 00031 // Owner : Malcolm J. Panthaki 00032 //------------------------------------------------------------------------- 00033 00034 #ifndef MODEL_QUERY_ENGINE_HPP 00035 #define MODEL_QUERY_ENGINE_HPP 00036 00037 00038 // ********** BEGIN STANDARD INCLUDES ********** 00039 // ********** END STANDARD INCLUDES ********** 00040 00041 // ********** BEGIN MOTIF INCLUDES ********** 00042 // ********** END MOTIF INCLUDES ********** 00043 00044 // ********** BEGIN OPEN INVENTOR INCLUDES ********** 00045 // ********** END OPEN INVENTOR INCLUDES ********** 00046 00047 // ********** BEGIN CUBIT INCLUDES ********** 00048 00049 #include "CubitDefines.h" 00050 #include "TopologyEntity.hpp" 00051 #include "DLIList.hpp" 00052 00053 // ********** END CUBIT INCLUDES ********** 00054 00055 // ********** BEGIN MACROS DEFINITIONS ********** 00056 // ********** END MACROS DEFINITIONS ********** 00057 00058 // ********** BEGIN FORWARD DECLARATIONS ********** 00059 00060 class TopologyEntity; 00061 00062 // ********** END FORWARD DECLARATIONS ********** 00063 00064 // ********** BEGIN ENUM DEFINITIONS ********** 00065 00066 enum CubitSearchDirection 00067 { 00068 CUBIT_SEARCH_NO_DIRECTION = -1, 00069 CUBIT_SEARCH_PARENT = 0, 00070 CUBIT_SEARCH_CHILD = 1 00071 }; 00072 // ********** END ENUM DEFINITIONS ********** 00073 00074 00075 class CUBIT_GEOM_EXPORT ModelQueryEngine 00076 { 00077 public: 00078 00079 static ModelQueryEngine* instance(); 00080 //R ModelQueryEngine* 00081 //R- A pointer to the only instance of this class. 00082 //- This function controls access and creation of the sole instance 00083 //- of this class. It ensures that only one instance can ever get 00084 //- created. It returns a pointer to the only instance of the class. 00085 00086 ~ModelQueryEngine() ; 00087 //- Destructor 00088 00089 static void delete_instance() 00090 { 00091 if(instance_) 00092 delete instance_; 00093 instance_ = NULL; 00094 } 00095 00096 //HEADER- Query functions on single source objects 00097 00098 CubitStatus query_model( TopologyEntity & source_object, 00099 DagType target_type, 00100 DLIList<TopologyEntity*>& result_set ); 00101 00102 CubitStatus query_model_and_append( TopologyEntity& source_object, 00103 DagType target_type, 00104 DLIList<TopologyEntity*>& result_set ); 00105 //R CubitStatus 00106 //R- CUBIT_SUCCESS/FAILURE 00107 //I sourceObject 00108 //I- A reference to the ModEnt on which query is to be done. 00109 //I targetType 00110 //I- The type of the ModEnts to query. 00111 //I- It can be any kind of data type: root base type, intermediate 00112 //I- base type, or leaf type. 00113 //O resultModEntSet 00114 //O- Reference to a set of ModEnts where output of the query will be 00115 //O- put/appended. 00116 //- This function queries the given object, "sourceObject", for all 00117 //- the ModEnts of the given type, "targetType" that it is related to and 00118 //- puts/apppends the result of the query in "resultModEntSet". 00119 //- The return value is CUBIT_SUCCESS if the source object has either 00120 //- a parent-child or child-parent relationship with objects of the 00121 //- given type, CUBIT_FAILURE otherwise. 00122 00123 00124 00125 00126 //HEADER- Query functions on sets of source objects 00127 00128 CubitStatus query_model( DLIList<TopologyEntity*>& source_set, 00129 DagType target_type, 00130 DLIList<TopologyEntity*>& result_set ); 00131 00132 CubitStatus query_model_and_append( DLIList<TopologyEntity*>& source_set, 00133 DagType target_type, 00134 DLIList<TopologyEntity*>& result_set ); 00135 //R CubitStatus 00136 //R- CUBIT_SUCCESS/FAILURE 00137 //I sourceObjectSet 00138 //I- A reference to a set of ModEnts on which query is to be done. 00139 //I targetType 00140 //I- The type of the ModEnts to query. 00141 //I- It can be any kind of data type: root base type, intermediate 00142 //I- base type, or leaf type. 00143 //O resultModEntSet 00144 //O- Reference to a set of ModEnts where output of the query will be 00145 //O- put/appended. 00146 //- This function queries the given objects, "sourceObjectSet", for all 00147 //- the ModEnts of the given type, "targetType" that they are related to and 00148 //- puts/apppends the result of the query in "resultModEntSet". 00149 //- The return value is CUBIT_SUCCESS if each of the source objects 00150 //- has either a parent-child or child-parent relationship with 00151 //- objects of the given type, CUBIT_FAILURE otherwise. 00152 00153 00154 bool encountered( TopologyEntity* ); 00155 //- Mark node as encountered if it was not already encountered. 00156 //- Return the previous value of the encountered flag. 00157 00158 class BeginQuery { 00159 public: 00160 inline BeginQuery() 00161 { ModelQueryEngine::instance()->inc_query_call_stack(); } 00162 inline ~BeginQuery() 00163 { ModelQueryEngine::instance()->dec_query_call_stack(); } 00164 inline void* operator new(size_t /*size*/) throw() 00165 { assert(0); return (void*)0; } 00166 }; 00167 00168 protected: 00169 00170 CubitStatus query_append_children ( TopologyEntity& source_object, 00171 DagType child_type, 00172 DLIList<TopologyEntity*>& result_set ); 00173 CubitStatus query_append_parents ( TopologyEntity& source_object, 00174 DagType parent_type, 00175 DLIList<TopologyEntity*>& result_set ); 00176 00177 00178 00179 friend class ModelQueryEngine::BeginQuery; 00180 00181 void inc_query_call_stack(); 00182 void dec_query_call_stack(); 00183 00184 int queryCallStackDepth; 00185 00186 DLIList<TopologyEntity*> encounteredSet; 00187 // A set of marked ModelEntities. 00188 00189 DLIList<TopologyEntity*> intermediateNodeSets[2]; 00190 00191 private: 00192 00193 ModelQueryEngine() ; 00194 //- Constructor. (Not callable by user code. Class is constructed 00195 //- by the "instance()" member function. 00196 00197 static ModelQueryEngine* instance_; 00198 //- The static pointer to unique instance of this class. 00199 }; 00200 00201 // ********** BEGIN HELPER CLASSES ********** 00202 // ********** END HELPER CLASSES ********** 00203 00204 // ********** BEGIN INLINE FUNCTIONS ********** 00205 00206 // ********** END INLINE FUNCTIONS ********** 00207 00208 // ********** BEGIN FRIEND FUNCTIONS ********** 00209 // ********** END FRIEND FUNCTIONS ********** 00210 00211 // ********** BEGIN EXTERN FUNCTIONS ********** 00212 // ********** END EXTERN FUNCTIONS ********** 00213 00214 #endif 00215