Panda3D
reversedNumericData.h
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 reversedNumericData.h
10  * @author drose
11  * @date 2001-05-09
12  */
13 
14 #ifndef REVERSEDNUMERICDATA_H
15 #define REVERSEDNUMERICDATA_H
16 
17 #include "dtoolbase.h"
18 
19 #include <string.h> // for memcpy()
20 
21 // The maximum size of any numeric data type. At present, this is int64 and
22 // float64.
23 static const int max_numeric_size = 8;
24 
25 /**
26  * NativeNumericData and ReversedNumericData work together to provide a sneaky
27  * interface for automatically byte-swapping numbers, when necessary, to
28  * transparency support big-endian and little-endian architectures.
29  *
30  * Both of these classes provide interfaces that accept a pointer to a numeric
31  * variable and the size of the number, and they can append that data to the
32  * end of a string, or memcpy it into another location.
33  *
34  * The difference is that NativeNumericData simply passes everything through
35  * unchanged, while ReversedNumericData always byte-swaps everything.
36  * Otherwise, they have the same interface.
37  *
38  * The transparent part comes from LittleEndian and BigEndian, which are
39  * typedeffed to be one of these or the other, according to the machine's
40  * architecture.
41  */
42 class EXPCL_DTOOL_PRC ReversedNumericData {
43 public:
44  INLINE ReversedNumericData(const void *data, size_t length);
45  INLINE ReversedNumericData(const void *data, size_t start, size_t length);
46 
47  INLINE void store_value(void *dest, size_t length) const;
48  INLINE const void *get_data() const;
49 
50 private:
51  void reverse_assign(const char *source, size_t length);
52  char _data[max_numeric_size];
53 };
54 
55 #include "reversedNumericData.I"
56 
57 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...