|
Sierra Toolkit Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #ifndef stk_mesh_EntityKey_hpp 00010 #define stk_mesh_EntityKey_hpp 00011 00012 #include <stdint.h> 00013 #include <limits> 00014 00015 #include <stk_mesh/base/Types.hpp> 00016 00017 namespace stk { 00018 namespace mesh { 00019 00020 00021 // Note: EntityRank and EntityId typedefs are defined in Types.hpp 00022 00027 //---------------------------------------------------------------------- 00062 union EntityKey { 00063 public: 00064 typedef uint64_t raw_key_type ; 00065 00066 enum { rank_digits = 8 }; 00067 00068 private: 00069 00070 enum { 00071 invalid_key = ~raw_key_type(0) , 00072 raw_digits = std::numeric_limits<raw_key_type>::digits , 00073 id_digits = raw_digits - rank_digits , 00074 id_mask = ~raw_key_type(0) >> rank_digits 00075 }; 00076 00077 raw_key_type key ; 00078 00079 struct { 00080 raw_key_type id : id_digits ; 00081 raw_key_type rank : rank_digits ; 00082 } normal_view ; 00083 00084 struct { 00085 raw_key_type rank : rank_digits ; 00086 raw_key_type id : id_digits ; 00087 } reverse_view ; 00088 00089 public: 00091 ~EntityKey() {} 00092 00096 EntityKey() : key(invalid_key) { } 00097 00098 EntityKey( const EntityKey & rhs ) : key( rhs.key ) {} 00099 00100 EntityKey & operator = ( const EntityKey & rhs ) 00101 { key = rhs.key ; return *this ; } 00102 00114 EntityKey( EntityRank entity_rank, raw_key_type entity_id ); 00115 00116 raw_key_type id() const { return key & id_mask ; } 00117 00118 EntityRank rank() const { return key >> id_digits ; } 00119 00120 EntityRank type() const { return rank(); } 00121 00122 bool operator==(const EntityKey &rhs) const { 00123 return key == rhs.key; 00124 } 00125 00126 bool operator!=(const EntityKey &rhs) const { 00127 return !(key == rhs.key); 00128 } 00129 00130 bool operator<(const EntityKey &rhs) const { 00131 return key < rhs.key; 00132 } 00133 00134 bool operator>(const EntityKey &rhs) const { 00135 return rhs.key < key; 00136 } 00137 00138 bool operator<=(const EntityKey &rhs) const { 00139 return !(key < rhs.key); 00140 } 00141 00142 bool operator>=(const EntityKey &rhs) const { 00143 return !(rhs.key < key); 00144 } 00145 00146 //------------------------------ 00147 // As safe and explict a conversion 00148 // as possible between the raw_key_type and value. 00149 00150 explicit EntityKey( const raw_key_type * const value ) 00151 : key( *value ) {} 00152 00153 raw_key_type raw_key() const { return key ; } 00154 }; 00155 00156 // Functions for encoding / decoding entity keys. 00157 00159 inline 00160 EntityRank entity_rank( const EntityKey & key ) { 00161 return key.rank(); 00162 } 00163 00165 inline 00166 EntityId entity_id( const EntityKey & key ) { 00167 return key.id(); 00168 } 00169 00171 inline 00172 bool entity_key_valid( const EntityKey & key ) { 00173 return key != EntityKey(); 00174 } 00175 00176 inline 00177 bool entity_id_valid( EntityKey::raw_key_type id ) { 00178 return 0 < id && id <= EntityKey().id(); 00179 } 00180 00181 } // namespace mesh 00182 } // namespace stk 00183 00184 #endif /* stk_mesh_EntityKey_hpp */ 00185