moab
|
00001 00017 #ifndef MB_INTERNALS_HPP 00018 #define MB_INTERNALS_HPP 00019 00020 #ifdef WIN32 00021 #pragma warning(disable : 4786) 00022 #endif 00023 00024 #ifndef IS_BUILDING_MB 00025 #error "Internals.hpp isn't supposed to be included into an application" 00026 #endif 00027 00028 #include "moab/Types.hpp" 00029 #include <assert.h> 00030 00031 namespace moab { 00032 00045 #define MB_TYPE_WIDTH 4 00046 #define MB_ID_WIDTH (8*sizeof(EntityHandle)-MB_TYPE_WIDTH) 00047 #define MB_TYPE_MASK ((EntityHandle)0xF << MB_ID_WIDTH) 00048 // 2^MB_TYPE_WIDTH-1 ------^ 00049 00050 #define MB_START_ID ((EntityID)1) //!< All entity id's currently start at 1 00051 #define MB_END_ID ((EntityID)MB_ID_MASK) //!< Last id is the complement of the MASK 00052 #define MB_ID_MASK (~MB_TYPE_MASK) 00053 00055 inline EntityHandle CREATE_HANDLE(const unsigned type, const EntityID id, int& err) 00056 { 00057 err = 0; //< Assume that there is a real error value defined somewhere 00058 00059 if (id > MB_END_ID || type > MBMAXTYPE) 00060 { 00061 err = 1; //< Assume that there is a real error value defined somewhere 00062 return 1; //<You've got to return something. What do you return? 00063 } 00064 00065 return (((EntityHandle)type) << MB_ID_WIDTH)|id; 00066 } 00067 00068 inline EntityHandle CREATE_HANDLE( const unsigned type, const EntityID id ) 00069 { 00070 assert( id <= MB_END_ID && type <= MBMAXTYPE ); 00071 return (((EntityHandle)type) << MB_ID_WIDTH)|id; 00072 } 00073 00074 inline EntityHandle FIRST_HANDLE( unsigned type ) 00075 { return (((EntityHandle)type) << MB_ID_WIDTH)|MB_START_ID; } 00076 00077 inline EntityHandle LAST_HANDLE( unsigned type ) 00078 { return ((EntityHandle)(type+1) << MB_ID_WIDTH) - 1; } 00079 00081 inline EntityID ID_FROM_HANDLE (EntityHandle handle) 00082 { 00083 return (handle & MB_ID_MASK); 00084 } 00085 00088 inline EntityType TYPE_FROM_HANDLE(EntityHandle handle) 00089 { 00090 return static_cast<EntityType> (handle >> MB_ID_WIDTH); 00091 } 00092 00093 } // namespace moab 00094 00095 #endif