CFx SDK Documentation  2023 SP0
Int64.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 
26 
27 #ifndef _INC_ODAINT64_38FF72C90128_INCLUDED
28 #define _INC_ODAINT64_38FF72C90128_INCLUDED
29 
30 #ifndef EMCC
31 #error "If this code is used anywhere?"
32 #endif
33 
34 #include "TD_PackPush.h"
35 #include "OdHeap.h"
36 
42 class OdInt64
43 {
44 public:
49  inline OdInt64& operator=(const OdInt64& n);
50  OdInt64& operator=(int n);
51  OdInt64() : low(0), hi(0) { }
52  OdInt64(int n) { hi = (n>=0 ? 0 : -1); low = n; }
53  OdInt64(const OdInt64& n) { *this = n; }
55  inline OdInt64 operator+(const OdInt64& n) const {return (OdInt64(*this)+=n);}
56  inline OdInt64& operator-=(const OdInt64 n) { return (*this += -n); }
57  inline OdInt64 operator-(const OdInt64& n) const {return (OdInt64(*this)-=n);}
58  inline OdInt64 operator/(const OdInt32& n) const {return (OdInt64(*this)/=n);}
60  OdUInt32 operator%(OdUInt32 n)const{return ((2<<31)%n*2*(hi%n)+(low%n))%n; }
61  inline OdInt64& operator++();
62  inline OdInt64 operator++(int /*dummy*/);
63  inline OdInt64& operator--();
64  inline bool operator>(const OdInt64& n) const;
65  inline bool operator<(const OdInt64& n) const;
66  inline bool operator>=(const OdInt64& n) const;
67  inline bool operator<=(const OdInt64& n) const;
68  inline bool operator!=(const OdInt64& n) const;
69  inline bool operator==(const OdInt64& n) const;
70 
72  { return low & mask;}
73 
78  inline bool operator!=(int n) const;
83  inline bool operator==(int n) const;
84 
85  bool operator>(int n) const { return operator>(OdInt64(n)); }
86  bool operator<(int n) const { return operator<(OdInt64(n)); }
87 
88  inline OdInt64 operator-() const;
91  {
92  while(n--) { *this += *this; }
93  return *this;
94  }
95  OdInt64 operator >>(int n) const
96  {
97  OdInt64 res = *this;
98  return (res>>=n);
99  }
100  OdInt64 operator <<(int n) const
101  {
102  OdInt64 res = *this;
103  return (res<<=n);
104  }
105 
107  {
108  OdInt64 res;
109  res.low = low | n.low;
110  res.hi = hi | n.hi;
111  return res;
112  }
113 
115  {
116  low |= n.low;
117  hi |= n.hi;
118  return *this;
119  }
120 
121 protected:
122 #ifdef ODA_BIGENDIAN
123  OdInt32 hi;
124  OdUInt32 low;
125 #else
128 #endif
129 };
130 
136 class OdUInt64 : public OdInt64
137 {
138 public :
139  OdUInt64 () { }
140  OdUInt64 (int n) : OdInt64(n) { }
141  OdUInt64 (const OdInt64& n) : OdInt64(n) { }
142  OdUInt64 (const OdUInt64& n) : OdInt64(n) { }
143 
144  bool operator > (const OdUInt64& n) const
145  {
146  if (hi == n.hi)
147  return low > n.low;
148  // else
149  return OdUInt32(hi) > OdUInt32(n.hi);
150  }
151  bool operator < (const OdUInt64& n) const
152  {
153  return (!operator>(n) && operator!=(n));
154  }
155  bool operator>(int n) const { return operator>(OdUInt64(n)); }
156  bool operator<(int n) const { return operator<(OdUInt64(n)); }
157 
158  OdUInt64 operator >>(int n) const
159  {
160  OdUInt64 res = *this;
161  return (res>>=n);
162  }
164 };
165 
166 //----------------------------------------------------------
167 //
168 // OdInt64 inline methods
169 //
170 //----------------------------------------------------------
172 {
173  hi = (n>=0 ? 0 : -1);
174  low = OdUInt32(n);
175  return *this;
176 }
177 
179 {
180  return (*this += 1);
181 }
182 
183 inline OdInt64 OdInt64::operator++(int /*dummy*/)
184 {
185  OdInt64 t = *this;
186  *this += 1;
187  return t;
188 }
189 
191 {
192  return (*this += -1);
193 }
194 
195 inline bool OdInt64::operator > (const OdInt64& n) const
196 {
197  if (hi == n.hi)
198  return low > n.low;
202  return hi > n.hi;
203 }
204 
205 inline bool OdInt64::operator < (const OdInt64& n) const
206 {
207  return (!operator>(n) && operator!=(n));
208 }
209 
210 inline bool OdInt64::operator >= (const OdInt64& n) const
211 {
212  return (operator>(n) || operator==(n));
213 }
214 
215 inline bool OdInt64::operator <= (const OdInt64& n) const
216 {
217  return (operator<(n) || operator==(n));
218 }
219 
220 inline bool OdInt64::operator!=(int n) const
221 {
222  return (!operator==(n));
223 }
224 
225 inline bool OdInt64::operator!=(const OdInt64& n) const
226 {
227  return (hi != n.hi || low != n.low);
228 }
229 
230 inline bool OdInt64::operator==(int n) const
231 {
232  return (hi == (n >= 0 ? 0 : -1) && low == OdUInt32(n));
233 }
234 
235 inline bool OdInt64::operator==(const OdInt64& n) const
236 {
237  return (hi == n.hi && low == n.low);
238 }
239 
241 {
242  OdInt64 res;
243  res.hi = ~hi; res.low =~low;
244  return (res += 1);
245 }
246 
248 {
249  low = n.low;
250  hi = n.hi;
251  return *this;
252 }
253 
254 #include "TD_PackPop.h"
255 
256 #endif /* _INC_ODAINT64_38FF72C90128_INCLUDED */
unsigned int OdUInt32
int OdInt32
Definition: Int64.h:43
bool operator>(int n) const
Definition: Int64.h:85
OdInt64 operator-() const
Definition: Int64.h:240
OdInt64 & operator--()
Definition: Int64.h:190
bool operator>(const OdInt64 &n) const
Definition: Int64.h:195
bool operator<(int n) const
Definition: Int64.h:86
OdInt64 & operator/=(const OdInt32 &n)
OdInt64 operator>>(int n) const
Definition: Int64.h:95
OdUInt32 low
Definition: Int64.h:126
OdInt64 operator|(const OdInt64 &n)
Definition: Int64.h:106
OdInt32 hi
Definition: Int64.h:127
bool operator>=(const OdInt64 &n) const
Definition: Int64.h:210
bool operator!=(const OdInt64 &n) const
Definition: Int64.h:225
OdInt64 operator+(const OdInt64 &n) const
Definition: Int64.h:55
OdUInt32 operator%(OdUInt32 n) const
Definition: Int64.h:60
OdInt64 operator<<(int n) const
Definition: Int64.h:100
OdInt64 & operator++()
Definition: Int64.h:178
OdInt64 operator/(const OdInt32 &n) const
Definition: Int64.h:58
OdInt64 & operator|=(const OdInt64 &n)
Definition: Int64.h:114
OdInt64(int n)
Definition: Int64.h:52
OdUInt32 operator&(OdUInt32 mask) const
Definition: Int64.h:71
OdInt64 & operator-=(const OdInt64 n)
Definition: Int64.h:56
OdInt64 & operator=(const OdInt64 &n)
Definition: Int64.h:247
OdInt64 & operator<<=(int n)
Definition: Int64.h:90
OdInt64(const OdInt64 &n)
Definition: Int64.h:53
bool operator==(const OdInt64 &n) const
Definition: Int64.h:235
OdInt64 & operator+=(const OdInt64 &n)
OdInt64 operator-(const OdInt64 &n) const
Definition: Int64.h:57
OdInt64 & operator>>=(int n)
OdInt64()
Definition: Int64.h:51
bool operator<(const OdInt64 &n) const
Definition: Int64.h:205
bool operator<=(const OdInt64 &n) const
Definition: Int64.h:215
bool operator<(int n) const
Definition: Int64.h:156
OdUInt64(const OdUInt64 &n)
Definition: Int64.h:142
bool operator>(const OdUInt64 &n) const
Definition: Int64.h:144
bool operator>(int n) const
Definition: Int64.h:155
bool operator<(const OdUInt64 &n) const
Definition: Int64.h:151
OdUInt64(int n)
Definition: Int64.h:140
OdUInt64()
Definition: Int64.h:139
OdUInt64 operator>>(int n) const
Definition: Int64.h:158
OdUInt64 & operator>>=(int n)
OdUInt64(const OdInt64 &n)
Definition: Int64.h:141
GLenum GLint GLuint mask
Definition: gles2_ext.h:262