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