MOAB: Mesh Oriented datABase  (version 5.4.1)
Internals.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifndef MB_INTERNALS_HPP
00017 #define MB_INTERNALS_HPP
00018 
00019 #ifdef WIN32
00020 #pragma warning( disable : 4786 )
00021 #endif
00022 
00023 #ifndef IS_BUILDING_MB
00024 #error "Internals.hpp isn't supposed to be included into an application"
00025 #endif
00026 
00027 #include "moab/Types.hpp"
00028 #include <cassert>
00029 
00030 namespace moab
00031 {
00032 
00033 /*! Define EntityHandle for both 32 bit and 64 bit systems.
00034  *  The decision to use 64 bit handles must be made at compile time.
00035  *  \bug we should probably have an Int64 typedef
00036  *
00037  *  EntityHandle format:
00038  *  0xXYYYYYYY  (assuming a 32-bit handle.  Top 4 bits reserved on a 64 bit system)
00039  *  X - reserved for entity type.  This system can only handle 15 different types
00040  *  Y - Entity id space.  Max id is over 200M
00041  *
00042  *  Note that for specialized databases (such as all hex) 16 bits are not
00043  *  required for the entity type and the id space can be increased to over 2B.
00044  */
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 
00054 //! Given a type and an id create a handle.
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 {
00076     return ( ( (EntityHandle)type ) << MB_ID_WIDTH ) | MB_START_ID;
00077 }
00078 
00079 inline EntityHandle LAST_HANDLE( unsigned type )
00080 {
00081     return ( (EntityHandle)( type + 1 ) << MB_ID_WIDTH ) - 1;
00082 }
00083 
00084 //! Get the entity id out of the handle.
00085 inline EntityID ID_FROM_HANDLE( EntityHandle handle )
00086 {
00087     return ( handle & MB_ID_MASK );
00088 }
00089 
00090 //! Get the type out of the handle.  Can do a simple shift because
00091 //! handles are unsigned (therefore shifting fills with zero's)
00092 inline EntityType TYPE_FROM_HANDLE( EntityHandle handle )
00093 {
00094     return static_cast< EntityType >( handle >> MB_ID_WIDTH );
00095 }
00096 
00097 }  // namespace moab
00098 
00099 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines