MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /** \file DenseTag.hpp 00002 * \author Jason Kraftcheck 00003 * \date 2010-12-14 00004 */ 00005 00006 #ifndef DENSE_TAG_HPP 00007 #define DENSE_TAG_HPP 00008 00009 #include "TagInfo.hpp" 00010 00011 namespace moab 00012 { 00013 00014 class EntitySequence; 00015 00016 /**\brief Dense storage of fixed-length tag data 00017 * 00018 * Implement normal dense tag. 00019 */ 00020 class DenseTag : public TagInfo 00021 { 00022 private: 00023 int mySequenceArray; //!< Array index in SequenceManager used to store tag data. 00024 00025 unsigned char* meshValue; 00026 00027 DenseTag( int array_index, const char* name, int size, DataType type, const void* default_value ); 00028 00029 public: 00030 static DenseTag* create_tag( SequenceManager* seqman, 00031 Error* error, 00032 const char* name, 00033 int bytes, 00034 DataType type, 00035 const void* default_value ); 00036 00037 virtual ~DenseTag(); 00038 00039 virtual TagType get_storage_type() const; 00040 00041 /**\brief Remove/clear tag data for all entities 00042 * 00043 * Remove tag values from entities. 00044 * 00045 *\param delete_pending If true, then release any global 00046 * data associated with the tag in preparation for deleting 00047 * the tag itself. 00048 * 00049 *\Note Invalidates tag if \c tag_delete_pending is true. The only 00050 * valid method that can be invoked that is is the destructor. 00051 * 00052 *\param seqman Pointer to mesh entity database 00053 */ 00054 virtual ErrorCode release_all_data( SequenceManager* seqman, Error* error_handler, bool delete_pending ); 00055 00056 /**\brief Get tag value for passed entities 00057 * 00058 * Get tag values for specified entities. 00059 * 00060 *\Note Will fail for variable-length data. 00061 *\param seqman Pointer to mesh entity database 00062 *\param entities Entity handles for which to retrieve tag data 00063 *\param num_entities Length of \c entities array 00064 *\param data Pointer to memory in which to store consecutive tag values, 00065 * one for each passed entity. 00066 */ 00067 virtual ErrorCode get_data( const SequenceManager* seqman, 00068 Error* error_handler, 00069 const EntityHandle* entities, 00070 size_t num_entities, 00071 void* data ) const; 00072 00073 /**\brief Get tag value for passed entities 00074 * 00075 * Get tag values for specified entities. 00076 * 00077 *\Note Will fail for variable-length data. 00078 *\param seqman Pointer to mesh entity database 00079 *\param entities Entity handles for which to retrieve tag data 00080 *\param data Pointer to memory in which to store consecutive tag values, 00081 * one for each passed entity. 00082 */ 00083 virtual ErrorCode get_data( const SequenceManager* seqman, 00084 Error* error_handler, 00085 const Range& entities, 00086 void* data ) const; 00087 00088 /**\brief Get tag value for passed entities 00089 * 00090 * Get tag values for specified entities. 00091 * 00092 *\param seqman Pointer to mesh entity database 00093 *\param entities Entity handles for which to retrieve tag data 00094 *\param num_entities Length of \c entities array 00095 *\param data_ptrs Array of pointers to tag values, one pointer 00096 * for each passed entity. 00097 *\param data_lengths One value for each entity specifying the 00098 * length of the tag value for the corresponding 00099 * entity. 00100 */ 00101 virtual ErrorCode get_data( const SequenceManager* seqman, 00102 Error* error_handler, 00103 const EntityHandle* entities, 00104 size_t num_entities, 00105 const void** data_ptrs, 00106 int* data_lengths ) const; 00107 00108 /**\brief Get tag value for passed entities 00109 * 00110 * Get tag values for specified entities. 00111 * 00112 *\param seqman Pointer to mesh entity database 00113 *\param entities Entity handles for which to retrieve tag data 00114 *\param data_ptrs Array of pointers to tag values, one pointer 00115 * for each passed entity. 00116 *\param data_lengths One value for each entity specifying the 00117 * length of the tag value for the corresponding 00118 * entity. 00119 */ 00120 virtual ErrorCode get_data( const SequenceManager* seqman, 00121 Error* error_handler, 00122 const Range& entities, 00123 const void** data_ptrs, 00124 int* data_lengths ) const; 00125 00126 /**\brief Set tag value for passed entities 00127 * 00128 * Store tag data or update stored tag values 00129 *\Note Will fail for variable-length data. 00130 *\param seqman Pointer to mesh entity database 00131 *\param entities Entity handles for which to store tag data 00132 *\param num_entities Length of \c entities array 00133 *\param data Pointer to memory holding consecutive tag values, 00134 * one for each passed entity. 00135 */ 00136 virtual ErrorCode set_data( SequenceManager* seqman, 00137 Error* error_handler, 00138 const EntityHandle* entities, 00139 size_t num_entities, 00140 const void* data ); 00141 00142 /**\brief Set tag value for passed entities 00143 * 00144 * Store tag data or update stored tag values 00145 *\Note Will fail for variable-length data. 00146 *\param seqman Pointer to mesh entity database 00147 *\param entities Entity handles for which to store tag data 00148 *\param data Pointer to memory holding consecutive tag values, 00149 * one for each passed entity. 00150 */ 00151 virtual ErrorCode set_data( SequenceManager* seqman, 00152 Error* error_handler, 00153 const Range& entities, 00154 const void* data ); 00155 00156 /**\brief Set tag value for passed entities 00157 * 00158 * Store tag data or update stored tag values 00159 * 00160 *\param seqman Pointer to mesh entity database 00161 *\param entities Entity handles for which to store tag data 00162 *\param num_entities Length of \c entities array 00163 *\param data_ptrs Array of pointers to tag values, one pointer 00164 * for each passed entity. 00165 *\param data_lengths One value for each entity specifying the 00166 * length of the tag value for the corresponding 00167 * entity. Array is required for variable-length 00168 * tags and is ignored for fixed-length tags. 00169 */ 00170 virtual ErrorCode set_data( SequenceManager* seqman, 00171 Error* error_handler, 00172 const EntityHandle* entities, 00173 size_t num_entities, 00174 void const* const* data_ptrs, 00175 const int* data_lengths ); 00176 00177 /**\brief Set tag value for passed entities 00178 * 00179 * Store tag data or update stored tag values 00180 * 00181 *\param seqman Pointer to mesh entity database 00182 *\param entities Entity handles for which to store tag data 00183 *\param data_ptrs Array of pointers to tag values, one pointer 00184 * for each passed entity. 00185 *\param data_lengths One value for each entity specifying the 00186 * length of the tag value for the corresponding 00187 * entity. Array is required for variable-length 00188 * tags and is ignored for fixed-length tags. 00189 */ 00190 virtual ErrorCode set_data( SequenceManager* seqman, 00191 Error* error_handler, 00192 const Range& entities, 00193 void const* const* data_ptrs, 00194 const int* data_lengths ); 00195 00196 /**\brief Set tag value for passed entities 00197 * 00198 * Store tag data or update stored tag values. 00199 * 00200 *\param seqman Pointer to mesh entity database 00201 *\param entities Entity handles for which to store tag data 00202 *\param num_entities Length of \c entities array 00203 *\param value_ptr Pointer to a single tag value which is to be 00204 * stored for each of the passed entities. 00205 *\param value_len Length of tag value in bytes. Ignored for 00206 * fixed-length tags. Required for variable- 00207 * length tags. 00208 */ 00209 virtual ErrorCode clear_data( SequenceManager* seqman, 00210 Error* error_handler, 00211 const EntityHandle* entities, 00212 size_t num_entities, 00213 const void* value_ptr, 00214 int value_len = 0 ); 00215 00216 /**\brief Set tag value for passed entities 00217 * 00218 * Store tag data or update stored tag values. 00219 * 00220 *\param seqman Pointer to mesh entity database 00221 *\param entities Entity handles for which to store tag data 00222 *\param value_ptr Pointer to a single tag value which is to be 00223 * stored for each of the passed entities. 00224 *\param value_len Length of tag value in bytes. Ignored for 00225 * fixed-length tags. Required for variable- 00226 * length tags. 00227 */ 00228 virtual ErrorCode clear_data( SequenceManager* seqman, 00229 Error* error_handler, 00230 const Range& entities, 00231 const void* value_ptr, 00232 int value_len = 0 ); 00233 00234 /**\brief Remove/clear tag data for entities 00235 * 00236 * Remove tag values from entities. 00237 * 00238 *\param seqman Pointer to mesh entity database 00239 *\param entities Entity handles for which to store tag data 00240 *\param num_entities Length of \c entities array 00241 */ 00242 virtual ErrorCode remove_data( SequenceManager* seqman, 00243 Error* error_handler, 00244 const EntityHandle* entities, 00245 size_t num_entities ); 00246 00247 /**\brief Remove/clear tag data for entities 00248 * 00249 * Remove tag values from entities. 00250 * 00251 *\param seqman Pointer to mesh entity database 00252 *\param entities Entity handles for which to store tag data 00253 */ 00254 virtual ErrorCode remove_data( SequenceManager* seqman, Error* error_handler, const Range& entities ); 00255 00256 /**\brief Access tag data via direct pointer into contiguous blocks 00257 * 00258 * Iteratively obtain direct access to contiguous blocks of tag 00259 * storage. This function cannot be used with bit tags because 00260 * of the compressed bit storage. This function cannot be used 00261 * with variable length tags because it does not provide a mechanism 00262 * to determine the length of the value for each entity. This 00263 * function may be used with sparse tags, but if it is used, it 00264 * will return data for a single entity at a time. 00265 * 00266 *\param iter As input, the first entity for which to return 00267 * data. As output, one past the last entity for 00268 * which data was returned. 00269 *\param end One past the last entity for which data is desired 00270 *\param data_ptr Output: pointer to tag storage. 00271 * 00272 *\Note If this function is called for entities for which no tag value 00273 * has been set, but for which a default value exists, it will 00274 * force the allocation of explicit storage for each such entity 00275 * even though MOAB would normally not explicitly store tag values 00276 * for such entities. 00277 */ 00278 virtual ErrorCode tag_iterate( SequenceManager* seqman, 00279 Error* error_handler, 00280 Range::iterator& iter, 00281 const Range::iterator& end, 00282 void*& data_ptr, 00283 bool allocate = true ); 00284 00285 /**\brief Get all tagged entities 00286 * 00287 * Get the list of entities for which the a tag value has been set, 00288 * or a close approximation if the tag storage scheme cannot 00289 * accurately determine exactly which entities have explicit values. 00290 * 00291 *\param seqman Pointer to entity storage database 00292 *\param output_entities Results *appended* to this range 00293 *\param type Optional entity type. If specified, search is 00294 * limited to entities of specified type. 00295 *\param intersect Optional intersect list. If specified, 00296 * search is restricted to entities in this list. 00297 */ 00298 virtual ErrorCode get_tagged_entities( const SequenceManager* seqman, 00299 Range& output_entities, 00300 EntityType type = MBMAXTYPE, 00301 const Range* intersect = 0 ) const; 00302 00303 /**\brief Count all tagged entities 00304 * 00305 * Count the entities for which the a tag value has been set, 00306 * or a close approximation if the tag storage scheme cannot 00307 * accurately determine exactly which entities have explicit values. 00308 * 00309 *\param seqman Pointer to entity storage database 00310 *\param output_count This is *incremented* for each detected entity. 00311 *\param type Optional entity type. If specified, search is 00312 * limited to entities of specified type. 00313 *\param intersect Optional intersect list. If specified, 00314 * search is restricted to entities in this list. 00315 */ 00316 virtual ErrorCode num_tagged_entities( const SequenceManager* seqman, 00317 size_t& output_count, 00318 EntityType type = MBMAXTYPE, 00319 const Range* intersect = 0 ) const; 00320 00321 /**\brief Get all tagged entities with tag value 00322 * 00323 * Get the list of entities which have the specified tag value. 00324 * 00325 *\param seqman Pointer to entity storage database 00326 *\param output_entities Results *appended* to this range 00327 *\param value Pointer to tag value 00328 *\param value_bytes Size of tag value in bytes. 00329 *\param type Optional entity type. If specified, search is 00330 * limited to entities of specified type. 00331 *\param intersect_entities Optional intersect list. If specified, 00332 * search is restricted to entities in this list. 00333 */ 00334 virtual ErrorCode find_entities_with_value( const SequenceManager* seqman, 00335 Error* error_handler, 00336 Range& output_entities, 00337 const void* value, 00338 int value_bytes = 0, 00339 EntityType type = MBMAXTYPE, 00340 const Range* intersect_entities = 0 ) const; 00341 00342 /**\brief Check if entity is tagged */ 00343 virtual bool is_tagged( const SequenceManager*, EntityHandle h ) const; 00344 00345 /**\brief Get memory use for tag data. 00346 * 00347 */ 00348 virtual ErrorCode get_memory_use( const SequenceManager* seqman, 00349 unsigned long& total, 00350 unsigned long& per_entity ) const; 00351 00352 /**\brief Get read-only tag storage 00353 * 00354 *\param seqman Sequence manager 00355 *\param error Error object through which to report errors 00356 *\param h First entity for which to return storage. 00357 *\param ptr Pointer to dag storage. This pointer will be set 00358 * to null and \c MB_SUCCESS will be returned if the handle 00359 * is valid but no tag storage has been allocated. 00360 *\param count Number of consecutive entities for which tag storage 00361 * is returned. This value will be valid even if null 00362 * is returned for \c ptr and indicates the number of 00363 * consecutive entities for which no tag storage has been 00364 * allocated. 00365 *\return MB_SUCCESS if handle is valid (regardless of whether 00366 * or not any tag storage is allocated). 00367 */ 00368 ErrorCode get_array( const SequenceManager* seqman, 00369 Error* error, 00370 EntityHandle h, 00371 const unsigned char* const& ptr, 00372 size_t& count ) const; 00373 00374 /**\brief Get read-only tag storage for entire sequence 00375 * 00376 *\param seq Sequence 00377 *\param ptr Pointer to dag storage. This pointer will be set 00378 * to null and \c MB_SUCCESS will be returned if no tag storage has been 00379 *allocated. \return MB_SUCCESS if sequence is valid (regardless of whether or not any 00380 *tag storage is allocated). 00381 */ 00382 ErrorCode get_array( const EntitySequence* seq, const unsigned char* const& ptr ) const; 00383 00384 private: 00385 DenseTag( const DenseTag& ); 00386 DenseTag& operator=( const DenseTag& ); 00387 00388 /**\brief Get or allocated tag storage 00389 * 00390 *\param h First entity for which to return storage. 00391 *\param ptr Pointer to dag storage. This pointer will be set 00392 * to null and \c MB_SUCCESS will be returned if the handle 00393 * is valid but no tag storage has been allocated. 00394 *\param count Number of consecutive entities for which tag storage 00395 * is returned. This value will be valid even if null 00396 * is returned for \c ptr and indicates the number of 00397 * consecutive entities for which no tag storage has been 00398 * allocated. 00399 *\param allocate If true storage will be allocated and initialized 00400 * if it has not already been allocated. 00401 *\return MB_SUCCESS if handle is valid (regardless of whether 00402 * or not any tag storage is allocated). 00403 */ 00404 inline ErrorCode get_array_private( SequenceManager* seqman, 00405 Error* error, 00406 EntityHandle h, 00407 unsigned char*& ptr, 00408 size_t& count, 00409 bool allocate ); 00410 00411 /**\brief Get tag storage 00412 * 00413 *\param h First entity for which to return storage. 00414 *\param ptr Pointer to dag storage. This pointer will be set 00415 * to null and \c MB_SUCCESS will be returned if the handle 00416 * is valid but no tag storage has been allocated. 00417 *\param count Number of consecutive entities for which tag storage 00418 * is returned. This value will be valid even if null 00419 * is returned for \c ptr and indicates the number of 00420 * consecutive entities for which no tag storage has been 00421 * allocated. 00422 *\return MB_SUCCESS if handle is valid (regardless of whether 00423 * or not any tag storage is allocated). 00424 */ 00425 inline ErrorCode get_array_private( const SequenceManager* seqman, 00426 Error* error, 00427 EntityHandle h, 00428 const unsigned char*& ptr, 00429 size_t& count ) const; 00430 00431 /**\brief Get non-read-only tag storage for entire sequence 00432 * 00433 *\param seq Sequence 00434 *\param ptr Pointer to dag storage. This pointer will be set 00435 * to null and \c MB_SUCCESS will be returned if no tag storage has been 00436 *allocated. \return MB_SUCCESS if sequence is valid (regardless of whether or not any 00437 *tag storage is allocated). 00438 */ 00439 ErrorCode get_array_private( const EntitySequence* seq, const unsigned char*& ptr ) const; 00440 00441 /**\brief Common implementation of public clear_data and remove_data */ 00442 ErrorCode clear_data( bool allocate, 00443 SequenceManager* seqman, 00444 Error* error, 00445 const EntityHandle* entities, 00446 size_t num_entities, 00447 const void* value_ptr ); 00448 00449 /**\brief Common implementation of public clear_data and remove_data */ 00450 ErrorCode clear_data( bool allocate, 00451 SequenceManager* seqman, 00452 Error* error, 00453 const Range& entities, 00454 const void* value_ptr ); 00455 }; 00456 00457 } // namespace moab 00458 00459 #endif // DENSE_TAG_HPP