Panda3D
|
00001 // Filename: nativeNumericData.I 00002 // Created by: drose (09May01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: NativeNumericData::Constructor 00018 // Access: Public 00019 // Description: This constructor accepts the address of a numeric 00020 // variable, and its sizeof. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE NativeNumericData:: 00023 NativeNumericData(const void *data, size_t) : 00024 _source(data) 00025 { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: NativeNumericData::Constructor 00030 // Access: Public 00031 // Description: This constructor accepts a pointer to a data array 00032 // containing a packed numeric value, the offset within 00033 // the array at which the numeric value starts, and the 00034 // size of the numeric value. 00035 // 00036 // It is essential that the array not be destructed or 00037 // modified as long as the NumericData object remains; 00038 // it may just store a pointer into that string's 00039 // internal buffer. 00040 //////////////////////////////////////////////////////////////////// 00041 INLINE NativeNumericData:: 00042 NativeNumericData(const void *data, size_t start, size_t) { 00043 _source = (void *)((const char *)data + start); 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: NativeNumericData::store_value 00048 // Access: Public 00049 // Description: Copies the data, with byte reversal if appropriate, 00050 // into the indicated numeric variable, whose address 00051 // and sizeof are given. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE void NativeNumericData:: 00054 store_value(void *dest, size_t length) const { 00055 memcpy(dest, _source, length); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: NativeNumericData::get_data 00060 // Access: Public 00061 // Description: Returns the pointer to the first byte of the data, 00062 // either reversed or nonreversed, as appropriate. 00063 //////////////////////////////////////////////////////////////////// 00064 INLINE const void *NativeNumericData:: 00065 get_data() const { 00066 return _source; 00067 } 00068 00069 ///////////////////// 00070 // this is for a intel compile .. it is native format and it is 00071 // readable off word boundries 00072 ///////////////////////// 00073 inline void TS_SetVal1(const PN_int8 * src, PN_int8 *dst) 00074 { 00075 *dst = *src; 00076 } 00077 inline void TS_SetVal2(const char * src, char *dst) 00078 { 00079 *(reinterpret_cast<PN_int16 *>(dst)) = *(reinterpret_cast <const PN_int16 *>(src)); 00080 } 00081 00082 inline void TS_SetVal4(const char * src, char *dst) 00083 { 00084 *(reinterpret_cast <PN_int32 *>(dst)) = *(reinterpret_cast <const PN_int32 *>(src)); 00085 } 00086 00087 00088 inline void TS_SetVal8(const char * src, char *dst) 00089 { 00090 *(reinterpret_cast<PN_int64 *>(dst)) = *(reinterpret_cast<const PN_int64 *>(src)); 00091 } 00092 00093 template<class type> inline type TS_GetInteger(type &val,const char * _src) 00094 { 00095 val = *(reinterpret_cast <const type *>(_src)); 00096 return val; 00097 } 00098 00099 template<class type> inline type TS_GetIntegerIncPtr(type &val,char *& _src) 00100 { 00101 val = *(reinterpret_cast <const type *>(_src)); 00102 _src+= sizeof(type); 00103 return val; 00104 } 00105 00106 template<class type> inline void TS_AddIntegerIncPtr(type val, char *& _dst) 00107 { 00108 *(reinterpret_cast <type *>(_dst)) = val; 00109 _dst+= sizeof(type); 00110 } 00111 00112 template<class type> inline void TS_AddInteger(type val, char * _dst) 00113 { 00114 *(reinterpret_cast <type *>(_dst)) = val; 00115 } 00116 00117 #define TS_GetDirect(TT,SS) *((TT *)(SS)) 00118 #define TS_GetDirectIncPtr(TT,SS) { _ptr += sizeof(TT); return *((TT *)(SS -sizeof(TT))); } 00119