MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #ifndef SEQUENCE_DATA_HPP 00002 #define SEQUENCE_DATA_HPP 00003 00004 #include "TypeSequenceManager.hpp" 00005 00006 #include <vector> 00007 #include <cstdlib> 00008 #include <cstring> 00009 00010 namespace moab 00011 { 00012 00013 class SequenceData 00014 { 00015 public: 00016 typedef std::vector< EntityHandle >* AdjacencyDataType; 00017 00018 /**\param num_sequence_arrays Number of data arrays needed by the EntitySequence 00019 * \param start First handle in this SequenceData 00020 * \param end Last handle in this SequenceData 00021 */ 00022 inline SequenceData( int num_sequence_arrays, EntityHandle start, EntityHandle end ); 00023 00024 virtual ~SequenceData(); 00025 00026 /**\return first handle in this sequence data */ 00027 EntityHandle start_handle() const 00028 { 00029 return startHandle; 00030 } 00031 00032 /**\return last handle in this sequence data */ 00033 EntityHandle end_handle() const 00034 { 00035 return endHandle; 00036 } 00037 00038 EntityID size() const 00039 { 00040 return endHandle + 1 - startHandle; 00041 } 00042 00043 /**\return ith array of EnitySequence-specific data */ 00044 void* get_sequence_data( int array_num ) 00045 { 00046 return arraySet[-1 - array_num]; 00047 } 00048 /**\return ith array of EnitySequence-specific data */ 00049 void const* get_sequence_data( int array_num ) const 00050 { 00051 return arraySet[-1 - array_num]; 00052 } 00053 00054 /**\return array of adjacency data, or NULL if none. */ 00055 AdjacencyDataType* get_adjacency_data() 00056 { 00057 return reinterpret_cast< AdjacencyDataType* >( arraySet[0] ); 00058 } 00059 /**\return array of adjacency data, or NULL if none. */ 00060 AdjacencyDataType const* get_adjacency_data() const 00061 { 00062 return reinterpret_cast< AdjacencyDataType const* >( arraySet[0] ); 00063 } 00064 00065 /**\return array of dense tag data, or NULL if none. */ 00066 void* get_tag_data( unsigned tag_num ) 00067 { 00068 return tag_num < numTagData ? arraySet[tag_num + 1] : 0; 00069 } 00070 /**\return array of dense tag data, or NULL if none. */ 00071 void const* get_tag_data( unsigned tag_num ) const 00072 { 00073 return tag_num < numTagData ? arraySet[tag_num + 1] : 0; 00074 } 00075 00076 /**\brief Allocate array of sequence-specific data 00077 * 00078 * Allocate an array of EntitySequence-specific data. 00079 *\param array_num Index for which to allocate array. 00080 * Must be in [0,num_sequence_arrays], where 00081 * num_sequence_arrays is constructor argument. 00082 *\param bytes_per_ent Bytes to allocate for each entity. 00083 *\param initial_val Value to initialize array with. If non-null, must 00084 * be bytes_per_ent long. If NULL, array will be zeroed. 00085 *\return The newly allocated array, or NULL if error. 00086 */ 00087 void* create_sequence_data( int array_num, int bytes_per_ent, const void* initial_val = 0 ); 00088 00089 /**\brief Allocate array of sequence-specific data 00090 * 00091 * Allocate an array of EntitySequence-specific data. 00092 *\param array_num Index for which to allocate array. 00093 * Must be in [0,num_sequence_arrays], where 00094 * num_sequence_arrays is constructor argument. 00095 *\return The newly allocated array, or NULL if error. 00096 */ 00097 void* create_custom_data( int array_num, size_t total_bytes ); 00098 00099 /**\brief Allocate array for storing adjacency data. 00100 * 00101 * Allocate array for storing adjacency data. 00102 *\return The newly allocated array, or NULL if already allocated. 00103 */ 00104 AdjacencyDataType* allocate_adjacency_data(); 00105 00106 /**\brief Allocate array of dense tag data 00107 * 00108 * Allocate an array of dense tag data. 00109 *\param index Dense tag ID for which to allocate array. 00110 *\param bytes_per_ent Bytes to allocate for each entity. 00111 *\return The newly allocated array, or NULL if error. 00112 */ 00113 void* allocate_tag_array( int index, int bytes_per_ent, const void* default_value = 0 ); 00114 00115 /**\brief Create new SequenceData that is a copy of a subset of this one 00116 * 00117 * Create a new SequenceData that is a copy of a subset of this one. 00118 * This function is intended for use in subdividing a SequenceData 00119 * for operations such as changing the number of nodes in a block of 00120 * elements. 00121 *\param start First handle for resulting subset 00122 *\param end Last handle for resulting subset 00123 *\param sequence_data_sizes Bytes-per-entity for sequence-specific data. 00124 *\NOTE Does not copy tag data. 00125 */ 00126 SequenceData* subset( EntityHandle start, EntityHandle end, const int* sequence_data_sizes ) const; 00127 00128 /**\brief SequenceManager data */ 00129 TypeSequenceManager::SequenceDataPtr seqManData; 00130 00131 /**\brief Move tag data for a subset of this sequences to specified sequence */ 00132 void move_tag_data( SequenceData* destination, const int* tag_sizes, int num_tag_sizes ); 00133 00134 /**\brief Free all tag data arrays */ 00135 void release_tag_data( const int* tag_sizes, int num_tag_sizes ); 00136 /**\brief Free specified tag data array */ 00137 void release_tag_data( int index, int tag_size ); 00138 00139 protected: 00140 SequenceData( const SequenceData* subset_from, 00141 EntityHandle start, 00142 EntityHandle end, 00143 const int* sequence_data_sizes ); 00144 00145 private: 00146 void increase_tag_count( unsigned by_this_many ); 00147 00148 void* create_data( int index, int bytes_per_ent, const void* initial_val = 0 ); 00149 void copy_data_subset( int index, int size_per_ent, const void* source, size_t offset, size_t count ); 00150 00151 const int numSequenceData; 00152 unsigned numTagData; 00153 void** arraySet; 00154 EntityHandle startHandle, endHandle; 00155 }; 00156 00157 inline SequenceData::SequenceData( int num_sequence_arrays, EntityHandle start, EntityHandle end ) 00158 : numSequenceData( num_sequence_arrays ), numTagData( 0 ), startHandle( start ), endHandle( end ) 00159 { 00160 const size_t sz = sizeof( void* ) * ( num_sequence_arrays + 1 ); 00161 void** data = (void**)malloc( sz ); 00162 memset( data, 0, sz ); 00163 arraySet = data + num_sequence_arrays; 00164 } 00165 00166 } // namespace moab 00167 00168 #endif