nativeNumericData.I 4.0 KB

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