moab
|
00001 #ifndef SEQUENCE_DATA_HPP 00002 #define SEQUENCE_DATA_HPP 00003 00004 00005 #include "TypeSequenceManager.hpp" 00006 00007 #include <vector> 00008 #include <stdlib.h> 00009 #include <string.h> 00010 00011 namespace moab { 00012 00013 class SequenceData 00014 { 00015 public: 00016 00017 typedef std::vector<EntityHandle>* AdjacencyDataType; 00018 00023 inline SequenceData( int num_sequence_arrays, 00024 EntityHandle start, 00025 EntityHandle end ); 00026 00027 virtual ~SequenceData(); 00028 00030 EntityHandle start_handle() const 00031 { return startHandle; } 00032 00034 EntityHandle end_handle() const 00035 { return endHandle; } 00036 00037 EntityID size() const 00038 { return endHandle + 1 - startHandle; } 00039 00041 void* get_sequence_data( int array_num ) 00042 { return arraySet[-1-array_num]; } 00044 void const* get_sequence_data( int array_num ) const 00045 { return arraySet[-1-array_num]; } 00046 00048 AdjacencyDataType* get_adjacency_data( ) 00049 { return reinterpret_cast<AdjacencyDataType*>(arraySet[0]); } 00051 AdjacencyDataType const* get_adjacency_data( ) const 00052 { return reinterpret_cast<AdjacencyDataType const*>(arraySet[0]); } 00053 00055 void* get_tag_data( unsigned tag_num ) 00056 { return tag_num < numTagData ? arraySet[tag_num+1] : 0; } 00058 void const* get_tag_data( unsigned tag_num ) const 00059 { return tag_num < numTagData ? arraySet[tag_num+1] : 0; } 00060 00072 void* create_sequence_data( int array_num, 00073 int bytes_per_ent, 00074 const void* initial_val = 0 ); 00075 00084 void* create_custom_data( int array_num, size_t total_bytes ); 00085 00091 AdjacencyDataType* allocate_adjacency_data(); 00092 00100 void* allocate_tag_array( int index, int bytes_per_ent, const void* default_value = 0 ); 00101 00113 SequenceData* subset( EntityHandle start, 00114 EntityHandle end, 00115 const int* sequence_data_sizes ) const; 00116 00118 TypeSequenceManager::SequenceDataPtr seqManData; 00119 00121 void move_tag_data( SequenceData* destination, const int* tag_sizes, int num_tag_sizes ); 00122 00124 void release_tag_data(const int* tag_sizes, int num_tag_sizes); 00126 void release_tag_data( int index, int tag_size ); 00127 00128 protected: 00129 00130 SequenceData( const SequenceData* subset_from, 00131 EntityHandle start, 00132 EntityHandle end, 00133 const int* sequence_data_sizes ); 00134 00135 private: 00136 00137 void increase_tag_count( unsigned by_this_many ); 00138 00139 void* create_data( int index, int bytes_per_ent, const void* initial_val = 0 ); 00140 void copy_data_subset( int index, 00141 int size_per_ent, 00142 const void* source, 00143 size_t offset, 00144 size_t count ); 00145 00146 const int numSequenceData; 00147 unsigned numTagData; 00148 void** arraySet; 00149 EntityHandle startHandle, endHandle; 00150 }; 00151 00152 inline SequenceData::SequenceData( int num_sequence_arrays, 00153 EntityHandle start, 00154 EntityHandle end ) 00155 : numSequenceData(num_sequence_arrays), 00156 numTagData(0), 00157 startHandle(start), 00158 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