Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

485 lines
11 KiB

  1. // Num64.h -- Classes for 64-bit integers and unsigned numbers
  2. // We define two classes here which provide arithmetic and bit shifting functions
  3. // for 64-bit signed and unsigned numbers. We use these classes instead of the
  4. // LONGLONG and DWORDLONG types so this code can be ported to environments which
  5. // don't have direct support for 64-bit data. In this implmentation we use inline
  6. // functions as a thin layer around the 64-bit support available in the Win32
  7. // environment.
  8. class CULINT;
  9. class CLINT
  10. {
  11. public:
  12. CLINT();
  13. CLINT(CLINT& cli);
  14. CLINT(LARGE_INTEGER li);
  15. CLINT(ULARGE_INTEGER uli);
  16. CLINT(LONGLONG ll);
  17. CLINT(CULINT culi);
  18. BOOL NonZero();
  19. friend CLINT operator- (const CLINT& cliRight);
  20. friend CLINT operator+ (const CLINT& cliLeft, const CLINT& cliRight);
  21. friend CLINT operator- (const CLINT& cliLeft, const CLINT& cliRight);
  22. friend CLINT operator* (const CLINT& cliLeft, const CLINT& cliRight);
  23. friend CLINT operator/ (const CLINT& cliLeft, const CLINT& cliRight);
  24. friend CLINT operator| (const CLINT& cliLeft, const CLINT& cliRight);
  25. friend CLINT operator<< (const CLINT& cliLeft, UINT cbits);
  26. friend CLINT operator>> (const CLINT& cliLeft, UINT cbits);
  27. friend BOOL operator< (const CLINT& cliLeft, const CLINT& cliRight);
  28. friend BOOL operator<= (const CLINT& cliLeft, const CLINT& cliRight);
  29. friend BOOL operator== (const CLINT& cliLeft, const CLINT& cliRight);
  30. friend BOOL operator>= (const CLINT& cliLeft, const CLINT& cliRight);
  31. friend BOOL operator> (const CLINT& cliLeft, const CLINT& cliRight);
  32. friend BOOL operator!= (const CLINT& cliLeft, const CLINT& cliRight);
  33. CLINT& operator= (const CLINT& cliRight);
  34. CLINT& operator+= (const CLINT& cliRight);
  35. CLINT& operator-= (const CLINT& cliRight);
  36. CLINT& operator*= (const CLINT& cliRight);
  37. CLINT& operator/= (const CLINT& cliRight);
  38. CLINT& operator|= (const CLINT& cliRight);
  39. CLINT& operator<<=(UINT cbits);
  40. CLINT& operator>>=(UINT cbits);
  41. LARGE_INTEGER Li();
  42. LONGLONG Ll();
  43. private:
  44. LONGLONG QuadPart;
  45. };
  46. typedef CLINT *PCLINT;
  47. class CULINT
  48. {
  49. public:
  50. CULINT();
  51. CULINT(CULINT& cli);
  52. CULINT(LARGE_INTEGER li);
  53. CULINT(ULARGE_INTEGER uli);
  54. CULINT(DWORDLONG dwl);
  55. CULINT(CLINT cli);
  56. BOOL NonZero();
  57. friend CULINT operator- (const CULINT& culiRight);
  58. friend CULINT operator+ (const CULINT& culiLeft, const CULINT& culiRight);
  59. friend CULINT operator- (const CULINT& culiLeft, const CULINT& culiRight);
  60. friend CULINT operator* (const CULINT& culiLeft, const CULINT& culiRight);
  61. friend CULINT operator/ (const CULINT& culiLeft, const CULINT& culiRight);
  62. friend CULINT operator| (const CULINT& culiLeft, const CULINT& culiRight);
  63. friend CULINT operator<< (const CULINT& culiLeft, UINT cbits);
  64. friend CULINT operator>> (const CULINT& culiLeft, UINT cbits);
  65. friend BOOL operator< (const CULINT& culiLeft, const CULINT& culiRight);
  66. friend BOOL operator<= (const CULINT& culiLeft, const CULINT& culiRight);
  67. friend BOOL operator== (const CULINT& culiLeft, const CULINT& culiRight);
  68. friend BOOL operator>= (const CULINT& culiLeft, const CULINT& culiRight);
  69. friend BOOL operator> (const CULINT& culiLeft, const CULINT& culiRight);
  70. friend BOOL operator!= (const CULINT& culiLeft, const CULINT& culiRight);
  71. CULINT& operator= (const CULINT& culiRight);
  72. CULINT& operator+= (const CULINT& culiRight);
  73. CULINT& operator-= (const CULINT& culiRight);
  74. CULINT& operator*= (const CULINT& culiRight);
  75. CULINT& operator/= (const CULINT& culiRight);
  76. CULINT& operator|= (const CULINT& culiRight);
  77. CULINT& operator<<=(UINT cbits);
  78. CULINT& operator>>=(UINT cbits);
  79. ULARGE_INTEGER Uli();
  80. DWORDLONG Ull();
  81. private:
  82. DWORDLONG QuadPart;
  83. };
  84. typedef CULINT *PCULINT;
  85. inline CLINT::CLINT()
  86. {
  87. }
  88. inline CLINT::CLINT(CLINT& cli)
  89. {
  90. QuadPart = cli.QuadPart;
  91. }
  92. inline CLINT::CLINT(LARGE_INTEGER li)
  93. {
  94. QuadPart = li.QuadPart;
  95. }
  96. inline CLINT::CLINT(ULARGE_INTEGER uli)
  97. {
  98. QuadPart = (LONGLONG) uli.QuadPart;
  99. }
  100. inline CLINT::CLINT(CULINT culi)
  101. {
  102. QuadPart = (LONGLONG) culi.Uli().QuadPart;
  103. }
  104. inline CLINT::CLINT(LONGLONG ll)
  105. {
  106. QuadPart = ll;
  107. }
  108. inline BOOL CLINT::NonZero()
  109. {
  110. return QuadPart != 0;
  111. }
  112. inline CLINT operator- (const CLINT& cliRight)
  113. {
  114. CLINT cliResult(-cliRight.QuadPart);
  115. return cliResult;
  116. }
  117. inline CLINT operator+ (const CLINT& cliLeft, const CLINT& cliRight)
  118. {
  119. CLINT cliResult(cliLeft.QuadPart + cliRight.QuadPart);
  120. return cliResult;
  121. }
  122. inline CLINT operator- (const CLINT& cliLeft, const CLINT& cliRight)
  123. {
  124. CLINT cliResult(cliLeft.QuadPart - cliRight.QuadPart);
  125. return cliResult;
  126. }
  127. inline CLINT operator* (const CLINT& cliLeft, const CLINT& cliRight)
  128. {
  129. CLINT cliResult(cliLeft.QuadPart * cliRight.QuadPart);
  130. return cliResult;
  131. }
  132. inline CLINT operator/ (const CLINT& cliLeft, const CLINT& cliRight)
  133. {
  134. CLINT cliResult(cliLeft.QuadPart / cliRight.QuadPart);
  135. return cliResult;
  136. }
  137. inline CLINT operator| (const CLINT& cliLeft, const CLINT& cliRight)
  138. {
  139. CLINT cliResult(cliLeft.QuadPart | cliRight.QuadPart);
  140. return cliResult;
  141. }
  142. inline CLINT operator<< (const CLINT& cliLeft, UINT cbits)
  143. {
  144. CLINT cliResult(cliLeft.QuadPart << cbits);
  145. return cliResult;
  146. }
  147. inline CLINT operator>> (const CLINT& cliLeft, UINT cbits)
  148. {
  149. CLINT cliResult(cliLeft.QuadPart >> cbits);
  150. return cliResult;
  151. }
  152. inline BOOL operator< (const CLINT& cliLeft, const CLINT& cliRight)
  153. {
  154. return cliLeft.QuadPart < cliLeft.QuadPart;
  155. }
  156. inline BOOL operator<= (const CLINT& cliLeft, const CLINT& cliRight)
  157. {
  158. return cliLeft.QuadPart <= cliLeft.QuadPart;
  159. }
  160. inline BOOL operator== (const CLINT& cliLeft, const CLINT& cliRight)
  161. {
  162. return cliLeft.QuadPart == cliLeft.QuadPart;
  163. }
  164. inline BOOL operator>= (const CLINT& cliLeft, const CLINT& cliRight)
  165. {
  166. return cliLeft.QuadPart >= cliLeft.QuadPart;
  167. }
  168. inline BOOL operator> (const CLINT& cliLeft, const CLINT& cliRight)
  169. {
  170. return cliLeft.QuadPart > cliLeft.QuadPart;
  171. }
  172. inline BOOL operator!= (const CLINT& cliLeft, const CLINT& cliRight)
  173. {
  174. return cliLeft.QuadPart != cliLeft.QuadPart;
  175. }
  176. inline CLINT& CLINT::operator= (const CLINT& cliRight)
  177. {
  178. QuadPart = cliRight.QuadPart;
  179. return *this;
  180. }
  181. inline CLINT& CLINT::operator+= (const CLINT& cliRight)
  182. {
  183. QuadPart += cliRight.QuadPart;
  184. return *this;
  185. }
  186. inline CLINT& CLINT::operator-= (const CLINT& cliRight)
  187. {
  188. QuadPart -= cliRight.QuadPart;
  189. return *this;
  190. }
  191. inline CLINT& CLINT::operator*= (const CLINT& cliRight)
  192. {
  193. QuadPart *= cliRight.QuadPart;
  194. return *this;
  195. }
  196. inline CLINT& CLINT::operator/= (const CLINT& cliRight)
  197. {
  198. QuadPart /= cliRight.QuadPart;
  199. return *this;
  200. }
  201. inline CLINT& CLINT::operator|= (const CLINT& cliRight)
  202. {
  203. QuadPart |= cliRight.QuadPart;
  204. return *this;
  205. }
  206. inline CLINT& CLINT::operator<<=(UINT cbits)
  207. {
  208. QuadPart <<= cbits;
  209. return *this;
  210. }
  211. inline CLINT& CLINT::operator>>=(UINT cbits)
  212. {
  213. QuadPart >>= cbits;
  214. return *this;
  215. }
  216. inline LARGE_INTEGER CLINT::Li()
  217. {
  218. LARGE_INTEGER li;
  219. li.QuadPart = QuadPart;
  220. return li;
  221. }
  222. inline LONGLONG CLINT::Ll()
  223. {
  224. return QuadPart;
  225. }
  226. inline CULINT::CULINT()
  227. {
  228. }
  229. inline CULINT::CULINT(CULINT& culi)
  230. {
  231. QuadPart = culi.QuadPart;
  232. }
  233. inline CULINT::CULINT(LARGE_INTEGER li)
  234. {
  235. QuadPart = (DWORDLONG) li.QuadPart;
  236. }
  237. inline CULINT::CULINT(ULARGE_INTEGER uli)
  238. {
  239. QuadPart = uli.QuadPart;
  240. }
  241. inline CULINT::CULINT(DWORDLONG dwl)
  242. {
  243. QuadPart = dwl;
  244. }
  245. inline CULINT::CULINT(CLINT cli)
  246. {
  247. QuadPart = (DWORDLONG) cli.Li().QuadPart;
  248. }
  249. inline BOOL CULINT::NonZero()
  250. {
  251. return QuadPart != 0;
  252. }
  253. inline CULINT operator- (const CULINT& culiRight)
  254. {
  255. #pragma warning( disable : 4146 )
  256. CULINT ulint(-culiRight.QuadPart);
  257. return ulint;
  258. }
  259. inline CULINT operator+ (const CULINT& culiLeft, const CULINT& culiRight)
  260. {
  261. CULINT ulint(culiLeft.QuadPart + culiRight.QuadPart);
  262. return ulint;
  263. }
  264. inline CULINT operator- (const CULINT& culiLeft, const CULINT& culiRight)
  265. {
  266. CULINT ulint(culiLeft.QuadPart - culiRight.QuadPart);
  267. return ulint;
  268. }
  269. inline CULINT operator* (const CULINT& culiLeft, const CULINT& culiRight)
  270. {
  271. CULINT ulint(culiLeft.QuadPart * culiRight.QuadPart);
  272. return ulint;
  273. }
  274. inline CULINT operator/ (const CULINT& culiLeft, const CULINT& culiRight)
  275. {
  276. CULINT ulint(culiLeft.QuadPart / culiRight.QuadPart);
  277. return ulint;
  278. }
  279. inline CULINT operator| (const CULINT& culiLeft, const CULINT& culiRight)
  280. {
  281. CULINT ulint(culiLeft.QuadPart | culiRight.QuadPart);
  282. return ulint;
  283. }
  284. inline CULINT operator<< (const CULINT& culiLeft, UINT cbits)
  285. {
  286. CULINT ulint(culiLeft.QuadPart << cbits);
  287. return ulint;
  288. }
  289. inline CULINT operator>> (const CULINT& culiLeft, UINT cbits)
  290. {
  291. CULINT ulint(culiLeft.QuadPart >> cbits);
  292. return ulint;
  293. }
  294. inline CULINT& CULINT::operator= (const CULINT& culiRight)
  295. {
  296. QuadPart = culiRight.QuadPart;
  297. return *this;
  298. }
  299. inline CULINT& CULINT::operator+= (const CULINT& culiRight)
  300. {
  301. QuadPart += culiRight.QuadPart;
  302. return *this;
  303. }
  304. inline CULINT& CULINT::operator-= (const CULINT& culiRight)
  305. {
  306. QuadPart -= culiRight.QuadPart;
  307. return *this;
  308. }
  309. inline CULINT& CULINT::operator*= (const CULINT& culiRight)
  310. {
  311. QuadPart *= culiRight.QuadPart;
  312. return *this;
  313. }
  314. inline CULINT& CULINT::operator/= (const CULINT& culiRight)
  315. {
  316. QuadPart /= culiRight.QuadPart;
  317. return *this;
  318. }
  319. inline CULINT& CULINT::operator|= (const CULINT& culiRight)
  320. {
  321. QuadPart |= culiRight.QuadPart;
  322. return *this;
  323. }
  324. inline CULINT& CULINT::operator<<=(UINT cbits)
  325. {
  326. QuadPart <<= cbits;
  327. return *this;
  328. }
  329. inline CULINT& CULINT::operator>>=(UINT cbits)
  330. {
  331. QuadPart >>= cbits;
  332. return *this;
  333. }
  334. inline BOOL operator< (const CULINT& culiLeft, const CULINT& culiRight)
  335. {
  336. return culiLeft.QuadPart < culiRight.QuadPart;
  337. }
  338. inline BOOL operator<= (const CULINT& culiLeft, const CULINT& culiRight)
  339. {
  340. return culiLeft.QuadPart <= culiRight.QuadPart;
  341. }
  342. inline BOOL operator== (const CULINT& culiLeft, const CULINT& culiRight)
  343. {
  344. return culiLeft.QuadPart == culiRight.QuadPart;
  345. }
  346. inline BOOL operator>= (const CULINT& culiLeft, const CULINT& culiRight)
  347. {
  348. return culiLeft.QuadPart >= culiRight.QuadPart;
  349. }
  350. inline BOOL operator> (const CULINT& culiLeft, const CULINT& culiRight)
  351. {
  352. return culiLeft.QuadPart > culiRight.QuadPart;
  353. }
  354. inline BOOL operator!= (const CULINT& culiLeft, const CULINT& culiRight)
  355. {
  356. return culiLeft.QuadPart != culiRight.QuadPart;
  357. }
  358. inline ULARGE_INTEGER CULINT::Uli()
  359. {
  360. ULARGE_INTEGER uli;
  361. uli.QuadPart = QuadPart;
  362. return uli;
  363. }
  364. inline DWORDLONG CULINT::Ull()
  365. {
  366. return QuadPart;
  367. }