Panda3D

reversedNumericData.h

00001 // Filename: reversedNumericData.h
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 #ifndef REVERSEDNUMERICDATA_H
00016 #define REVERSEDNUMERICDATA_H
00017 
00018 #include "dtoolbase.h"
00019 
00020 #include <string.h>  // for memcpy()
00021 
00022 // The maximum size of any numeric data type.  At present, this is
00023 // int64 and float64.
00024 static const int max_numeric_size = 8;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : ReversedNumericData
00028 // Description : NativeNumericData and ReversedNumericData work
00029 //               together to provide a sneaky interface for
00030 //               automatically byte-swapping numbers, when necessary,
00031 //               to transparency support big-endian and little-endian
00032 //               architectures.
00033 //
00034 //               Both of these classes provide interfaces that accept
00035 //               a pointer to a numeric variable and the size of the
00036 //               number, and they can append that data to the end of a
00037 //               string, or memcpy it into another location.
00038 //
00039 //               The difference is that NativeNumericData simply
00040 //               passes everything through unchanged, while
00041 //               ReversedNumericData always byte-swaps everything.
00042 //               Otherwise, they have the same interface.
00043 //
00044 //               The transparent part comes from LittleEndian and
00045 //               BigEndian, which are typedeffed to be one of these or
00046 //               the other, according to the machine's architecture.
00047 ////////////////////////////////////////////////////////////////////
00048 class EXPCL_DTOOLCONFIG ReversedNumericData {
00049 public:
00050   INLINE ReversedNumericData(const void *data, size_t length);
00051   INLINE ReversedNumericData(const void *data, size_t start, size_t length);
00052 
00053   INLINE void store_value(void *dest, size_t length) const;
00054   INLINE const void *get_data() const;
00055 
00056 private:
00057   void reverse_assign(const char *source, size_t length);
00058   char _data[max_numeric_size];
00059 };
00060 
00061 #include "reversedNumericData.I"
00062 
00063 #endif
 All Classes Functions Variables Enumerations