b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
a174a3c5 |
2 | // Copyright (c) 1999-2013 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #ifndef _Standard_Integer_HeaderFile |
16 | #define _Standard_Integer_HeaderFile |
17 | |
7fd59977 |
18 | #include <Standard_TypeDef.hxx> |
2cb44241 |
19 | #include <Standard_values.h> |
7fd59977 |
20 | |
21 | // =============== |
22 | // Inline methods |
23 | // =============== |
24 | |
25 | // ------------------------------------------------------------------ |
26 | // Abs : Returns the absolute value of an Integer |
27 | // ------------------------------------------------------------------ |
28 | inline Standard_Integer Abs (const Standard_Integer Value) |
29 | { |
30 | return Value >= 0 ? Value : -Value; |
31 | } |
32 | |
33 | // ------------------------------------------------------------------ |
34 | // Hascode : Computes a hascoding value for a given Integer |
35 | // ------------------------------------------------------------------ |
a174a3c5 |
36 | inline Standard_Integer HashCode (const Standard_Integer theMe, |
37 | const Standard_Integer theUpper) |
7fd59977 |
38 | { |
a174a3c5 |
39 | //return (Abs (theMe) % theUpper) + 1; |
40 | return ((theMe & 0x7fffffff ) % theUpper) + 1; |
7fd59977 |
41 | } |
42 | |
43 | // ------------------------------------------------------------------ |
44 | // IsEqual : Returns Standard_True if two integers are equal |
45 | // ------------------------------------------------------------------ |
a174a3c5 |
46 | inline Standard_Boolean IsEqual (const Standard_Integer theOne, |
47 | const Standard_Integer theTwo) |
48 | { |
49 | return theOne == theTwo; |
50 | } |
51 | |
52 | #if (defined(_LP64) || defined(__LP64__) || defined(_WIN64)) |
53 | // ------------------------------------------------------------------ |
54 | // Hascode : Computes a hascoding value for a given unsigned integer |
55 | // ------------------------------------------------------------------ |
56 | inline Standard_Integer HashCode (const Standard_Utf32Char theMe, |
57 | const Standard_Integer theUpper) |
58 | { |
59 | return ((theMe & 0x7fffffff ) % theUpper) + 1; |
60 | } |
61 | |
62 | // ------------------------------------------------------------------ |
63 | // IsEqual : Returns Standard_True if two integers are equal |
64 | // ------------------------------------------------------------------ |
65 | inline Standard_Boolean IsEqual (const Standard_Utf32Char theOne, |
66 | const Standard_Utf32Char theTwo) |
67 | { |
68 | return theOne == theTwo; |
69 | } |
70 | #endif |
7fd59977 |
71 | |
72 | // ------------------------------------------------------------------ |
73 | // IsSimilar : Returns Standard_True if two integers are equal |
74 | // ------------------------------------------------------------------ |
75 | inline Standard_Boolean IsSimilar (const Standard_Integer One, |
76 | const Standard_Integer Two) |
77 | { return One == Two; } |
78 | |
79 | |
80 | // ------------------------------------------------------------------ |
81 | // IsEven : Returns Standard_True if an integer is even |
82 | // ------------------------------------------------------------------ |
83 | inline Standard_Boolean IsEven (const Standard_Integer Value) |
84 | { return Value % 2 == 0; } |
85 | |
86 | |
87 | // ------------------------------------------------------------------ |
88 | // IsOdd : Returns Standard_True if an integer is odd |
89 | // ------------------------------------------------------------------ |
90 | inline Standard_Boolean IsOdd (const Standard_Integer Value) |
91 | { return Value % 2 == 1; } |
92 | |
93 | // ------------------------------------------------------------------ |
94 | // Max : Returns the maximum integer between two integers |
95 | // ------------------------------------------------------------------ |
96 | inline Standard_Integer Max (const Standard_Integer Val1, |
97 | const Standard_Integer Val2) |
98 | { |
99 | return Val1 >= Val2 ? Val1 : Val2; |
100 | } |
101 | |
102 | // ------------------------------------------------------------------ |
103 | // Min : Returns the minimum integer between two integers |
104 | // ------------------------------------------------------------------ |
105 | inline Standard_Integer Min (const Standard_Integer Val1, |
106 | const Standard_Integer Val2) |
107 | { |
108 | return Val1 <= Val2 ? Val1 : Val2; |
109 | } |
110 | |
111 | // ------------------------------------------------------------------ |
112 | // Modulus : Returns the remainder of division between two integers |
113 | // ------------------------------------------------------------------ |
114 | inline Standard_Integer Modulus (const Standard_Integer Value, |
115 | const Standard_Integer Divisor) |
116 | { return Value % Divisor; } |
117 | |
118 | // ------------------------------------------------------------------ |
119 | // Square : Returns the square of an integer |
120 | // ------------------------------------------------------------------ |
121 | inline Standard_Integer Square(const Standard_Integer Value) |
122 | { return Value * Value; } |
123 | |
124 | // ------------------------------------------------------------------ |
125 | // IntegerFirst : Returns the minimum value of an integer |
126 | // ------------------------------------------------------------------ |
127 | inline Standard_Integer IntegerFirst() |
128 | { return INT_MIN; } |
129 | |
130 | // ------------------------------------------------------------------ |
131 | // IntegerLast : Returns the maximum value of an integer |
132 | // ------------------------------------------------------------------ |
133 | inline Standard_Integer IntegerLast() |
134 | { return INT_MAX; } |
135 | |
136 | // ------------------------------------------------------------------ |
137 | // IntegerSize : Returns the size in digits of an integer |
138 | // ------------------------------------------------------------------ |
139 | inline Standard_Integer IntegerSize() |
140 | { return BITS(Standard_Integer); } |
141 | |
142 | #endif |