0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / Standard / Standard_Integer.hxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
a174a3c5 2// Copyright (c) 1999-2013 OPEN CASCADE SAS
b311480e 3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#ifndef _Standard_Integer_HeaderFile
20#define _Standard_Integer_HeaderFile
21
22#ifndef _Standard_TypeDef_HeaderFile
23#include <Standard_TypeDef.hxx>
24#endif
25
26#ifndef _Standard_values_HeaderFile
27# include <Standard_values.h>
28#endif
29
30class Handle_Standard_Type;
31
34781c33 32__Standard_API const Handle_Standard_Type& Standard_Integer_Type_();
7fd59977 33// ===============================================
34// Methods from Standard_Entity class which are redefined:
35// - Hascode
36// - IsEqual
37// - IsSimilar
38// - Shallowcopy
39// - ShallowDump
40// ===============================================
41
42// ==================================
43// Methods implemeted in Standard_Integer.cxx
44// ==================================
45__Standard_API Standard_Integer NextPrimeForMap(const Standard_Integer anInt ) ;
46__Standard_API long NextPrime (const long me);
47__Standard_API Standard_Integer CharToInt (const Standard_Character me);
48__Standard_API Standard_Integer CharToInt (const Standard_CString me);
49__Standard_API Standard_Integer ShallowCopy (const Standard_Integer me);
7fd59977 50
51// ===============
52// Inline methods
53// ===============
54
55// ------------------------------------------------------------------
56// Abs : Returns the absolute value of an Integer
57// ------------------------------------------------------------------
58inline Standard_Integer Abs (const Standard_Integer Value)
59{
60 return Value >= 0 ? Value : -Value;
61}
62
63// ------------------------------------------------------------------
64// Hascode : Computes a hascoding value for a given Integer
65// ------------------------------------------------------------------
a174a3c5 66inline Standard_Integer HashCode (const Standard_Integer theMe,
67 const Standard_Integer theUpper)
7fd59977 68{
a174a3c5 69 //return (Abs (theMe) % theUpper) + 1;
70 return ((theMe & 0x7fffffff ) % theUpper) + 1;
7fd59977 71}
72
73// ------------------------------------------------------------------
74// IsEqual : Returns Standard_True if two integers are equal
75// ------------------------------------------------------------------
a174a3c5 76inline Standard_Boolean IsEqual (const Standard_Integer theOne,
77 const Standard_Integer theTwo)
78{
79 return theOne == theTwo;
80}
81
82#if (defined(_LP64) || defined(__LP64__) || defined(_WIN64))
83// ------------------------------------------------------------------
84// Hascode : Computes a hascoding value for a given unsigned integer
85// ------------------------------------------------------------------
86inline Standard_Integer HashCode (const Standard_Utf32Char theMe,
87 const Standard_Integer theUpper)
88{
89 return ((theMe & 0x7fffffff ) % theUpper) + 1;
90}
91
92// ------------------------------------------------------------------
93// IsEqual : Returns Standard_True if two integers are equal
94// ------------------------------------------------------------------
95inline Standard_Boolean IsEqual (const Standard_Utf32Char theOne,
96 const Standard_Utf32Char theTwo)
97{
98 return theOne == theTwo;
99}
100#endif
7fd59977 101
102// ------------------------------------------------------------------
103// IsSimilar : Returns Standard_True if two integers are equal
104// ------------------------------------------------------------------
105inline Standard_Boolean IsSimilar (const Standard_Integer One,
106 const Standard_Integer Two)
107{ return One == Two; }
108
109
110// ------------------------------------------------------------------
111// IsEven : Returns Standard_True if an integer is even
112// ------------------------------------------------------------------
113inline Standard_Boolean IsEven (const Standard_Integer Value)
114{ return Value % 2 == 0; }
115
116
117// ------------------------------------------------------------------
118// IsOdd : Returns Standard_True if an integer is odd
119// ------------------------------------------------------------------
120inline Standard_Boolean IsOdd (const Standard_Integer Value)
121{ return Value % 2 == 1; }
122
123// ------------------------------------------------------------------
124// Max : Returns the maximum integer between two integers
125// ------------------------------------------------------------------
126inline Standard_Integer Max (const Standard_Integer Val1,
127 const Standard_Integer Val2)
128{
129 return Val1 >= Val2 ? Val1 : Val2;
130}
131
132// ------------------------------------------------------------------
133// Min : Returns the minimum integer between two integers
134// ------------------------------------------------------------------
135inline Standard_Integer Min (const Standard_Integer Val1,
136 const Standard_Integer Val2)
137{
138 return Val1 <= Val2 ? Val1 : Val2;
139}
140
141// ------------------------------------------------------------------
142// Modulus : Returns the remainder of division between two integers
143// ------------------------------------------------------------------
144inline Standard_Integer Modulus (const Standard_Integer Value,
145 const Standard_Integer Divisor)
146{ return Value % Divisor; }
147
148// ------------------------------------------------------------------
149// Square : Returns the square of an integer
150// ------------------------------------------------------------------
151inline Standard_Integer Square(const Standard_Integer Value)
152{ return Value * Value; }
153
154// ------------------------------------------------------------------
155// IntegerFirst : Returns the minimum value of an integer
156// ------------------------------------------------------------------
157inline Standard_Integer IntegerFirst()
158{ return INT_MIN; }
159
160// ------------------------------------------------------------------
161// IntegerLast : Returns the maximum value of an integer
162// ------------------------------------------------------------------
163inline Standard_Integer IntegerLast()
164{ return INT_MAX; }
165
166// ------------------------------------------------------------------
167// IntegerSize : Returns the size in digits of an integer
168// ------------------------------------------------------------------
169inline Standard_Integer IntegerSize()
170{ return BITS(Standard_Integer); }
171
172#endif