Salome HOME
[EDF30062] [EDF29150]: Additional fault tolerant mecanism
[modules/kernel.git] / src / Basics / smIdType.hxx.in
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SALOME Basics : general SALOME definitions and tools (C++ part - no CORBA)
21 //  File   : smIdType.hxx
22
23 #ifndef _SMIDTYPE_HXX_
24 #define _SMIDTYPE_HXX_
25
26 #cmakedefine SALOME_USE_64BIT_IDS
27
28 #include "Basics_OCCTVersion.hxx"
29
30 #include <cinttypes>
31 #include <cstddef>
32 #include <limits>
33
34 #ifndef SALOME_USE_64BIT_IDS
35 typedef std::int32_t smIdType;
36 #else
37 typedef std::int64_t smIdType;
38 #endif
39
40 struct smIdHasher
41 {
42 #if OCC_VERSION_LARGE < 0x07080000
43   static int HashCode(const smIdType theValue,  const int theUpperBound)
44   {
45     return static_cast<int> ((theValue & std::numeric_limits<smIdType>::max()) % theUpperBound + 1);
46   }
47
48   static bool IsEqual( const smIdType& id1, const smIdType& id2 )
49   {
50     return id1 == id2;
51   }
52 #else
53   size_t operator()(const smIdType theValue) const
54   {
55     return static_cast<size_t> (theValue & std::numeric_limits<smIdType>::max());
56   }
57   bool operator()(const smIdType& theValue1, const smIdType& theValue2) const
58   {
59     return theValue1 == theValue2;
60   }
61 #endif
62 };
63
64 template <class T> inline smIdType ToSmIdType(T val)
65 {
66   return static_cast<smIdType>(val);
67 }
68 template <class T> inline T FromSmIdType(smIdType val)
69 {
70   return static_cast<T>(val);
71 }
72
73 #endif //_SMIDTYPE_HXX_