Panda3D

Loading...
Searching...
No Matches
nativeNumericData.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 nativeNumericData.I
10 * @author drose
11 * @date 2001-05-09
12 */
13
14/**
15 * This constructor accepts the address of a numeric variable, and its sizeof.
16 */
17INLINE NativeNumericData::
18 NativeNumericData(const void *data, size_t) :
19 _source(data)
20{
21}
22
23/**
24 * This constructor accepts a pointer to a data array containing a packed
25 * numeric value, the offset within the array at which the numeric value
26 * starts, and the size of the numeric value.
27 *
28 * It is essential that the array not be destructed or modified as long as the
29 * NumericData object remains; it may just store a pointer into that string's
30 * internal buffer.
31 */
32INLINE NativeNumericData::
33 NativeNumericData(const void *data, size_t start, size_t) {
34 _source = (void *)((const char *)data + start);
35}
36
37/**
38 * Copies the data, with byte reversal if appropriate, into the indicated
39 * numeric variable, whose address and sizeof are given.
40 */
41INLINE void NativeNumericData::
42 store_value(void *dest, size_t length) const {
43 memcpy(dest, _source, length);
44}
45
46/**
47 * Returns the pointer to the first byte of the data, either reversed or
48 * nonreversed, as appropriate.
49 */
50INLINE const void *NativeNumericData::
51 get_data() const {
52 return _source;
53}
54
55// this is for a intel compile .. it is native format and it is readable off
56// word boundries
57 inline void TS_SetVal1(const int8_t * src, int8_t *dst)
58{
59 *dst = *src;
60}
61 inline void TS_SetVal2(const char * src, char *dst)
62{
63 *(reinterpret_cast<int16_t *>(dst)) = *(reinterpret_cast <const int16_t *>(src));
64}
65
66 inline void TS_SetVal4(const char * src, char *dst)
67{
68 *(reinterpret_cast <int32_t *>(dst)) = *(reinterpret_cast <const int32_t *>(src));
69}
70
71
72 inline void TS_SetVal8(const char * src, char *dst)
73{
74 *(reinterpret_cast<int64_t *>(dst)) = *(reinterpret_cast<const int64_t *>(src));
75}
76
77 template<class type> inline type TS_GetInteger(type &val,const char * _src)
78{
79 val = *(reinterpret_cast <const type *>(_src));
80 return val;
81}
82
83 template<class type> inline type TS_GetIntegerIncPtr(type &val,char *& _src)
84{
85 val = *(reinterpret_cast <const type *>(_src));
86 _src+= sizeof(type);
87 return val;
88}
89
90 template<class type> inline void TS_AddIntegerIncPtr(type val, char *& _dst)
91{
92 *(reinterpret_cast <type *>(_dst)) = val;
93 _dst+= sizeof(type);
94}
95
96 template<class type> inline void TS_AddInteger(type val, char * _dst)
97{
98 *(reinterpret_cast <type *>(_dst)) = val;
99}
100
101#define TS_GetDirect(TT,SS) *((TT *)(SS))
102#define TS_GetDirectIncPtr(TT,SS) { _ptr += sizeof(TT); return *((TT *)(SS -sizeof(TT))); }
NativeNumericData::get_data
const void * get_data() const
Returns the pointer to the first byte of the data, either reversed or nonreversed,...
Definition nativeNumericData.I:51
NativeNumericData::NativeNumericData
NativeNumericData(const void *data, size_t length)
This constructor accepts the address of a numeric variable, and its sizeof.
Definition nativeNumericData.I:18
NativeNumericData::store_value
void store_value(void *dest, size_t length) const
Copies the data, with byte reversal if appropriate, into the indicated numeric variable,...
Definition nativeNumericData.I:42