Panda3D
 All Classes Functions Variables Enumerations
nativeNumericData.I
1 // Filename: nativeNumericData.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: NativeNumericData::Constructor
18 // Access: Public
19 // Description: This constructor accepts the address of a numeric
20 // variable, and its sizeof.
21 ////////////////////////////////////////////////////////////////////
23 NativeNumericData(const void *data, size_t) :
24  _source(data)
25 {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: NativeNumericData::Constructor
30 // Access: Public
31 // Description: This constructor accepts a pointer to a data array
32 // containing a packed numeric value, the offset within
33 // the array at which the numeric value starts, and the
34 // size of the numeric value.
35 //
36 // It is essential that the array not be destructed or
37 // modified as long as the NumericData object remains;
38 // it may just store a pointer into that string's
39 // internal buffer.
40 ////////////////////////////////////////////////////////////////////
42 NativeNumericData(const void *data, size_t start, size_t) {
43  _source = (void *)((const char *)data + start);
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: NativeNumericData::store_value
48 // Access: Public
49 // Description: Copies the data, with byte reversal if appropriate,
50 // into the indicated numeric variable, whose address
51 // and sizeof are given.
52 ////////////////////////////////////////////////////////////////////
53 INLINE void NativeNumericData::
54 store_value(void *dest, size_t length) const {
55  memcpy(dest, _source, length);
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: NativeNumericData::get_data
60 // Access: Public
61 // Description: Returns the pointer to the first byte of the data,
62 // either reversed or nonreversed, as appropriate.
63 ////////////////////////////////////////////////////////////////////
64 INLINE const void *NativeNumericData::
65 get_data() const {
66  return _source;
67 }
68 
69 /////////////////////
70 // this is for a intel compile .. it is native format and it is
71 // readable off word boundries
72 /////////////////////////
73 inline void TS_SetVal1(const PN_int8 * src, PN_int8 *dst)
74 {
75  *dst = *src;
76 }
77 inline void TS_SetVal2(const char * src, char *dst)
78 {
79  *(reinterpret_cast<PN_int16 *>(dst)) = *(reinterpret_cast <const PN_int16 *>(src));
80 }
81 
82 inline void TS_SetVal4(const char * src, char *dst)
83 {
84  *(reinterpret_cast <PN_int32 *>(dst)) = *(reinterpret_cast <const PN_int32 *>(src));
85 }
86 
87 
88 inline void TS_SetVal8(const char * src, char *dst)
89 {
90  *(reinterpret_cast<PN_int64 *>(dst)) = *(reinterpret_cast<const PN_int64 *>(src));
91 }
92 
93 template<class type> inline type TS_GetInteger(type &val,const char * _src)
94 {
95  val = *(reinterpret_cast <const type *>(_src));
96  return val;
97 }
98 
99 template<class type> inline type TS_GetIntegerIncPtr(type &val,char *& _src)
100 {
101  val = *(reinterpret_cast <const type *>(_src));
102  _src+= sizeof(type);
103  return val;
104 }
105 
106 template<class type> inline void TS_AddIntegerIncPtr(type val, char *& _dst)
107 {
108  *(reinterpret_cast <type *>(_dst)) = val;
109  _dst+= sizeof(type);
110 }
111 
112 template<class type> inline void TS_AddInteger(type val, char * _dst)
113 {
114  *(reinterpret_cast <type *>(_dst)) = val;
115 }
116 
117 #define TS_GetDirect(TT,SS) *((TT *)(SS))
118 #define TS_GetDirectIncPtr(TT,SS) { _ptr += sizeof(TT); return *((TT *)(SS -sizeof(TT))); }
119 
void store_value(void *dest, size_t length) const
Copies the data, with byte reversal if appropriate, into the indicated numeric variable, whose address and sizeof are given.
const void * get_data() const
Returns the pointer to the first byte of the data, either reversed or nonreversed, as appropriate.
NativeNumericData(const void *data, size_t length)
This constructor accepts the address of a numeric variable, and its sizeof.