Panda3D
reversedNumericData.h
1 // Filename: reversedNumericData.h
2 // Created by: drose (09May01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef REVERSEDNUMERICDATA_H
16 #define REVERSEDNUMERICDATA_H
17 
18 #include "dtoolbase.h"
19 
20 #include <string.h> // for memcpy()
21 
22 // The maximum size of any numeric data type. At present, this is
23 // int64 and float64.
24 static const int max_numeric_size = 8;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : ReversedNumericData
28 // Description : NativeNumericData and ReversedNumericData work
29 // together to provide a sneaky interface for
30 // automatically byte-swapping numbers, when necessary,
31 // to transparency support big-endian and little-endian
32 // architectures.
33 //
34 // Both of these classes provide interfaces that accept
35 // a pointer to a numeric variable and the size of the
36 // number, and they can append that data to the end of a
37 // string, or memcpy it into another location.
38 //
39 // The difference is that NativeNumericData simply
40 // passes everything through unchanged, while
41 // ReversedNumericData always byte-swaps everything.
42 // Otherwise, they have the same interface.
43 //
44 // The transparent part comes from LittleEndian and
45 // BigEndian, which are typedeffed to be one of these or
46 // the other, according to the machine's architecture.
47 ////////////////////////////////////////////////////////////////////
48 class EXPCL_DTOOLCONFIG ReversedNumericData {
49 public:
50  INLINE ReversedNumericData(const void *data, size_t length);
51  INLINE ReversedNumericData(const void *data, size_t start, size_t length);
52 
53  INLINE void store_value(void *dest, size_t length) const;
54  INLINE const void *get_data() const;
55 
56 private:
57  void reverse_assign(const char *source, size_t length);
58  char _data[max_numeric_size];
59 };
60 
61 #include "reversedNumericData.I"
62 
63 #endif
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...