Branch data Line data Source code
1 : : /**
2 : : * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3 : : * storing and accessing finite element mesh data.
4 : : *
5 : : * Copyright 2004 Sandia Corporation. Under the terms of Contract
6 : : * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7 : : * retains certain rights in this software.
8 : : *
9 : : * This library is free software; you can redistribute it and/or
10 : : * modify it under the terms of the GNU Lesser General Public
11 : : * License as published by the Free Software Foundation; either
12 : : * version 2.1 of the License, or (at your option) any later version.
13 : : *
14 : : */
15 : :
16 : : #ifndef MB_INTERNALS_HPP
17 : : #define MB_INTERNALS_HPP
18 : :
19 : : #ifdef WIN32
20 : : #pragma warning( disable : 4786 )
21 : : #endif
22 : :
23 : : #ifndef IS_BUILDING_MB
24 : : #error "Internals.hpp isn't supposed to be included into an application"
25 : : #endif
26 : :
27 : : #include "moab/Types.hpp"
28 : : #include <assert.h>
29 : :
30 : : namespace moab
31 : : {
32 : :
33 : : /*! Define EntityHandle for both 32 bit and 64 bit systems.
34 : : * The decision to use 64 bit handles must be made at compile time.
35 : : * \bug we should probably have an Int64 typedef
36 : : *
37 : : * EntityHandle format:
38 : : * 0xXYYYYYYY (assuming a 32-bit handle. Top 4 bits reserved on a 64 bit system)
39 : : * X - reserved for entity type. This system can only handle 15 different types
40 : : * Y - Entity id space. Max id is over 200M
41 : : *
42 : : * Note that for specialized databases (such as all hex) 16 bits are not
43 : : * required for the entity type and the id space can be increased to over 2B.
44 : : */
45 : : #define MB_TYPE_WIDTH 4
46 : : #define MB_ID_WIDTH ( 8 * sizeof( EntityHandle ) - MB_TYPE_WIDTH )
47 : : #define MB_TYPE_MASK ( (EntityHandle)0xF << MB_ID_WIDTH )
48 : : // 2^MB_TYPE_WIDTH-1 ------^
49 : :
50 : : #define MB_START_ID ( (EntityID)1 ) //!< All entity id's currently start at 1
51 : : #define MB_END_ID ( (EntityID)MB_ID_MASK ) //!< Last id is the complement of the MASK
52 : : #define MB_ID_MASK ( ~MB_TYPE_MASK )
53 : :
54 : : //! Given a type and an id create a handle.
55 : 20696195 : inline EntityHandle CREATE_HANDLE( const unsigned type, const EntityID id, int& err )
56 : : {
57 : 20696195 : err = 0; //< Assume that there is a real error value defined somewhere
58 : :
59 [ + - ][ - + ]: 20696195 : if( id > MB_END_ID || type > MBMAXTYPE )
60 : : {
61 : 0 : err = 1; //< Assume that there is a real error value defined somewhere
62 : 0 : return 1; //<You've got to return something. What do you return?
63 : : }
64 : :
65 : 20696195 : return ( ( (EntityHandle)type ) << MB_ID_WIDTH ) | id;
66 : : }
67 : :
68 : 5129583 : inline EntityHandle CREATE_HANDLE( const unsigned type, const EntityID id )
69 : : {
70 [ + - ][ - + ]: 5129583 : assert( id <= MB_END_ID && type <= MBMAXTYPE );
71 : 5129583 : return ( ( (EntityHandle)type ) << MB_ID_WIDTH ) | id;
72 : : }
73 : :
74 : 1471823 : inline EntityHandle FIRST_HANDLE( unsigned type )
75 : : {
76 : 1471823 : return ( ( (EntityHandle)type ) << MB_ID_WIDTH ) | MB_START_ID;
77 : : }
78 : :
79 : 1420163 : inline EntityHandle LAST_HANDLE( unsigned type )
80 : : {
81 : 1420163 : return ( ( EntityHandle )( type + 1 ) << MB_ID_WIDTH ) - 1;
82 : : }
83 : :
84 : : //! Get the entity id out of the handle.
85 : 27751760 : inline EntityID ID_FROM_HANDLE( EntityHandle handle )
86 : : {
87 : 27751760 : return ( handle & MB_ID_MASK );
88 : : }
89 : :
90 : : //! Get the type out of the handle. Can do a simple shift because
91 : : //! handles are unsigned (therefore shifting fills with zero's)
92 : 152640644 : inline EntityType TYPE_FROM_HANDLE( EntityHandle handle )
93 : : {
94 : 152640644 : return static_cast< EntityType >( handle >> MB_ID_WIDTH );
95 : : }
96 : :
97 : : } // namespace moab
98 : :
99 : : #endif
|