Salome HOME
[EDF29138] : measure CPU/Mem even in OutOfProcess mode
[modules/kernel.git] / src / Basics / smIdType.hxx.in
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, 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 <cinttypes>
29 #include <limits>
30
31 #ifndef SALOME_USE_64BIT_IDS
32 typedef std::int32_t smIdType;
33 #else
34 typedef std::int64_t smIdType;
35 #endif
36
37 struct smIdHasher
38 {
39   static int HashCode(const smIdType theValue,  const int theUpperBound)
40   {
41     return static_cast<int> ((theValue & std::numeric_limits<smIdType>::max()) % theUpperBound + 1);
42   }
43
44   static bool IsEqual( const smIdType& id1, const smIdType& id2 )
45   {
46     return id1 == id2;
47   }
48 };
49
50 template <class T> inline smIdType ToSmIdType(T val)
51 {
52   return static_cast<smIdType>(val);
53 }
54 template <class T> inline T FromSmIdType(smIdType val)
55 {
56   return static_cast<T>(val);
57 }
58
59 #endif //_SMIDTYPE_HXX_