Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 #ifndef __smoab_detail_UsageTable_h 00002 #define __smoab_detail_UsageTable_h 00003 00004 #include <set> 00005 #include <vector> 00006 00007 namespace smoab 00008 { 00009 namespace detail 00010 { 00011 00012 namespace internal 00013 { 00014 00015 struct KeyType 00016 { 00017 moab::EntityHandle Handle; 00018 int ParentId; 00019 00020 KeyType( const moab::EntityHandle& h, int p ) : Handle( h ), ParentId( p ) {} 00021 00022 bool operator<( const KeyType& other ) const 00023 { 00024 return ( ( this->Handle < other.Handle ) || 00025 ( ( this->Handle < other.Handle ) && ( this->ParentId < other.ParentId ) ) ); 00026 } 00027 }; 00028 00029 class key_inserter 00030 { 00031 00032 protected: 00033 Range* container; 00034 00035 public: 00036 //constructor 00037 explicit key_inserter( Range& x ) : container( &x ) {} 00038 key_inserter& operator=( const KeyType& value ) 00039 { 00040 container->insert( value.Handle ); 00041 return *this; 00042 } 00043 00044 key_inserter& operator*() 00045 { 00046 return *this; 00047 } 00048 key_inserter& operator++() 00049 { 00050 return *this; 00051 } 00052 key_inserter& operator++( int ) 00053 { 00054 return *this; 00055 } 00056 00057 typedef moab::EntityHandle value_type; 00058 typedef moab::EntityID difference_type; 00059 typedef std::output_iterator_tag iterator_category; 00060 typedef moab::EntityHandle* pointer; 00061 typedef moab::EntityHandle& reference; 00062 }; 00063 00064 } // namespace internal 00065 00066 //will store a collection of entities that are used only once with a given 00067 //owner id 00068 class UsageTable 00069 { 00070 public: 00071 void incrementUsage( const std::vector< smoab::EntityHandle >& entities, const std::vector< int >& usageId ); 00072 00073 smoab::Range multipleUsage() const; 00074 smoab::Range singleUsage() const; 00075 00076 private: 00077 std::vector< smoab::EntityHandle > MultipleUsageIds; 00078 std::set< internal::KeyType > SingleUsageIds; 00079 }; 00080 00081 //---------------------------------------------------------------------------- 00082 void UsageTable::incrementUsage( const std::vector< smoab::EntityHandle >& entities, 00083 const std::vector< int >& usageId ) 00084 { 00085 typedef std::vector< smoab::EntityHandle >::const_iterator iterator; 00086 typedef std::vector< int >::const_iterator uiterator; 00087 00088 uiterator usage = usageId.begin(); 00089 for( iterator i = entities.begin(); i != entities.end(); ++i, ++usage ) 00090 { 00091 internal::KeyType key( *i, *usage ); 00092 if( this->SingleUsageIds.find( key ) != this->SingleUsageIds.end() ) 00093 { 00094 this->SingleUsageIds.erase( key ); 00095 this->MultipleUsageIds.push_back( *i ); 00096 } 00097 else 00098 { 00099 this->SingleUsageIds.insert( key ); 00100 } 00101 } 00102 } 00103 00104 //---------------------------------------------------------------------------- 00105 smoab::Range UsageTable::multipleUsage() const 00106 { 00107 smoab::Range multiples; 00108 std::copy( this->MultipleUsageIds.rbegin(), this->MultipleUsageIds.rend(), moab::range_inserter( multiples ) ); 00109 return multiples; 00110 } 00111 00112 //---------------------------------------------------------------------------- 00113 smoab::Range UsageTable::singleUsage() const 00114 { 00115 smoab::Range single; 00116 std::copy( this->SingleUsageIds.rbegin(), this->SingleUsageIds.rend(), internal::key_inserter( single ) ); 00117 return single; 00118 } 00119 00120 } // namespace detail 00121 } // namespace smoab 00122 #endif