Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/reversedNumericData.h

Go to the documentation of this file.
00001 // Filename: reversedNumericData.h
00002 // Created by:  drose (09May01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef REVERSEDNUMERICDATA_H
00020 #define REVERSEDNUMERICDATA_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include <string.h>  // for memcpy()
00025 
00026 // The maximum size of any numeric data type.  At present, this is
00027 // int64 and float64.
00028 static const int max_numeric_size = 8;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : ReversedNumericData
00032 // Description : NativeNumericData and ReversedNumericData work
00033 //               together to provide a sneaky interface for
00034 //               automatically byte-swapping numbers, when necessary,
00035 //               to transparency support big-endian and little-endian
00036 //               architectures.
00037 //
00038 //               Both of these classes provide interfaces that accept
00039 //               a pointer to a numeric variable and the size of the
00040 //               number, and they can append that data to the end of a
00041 //               string, or memcpy it into another location.
00042 //
00043 //               The difference is that NativeNumericData simply
00044 //               passes everything through unchanged, while
00045 //               ReversedNumericData always byte-swaps everything.
00046 //               Otherwise, they have the same interface.
00047 //
00048 //               The transparent part comes from LittleEndian and
00049 //               BigEndian, which are typedeffed to be one of these or
00050 //               the other, according to the machine's architecture.
00051 ////////////////////////////////////////////////////////////////////
00052 class EXPCL_PANDAEXPRESS ReversedNumericData {
00053 public:
00054   INLINE ReversedNumericData(const void *data, size_t length);
00055   INLINE ReversedNumericData(const void *data, size_t start, size_t length);
00056 
00057   INLINE void store_value(void *dest, size_t length) const;
00058   INLINE const void *get_data() const;
00059 
00060 private:
00061   void reverse_assign(const char *source, size_t length);
00062   char _data[max_numeric_size];
00063 };
00064 
00065 #include "reversedNumericData.I"
00066 
00067 #endif

Generated on Fri May 2 00:38:34 2003 for Panda by doxygen1.3