Panda3D

checksumHashGenerator.I
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file checksumHashGenerator.I
10 * @author drose
11 * @date 2001-05-14
12 */
13
14 #ifdef _WIN32
15 // Needed for PtrToLong, below
16 #ifndef WIN32_LEAN_AND_MEAN
17 #define WIN32_LEAN_AND_MEAN 1
18 #endif
19 #include <windows.h>
20 #endif
21
22 /**
23 * Adds another integer to the hash so far. This function should be
24 * overridden in base classes; this is the principle implementation of the
25 * HashGenerator.
26 */
27 INLINE void ChecksumHashGenerator::
28 add_int(long sum) {
29 _hash += (size_t)sum;
30 }
31
32 /**
33 * Adds a boolean flag.
34 */
35 INLINE void ChecksumHashGenerator::
36 add_bool(bool flag) {
37 add_int(flag);
38 }
39
40 /**
41 * Adds a floating-point number, first converting it to fixed point by
42 * dividing it by the indicated threshold.
43 */
44 INLINE void ChecksumHashGenerator::
45 add_fp(float number, float threshold) {
46 add_int((long)(number / threshold));
47 }
48
49 /**
50 * Adds a floating-point number, first converting it to fixed point by
51 * dividing it by the indicated threshold.
52 */
53 INLINE void ChecksumHashGenerator::
54 add_fp(double number, double threshold) {
55 add_int((long)(number / threshold));
56 }
57
58 /**
59 * Adds a pointer, derived simply by casting the pointer to an integer. This
60 * should be good enough even on architectures for which this cast is lossy.
61 */
62 INLINE void ChecksumHashGenerator::
63 add_pointer(void *ptr) {
64 #ifdef _WIN32
65 add_int(PtrToLong(ptr));
66 #else
67 add_int((long)ptr);
68 #endif
69 }
ChecksumHashGenerator::add_int
void add_int(long num)
Adds another integer to the hash so far.
Definition: checksumHashGenerator.I:28
ChecksumHashGenerator::add_pointer
void add_pointer(void *ptr)
Adds a pointer, derived simply by casting the pointer to an integer.
Definition: checksumHashGenerator.I:63
ChecksumHashGenerator::add_fp
void add_fp(float num, float threshold)
Adds a floating-point number, first converting it to fixed point by dividing it by the indicated thre...
Definition: checksumHashGenerator.I:45
ChecksumHashGenerator::add_bool
void add_bool(bool flag)
Adds a boolean flag.
Definition: checksumHashGenerator.I:36