*** empty log message ***

This commit is contained in:
David Rose 2001-05-09 20:52:16 +00:00
parent 1892ffa1d0
commit b2bc682693
17 changed files with 769 additions and 867 deletions

View File

@ -9,7 +9,7 @@
#define USE_NET yes
#define SOURCES \
bigEndian.I bigEndian.cxx bigEndian.h buffer.I buffer.cxx buffer.h \
bigEndian.h buffer.I buffer.cxx buffer.h \
circBuffer.I circBuffer.h clockObject.I clockObject.cxx \
clockObject.h config_express.cxx config_express.h datagram.I \
datagram.cxx datagram.h datagramGenerator.I datagramGenerator.cxx \
@ -20,13 +20,17 @@
datagramSink.I datagramSink.cxx datagramSink.h \
get_config_path.cxx get_config_path.h \
hashVal.I hashVal.cxx hashVal.h \
indent.I indent.cxx indent.h littleEndian.I \
littleEndian.cxx littleEndian.h memoryUsage.I memoryUsage.cxx \
indent.I indent.cxx indent.h \
littleEndian.h memoryUsage.I memoryUsage.cxx \
memoryUsage.h memoryUsagePointers.I memoryUsagePointers.cxx \
memoryUsagePointers.h multifile.I multifile.cxx multifile.h \
namable.I namable.cxx namable.h numeric_types.h \
namable.I namable.cxx namable.h \
nativeNumericData.I nativeNumericData.cxx nativeNumericData.h \
numeric_types.h \
pointerTo.I pointerTo.h referenceCount.I \
referenceCount.cxx referenceCount.h tokenBoard.I tokenBoard.h \
referenceCount.cxx referenceCount.h \
reversedNumericData.I reversedNumericData.cxx reversedNumericData.h \
tokenBoard.I tokenBoard.h \
trueClock.I trueClock.cxx trueClock.h typeHandle.I typeHandle.cxx \
typeHandle.h typedReferenceCount.I typedReferenceCount.cxx \
typedReferenceCount.h typedef.h error_utils.cxx error_utils.h
@ -36,7 +40,7 @@
patchfile.I patchfile.cxx patchfile.h
#define INSTALL_HEADERS \
bigEndian.I bigEndian.h buffer.I buffer.h circBuffer.I \
bigEndian.h buffer.I buffer.h circBuffer.I \
circBuffer.h clockObject.I clockObject.h config_express.h \
datagram.I datagram.h datagramInputFile.I datagramInputFile.h \
datagramIterator.I datagramIterator.h \
@ -44,11 +48,13 @@
datagramSink.I datagramSink.h datagramGenerator.I \
datagramGenerator.h get_config_path.h \
hashVal.I hashVal.h \
indent.I indent.h littleEndian.I littleEndian.h \
indent.I indent.h littleEndian.h \
memoryUsage.I memoryUsage.h memoryUsagePointers.I \
memoryUsagePointers.h multifile.I multifile.h \
nativeNumericData.I nativeNumericData.h \
numeric_types.h \
pointerTo.I pointerTo.h referenceCount.I referenceCount.h \
reversedNumericData.I reversedNumericData.h \
tokenBoard.h trueClock.I trueClock.h typeHandle.I typeHandle.h \
typedReferenceCount.I typedReferenceCount.h typedef.h \
namable.I namable.h tokenBoard.I patchfile.h patchfile.I \

View File

@ -1,91 +0,0 @@
// Filename: bigEndian.I
// Created by: drose (23Aug00)
//
////////////////////////////////////////////////////////////////////
#ifdef IS_LITTLE_ENDIAN
////////////////////////////////////////////////////////////////////
// Function: BigEndian::Constructor
// Access: Public
// Description: Reverses the bytes in the indicated string.
////////////////////////////////////////////////////////////////////
INLINE BigEndian::
BigEndian(const string &string) {
reverse_assign(string.data(), string.length());
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::Constructor
// Access: Public
// Description: Reverses the bytes in the indicated string.
////////////////////////////////////////////////////////////////////
INLINE BigEndian::
BigEndian(const char *data, size_t length) {
reverse_assign(data, length);
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::Copy Constructor
// Access: Public
// Description: Since this is assigned from another BigEndian,
// presumably already reversed, this does *not* reverse
// the byte order.
////////////////////////////////////////////////////////////////////
INLINE BigEndian::
BigEndian(const BigEndian &other) : _str(other._str) {
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::String Assignment Operator
// Access: Public
// Description: Reverses the bytes in the indicated string.
////////////////////////////////////////////////////////////////////
INLINE void BigEndian::
operator =(const string &string) {
reverse_assign(string.data(), string.length());
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::Copy Assignment Operator
// Access: Public
// Description: Since this is assigned from another BigEndian,
// presumably already reversed, this does *not* reverse
// the byte order.
////////////////////////////////////////////////////////////////////
INLINE void BigEndian::
operator =(const BigEndian &other) {
_str = other._str;
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::string Typecast Operator
// Access: Public
// Description: Returns the data as a string.
////////////////////////////////////////////////////////////////////
INLINE BigEndian::
operator const string &() const {
return _str;
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::data
// Access: Public
// Description: Returns the data in the string.
////////////////////////////////////////////////////////////////////
INLINE const char *BigEndian::
data() const {
return _str.data();
}
////////////////////////////////////////////////////////////////////
// Function: BigEndian::length
// Access: Public
// Description: Returns the number of bytes in the string.
////////////////////////////////////////////////////////////////////
INLINE size_t BigEndian::
length() const {
return _str.length();
}
#endif // IS_LITTLE_ENDIAN

View File

@ -9,52 +9,21 @@
#include <pandabase.h>
#include "numeric_types.h"
#ifdef IS_LITTLE_ENDIAN
#include "nativeNumericData.h"
#include "reversedNumericData.h"
////////////////////////////////////////////////////////////////////
// Class : BigEndian
// Description : BigEndian is a special string-like class that
// automatically reverses the byte order when it is
// assigned from either a char buffer or a true
// string--but only when compiling for a littleendian
// architecture. On bigendian machines, BigEndian
// is defined to map directly to string.
//
// See also LittleEndian.
// Description : BigEndian is a special class that automatically
// reverses the byte-order of numeric values for
// little-endian machines, and passes them through
// unchanged for big-endian machines.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS BigEndian {
public:
INLINE BigEndian(const string &string);
INLINE BigEndian(const char *data, size_t length);
INLINE BigEndian(const BigEndian &other);
INLINE void operator =(const string &string);
INLINE void operator =(const BigEndian &other);
INLINE operator const string &() const;
INLINE const char *data() const;
INLINE size_t length() const;
private:
void reverse_assign(const char *data, size_t length);
string _str;
};
#else // !IS_LITTLE_ENDIAN
#define BigEndian string
#endif // IS_LITTLE_ENDIAN
#include "bigEndian.I"
#ifdef IS_LITTLE_ENDIAN
typedef ReversedNumericData BigEndian;
#else
typedef NativeNumericData BigEndian;
#endif
#endif

View File

@ -67,8 +67,8 @@ add_bool(bool b) {
// Description: Adds a signed 8-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_int8(PN_int8 int8) {
_message += LittleEndian((char *)&int8, sizeof(int8));
add_int8(PN_int8 value) {
_message += (char)value;
}
////////////////////////////////////////////////////////////////////
@ -77,8 +77,8 @@ add_int8(PN_int8 int8) {
// Description: Adds an unsigned 8-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_uint8(PN_uint8 uint8) {
_message += LittleEndian((char *)&uint8, sizeof(uint8));
add_uint8(PN_uint8 value) {
_message += (char)value;
}
////////////////////////////////////////////////////////////////////
@ -87,8 +87,9 @@ add_uint8(PN_uint8 uint8) {
// Description: Adds a signed 16-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_int16(PN_int16 int16) {
_message += LittleEndian((char *)&int16, sizeof(int16));
add_int16(PN_int16 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -97,8 +98,9 @@ add_int16(PN_int16 int16) {
// Description: Adds a signed 32-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_int32(PN_int32 int32) {
_message += LittleEndian((char *)&int32, sizeof(int32));
add_int32(PN_int32 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -107,8 +109,9 @@ add_int32(PN_int32 int32) {
// Description: Adds a signed 64-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_int64(PN_int64 int64) {
_message += LittleEndian((char *)&int64, sizeof(int64));
add_int64(PN_int64 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -117,8 +120,9 @@ add_int64(PN_int64 int64) {
// Description: Adds an unsigned 16-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_uint16(PN_uint16 uint16) {
_message += LittleEndian((char *)&uint16, sizeof(uint16));
add_uint16(PN_uint16 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -127,8 +131,9 @@ add_uint16(PN_uint16 uint16) {
// Description: Adds an unsigned 32-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_uint32(PN_uint32 uint32) {
_message += LittleEndian((char *)&uint32, sizeof(uint32));
add_uint32(PN_uint32 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -137,8 +142,9 @@ add_uint32(PN_uint32 uint32) {
// Description: Adds an unsigned 64-bit integer to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_uint64(PN_uint64 uint64) {
_message += LittleEndian((char *)&uint64, sizeof(uint64));
add_uint64(PN_uint64 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -150,12 +156,13 @@ add_uint64(PN_uint64 uint64) {
// special care is required.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_float32(float float32) {
add_float32(float value) {
// For now, we assume the float format is portable across all
// architectures we are concerned with. If we come across one that
// is different, we will have to convert.
nassertv(sizeof(float32) == 4);
_message += LittleEndian((char *)&float32, sizeof(float32));
nassertv(sizeof(value) == 4);
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -164,8 +171,9 @@ add_float32(float float32) {
// Description: Adds a 64-bit floating-point number to the datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_float64(PN_float64 float64) {
_message += LittleEndian((char *)&float64, sizeof(float64));
add_float64(PN_float64 value) {
LittleEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -175,8 +183,9 @@ add_float64(PN_float64 float64) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_int16(PN_int16 int16) {
_message += BigEndian((char *)&int16, sizeof(int16));
add_be_int16(PN_int16 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -186,8 +195,9 @@ add_be_int16(PN_int16 int16) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_int32(PN_int32 int32) {
_message += BigEndian((char *)&int32, sizeof(int32));
add_be_int32(PN_int32 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -197,8 +207,9 @@ add_be_int32(PN_int32 int32) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_int64(PN_int64 int64) {
_message += BigEndian((char *)&int64, sizeof(int64));
add_be_int64(PN_int64 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -208,8 +219,9 @@ add_be_int64(PN_int64 int64) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_uint16(PN_uint16 uint16) {
_message += BigEndian((char *)&uint16, sizeof(uint16));
add_be_uint16(PN_uint16 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -219,8 +231,9 @@ add_be_uint16(PN_uint16 uint16) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_uint32(PN_uint32 uint32) {
_message += BigEndian((char *)&uint32, sizeof(uint32));
add_be_uint32(PN_uint32 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -230,8 +243,9 @@ add_be_uint32(PN_uint32 uint32) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_uint64(PN_uint64 uint64) {
_message += BigEndian((char *)&uint64, sizeof(uint64));
add_be_uint64(PN_uint64 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -243,12 +257,13 @@ add_be_uint64(PN_uint64 uint64) {
// different architectures, special care is required.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_float32(float float32) {
add_be_float32(float value) {
// For now, we assume the float format is portable across all
// architectures we are concerned with. If we come across one that
// is different, we will have to convert.
nassertv(sizeof(float32) == 4);
_message += BigEndian((char *)&float32, sizeof(float32));
nassertv(sizeof(value) == 4);
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////
@ -258,8 +273,9 @@ add_be_float32(float float32) {
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void Datagram::
add_be_float64(PN_float64 float64) {
_message += BigEndian((char *)&float64, sizeof(float64));
add_be_float64(PN_float64 value) {
BigEndian s(&value, sizeof(value));
s.append_to(_message, sizeof(value));
}
////////////////////////////////////////////////////////////////////

View File

@ -45,29 +45,29 @@ PUBLISHED:
virtual void clear();
void dump_hex(ostream &out) const;
INLINE void add_bool(bool b);
INLINE void add_int8(PN_int8 int8);
INLINE void add_uint8(PN_uint8 uint8);
INLINE void add_bool(bool value);
INLINE void add_int8(PN_int8 value);
INLINE void add_uint8(PN_uint8 value);
// The default numeric packing is little-endian.
INLINE void add_int16(PN_int16 int16);
INLINE void add_int32(PN_int32 int32);
INLINE void add_int64(PN_int64 int64);
INLINE void add_uint16(PN_uint16 uint16);
INLINE void add_uint32(PN_uint32 uint32);
INLINE void add_uint64(PN_uint64 uint64);
INLINE void add_float32(float float32);
INLINE void add_float64(PN_float64 float64);
INLINE void add_int16(PN_int16 value);
INLINE void add_int32(PN_int32 value);
INLINE void add_int64(PN_int64 value);
INLINE void add_uint16(PN_uint16 value);
INLINE void add_uint32(PN_uint32 value);
INLINE void add_uint64(PN_uint64 value);
INLINE void add_float32(float value);
INLINE void add_float64(PN_float64 value);
// These functions pack numbers big-endian, in case that's desired.
INLINE void add_be_int16(PN_int16 int16);
INLINE void add_be_int32(PN_int32 int32);
INLINE void add_be_int64(PN_int64 int64);
INLINE void add_be_uint16(PN_uint16 uint16);
INLINE void add_be_uint32(PN_uint32 uint32);
INLINE void add_be_uint64(PN_uint64 uint64);
INLINE void add_be_float32(float float32);
INLINE void add_be_float64(PN_float64 float64);
INLINE void add_be_int16(PN_int16 value);
INLINE void add_be_int32(PN_int32 value);
INLINE void add_be_int64(PN_int64 value);
INLINE void add_be_uint16(PN_uint16 value);
INLINE void add_be_uint32(PN_uint32 value);
INLINE void add_be_uint64(PN_uint64 value);
INLINE void add_be_float32(float value);
INLINE void add_be_float64(PN_float64 value);
INLINE void add_string(const string &str);
INLINE void add_fixed_string(const string &str, size_t size);

View File

@ -60,3 +60,407 @@ operator = (const DatagramIterator &copy) {
INLINE DatagramIterator::
~DatagramIterator() {
}
// Various ways to get data and increment the iterator...
// Cut-and-paste-orama
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_bool
// Access: Public
// Description: Extracts a boolean value.
////////////////////////////////////////////////////////////////////
INLINE bool DatagramIterator::
get_bool() {
return (get_uint8() != 0);
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int8
// Access: Public
// Description: Extracts a signed 8-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int8 DatagramIterator::
get_int8() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int8 tempvar = (PN_int8)_datagram->get_message()[_current_index];
_current_index++;
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint8
// Access: Public
// Description: Extracts an unsigned 8-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint8 DatagramIterator::
get_uint8() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint8 tempvar = (PN_uint8)_datagram->get_message()[_current_index];
_current_index++;
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int16
// Access: Public
// Description: Extracts a signed 16-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int16 DatagramIterator::
get_int16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int16 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int32
// Access: Public
// Description: Extracts a signed 32-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int32 DatagramIterator::
get_int32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int32 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int64
// Access: Public
// Description: Extracts a signed 64-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int64 DatagramIterator::
get_int64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int64 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint16
// Access: Public
// Description: Extracts an unsigned 16-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint16 DatagramIterator::
get_uint16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint16 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint32
// Access: Public
// Description: Extracts an unsigned 32-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint32 DatagramIterator::
get_uint32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint32 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint64
// Access: Public
// Description: Extracts an unsigned 64-bit integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint64 DatagramIterator::
get_uint64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint64 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_float32
// Access: Public
// Description: Extracts a 32-bit single-precision floating-point
// number. Since this kind of float is not necessarily
// portable across different architectures, special care
// is required.
////////////////////////////////////////////////////////////////////
INLINE float DatagramIterator::
get_float32() {
// For now, we assume the float format is portable across all
// architectures we are concerned with. If we come across one that
// is different, we will have to convert.
nassertr(sizeof(float) == 4, 0.0);
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
float tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_float64
// Access: Public
// Description: Extracts a 64-bit floating-point number.
////////////////////////////////////////////////////////////////////
INLINE PN_float64 DatagramIterator::
get_float64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
PN_float64 tempvar;
LittleEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_int16
// Access: Public
// Description: Extracts a signed 16-bit big-endian integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int16 DatagramIterator::
get_be_int16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int16 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_int32
// Access: Public
// Description: Extracts a signed 32-bit big-endian integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int32 DatagramIterator::
get_be_int32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int32 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_int64
// Access: Public
// Description: Extracts a signed 64-bit big-endian integer.
////////////////////////////////////////////////////////////////////
INLINE PN_int64 DatagramIterator::
get_be_int64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int64 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_uint16
// Access: Public
// Description: Extracts an unsigned 16-bit big-endian integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint16 DatagramIterator::
get_be_uint16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint16 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_uint32
// Access: Public
// Description: Extracts an unsigned 32-bit big-endian integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint32 DatagramIterator::
get_be_uint32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint32 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_uint64
// Access: Public
// Description: Extracts an unsigned 64-bit big-endian integer.
////////////////////////////////////////////////////////////////////
INLINE PN_uint64 DatagramIterator::
get_be_uint64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint64 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_float32
// Access: Public
// Description: Extracts a 32-bit big-endian single-precision
// floating-point number. Since this kind of float is
// not necessarily portable across different
// architectures, special care is required.
////////////////////////////////////////////////////////////////////
INLINE float DatagramIterator::
get_be_float32() {
// For now, we assume the float format is portable across all
// architectures we are concerned with. If we come across one that
// is different, we will have to convert.
nassertr(sizeof(float) == 4, 0.0);
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
float tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_float64
// Access: Public
// Description: Extracts a 64-bit big-endian floating-point number.
////////////////////////////////////////////////////////////////////
INLINE PN_float64 DatagramIterator::
get_be_float64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
PN_float64 tempvar;
BigEndian s(_datagram->get_message(), _current_index, sizeof(tempvar));
s.store_value(&tempvar, sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::skip_bytes
// Access: Public
// Description: Skips over the indicated number of bytes in the
// datagram.
////////////////////////////////////////////////////////////////////
INLINE void DatagramIterator::
skip_bytes(size_t size) {
nassertv((int)size >= 0);
nassertv(_current_index + size <= _datagram->get_length());
_current_index += size;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_remaining_bytes
// Access: Public
// Description: Returns the remaining bytes in the datagram as a
// string, but does not extract them from the iterator.
////////////////////////////////////////////////////////////////////
INLINE string DatagramIterator::
get_remaining_bytes() const {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index <= _datagram->get_length(), "");
return _datagram->get_message().substr(_current_index);
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_remaining_size
// Access: Public
// Description: Return the bytes left in the datagram.
////////////////////////////////////////////////////////////////////
INLINE int DatagramIterator::
get_remaining_size() const {
return _datagram->get_length() - _current_index;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_datagram
// Access: Public
// Description: Return the datagram of this iterator.
////////////////////////////////////////////////////////////////////
const Datagram &DatagramIterator::
get_datagram() const {
return *_datagram;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_current_index
// Access: Public
// Description: Returns the current position within the datagram of the
// next piece of data to extract.
////////////////////////////////////////////////////////////////////
INLINE size_t DatagramIterator::
get_current_index() const {
return _current_index;
}

View File

@ -8,422 +8,6 @@
#include <notify.h>
// Various ways to get data and increment the iterator...
// Cut-and-paste-orama
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_bool
// Access: Public
// Description: Extracts a boolean value.
////////////////////////////////////////////////////////////////////
bool DatagramIterator::
get_bool() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint8 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return (tempvar != 0);
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int8
// Access: Public
// Description: Extracts a signed 8-bit integer.
////////////////////////////////////////////////////////////////////
PN_int8 DatagramIterator::
get_int8() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int8 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint8
// Access: Public
// Description: Extracts an unsigned 8-bit integer.
////////////////////////////////////////////////////////////////////
PN_uint8 DatagramIterator::
get_uint8() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint8 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int16
// Access: Public
// Description: Extracts a signed 16-bit integer.
////////////////////////////////////////////////////////////////////
PN_int16 DatagramIterator::
get_int16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int16 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int32
// Access: Public
// Description: Extracts a signed 32-bit integer.
////////////////////////////////////////////////////////////////////
PN_int32 DatagramIterator::
get_int32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int32 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_int64
// Access: Public
// Description: Extracts a signed 64-bit integer.
////////////////////////////////////////////////////////////////////
PN_int64 DatagramIterator::
get_int64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int64 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint16
// Access: Public
// Description: Extracts an unsigned 16-bit integer.
////////////////////////////////////////////////////////////////////
PN_uint16 DatagramIterator::
get_uint16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint16 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint32
// Access: Public
// Description: Extracts an unsigned 32-bit integer.
////////////////////////////////////////////////////////////////////
PN_uint32 DatagramIterator::
get_uint32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint32 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_uint64
// Access: Public
// Description: Extracts an unsigned 64-bit integer.
////////////////////////////////////////////////////////////////////
PN_uint64 DatagramIterator::
get_uint64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint64 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_float32
// Access: Public
// Description: Extracts a 32-bit single-precision floating-point
// number. Since this kind of float is not necessarily
// portable across different architectures, special care
// is required.
////////////////////////////////////////////////////////////////////
float DatagramIterator::
get_float32() {
// For now, we assume the float format is portable across all
// architectures we are concerned with. If we come across one that
// is different, we will have to convert.
nassertr(sizeof(float) == 4, 0.0);
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
float tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0.0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_float64
// Access: Public
// Description: Extracts a 64-bit floating-point number.
////////////////////////////////////////////////////////////////////
PN_float64 DatagramIterator::
get_float64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
PN_float64 tempvar;
LittleEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0.0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_int16
// Access: Public
// Description: Extracts a signed 16-bit big-endian integer.
////////////////////////////////////////////////////////////////////
PN_int16 DatagramIterator::
get_be_int16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int16 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_int32
// Access: Public
// Description: Extracts a signed 32-bit big-endian integer.
////////////////////////////////////////////////////////////////////
PN_int32 DatagramIterator::
get_be_int32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int32 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_int64
// Access: Public
// Description: Extracts a signed 64-bit big-endian integer.
////////////////////////////////////////////////////////////////////
PN_int64 DatagramIterator::
get_be_int64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_int64 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_uint16
// Access: Public
// Description: Extracts an unsigned 16-bit big-endian integer.
////////////////////////////////////////////////////////////////////
PN_uint16 DatagramIterator::
get_be_uint16() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint16 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_uint32
// Access: Public
// Description: Extracts an unsigned 32-bit big-endian integer.
////////////////////////////////////////////////////////////////////
PN_uint32 DatagramIterator::
get_be_uint32() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint32 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_uint64
// Access: Public
// Description: Extracts an unsigned 64-bit big-endian integer.
////////////////////////////////////////////////////////////////////
PN_uint64 DatagramIterator::
get_be_uint64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0);
PN_uint64 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_float32
// Access: Public
// Description: Extracts a 32-bit big-endian single-precision
// floating-point number. Since this kind of float is
// not necessarily portable across different
// architectures, special care is required.
////////////////////////////////////////////////////////////////////
float DatagramIterator::
get_be_float32() {
// For now, we assume the float format is portable across all
// architectures we are concerned with. If we come across one that
// is different, we will have to convert.
nassertr(sizeof(float) == 4, 0.0);
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
float tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0.0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_be_float64
// Access: Public
// Description: Extracts a 64-bit big-endian floating-point number.
////////////////////////////////////////////////////////////////////
PN_float64 DatagramIterator::
get_be_float64() {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index < _datagram->get_length(), 0.0);
PN_float64 tempvar;
BigEndian s =
_datagram->get_message().substr(_current_index, sizeof(tempvar));
nassertr(s.length() == sizeof(tempvar), 0.0);
memcpy((void *)&tempvar, (void *)s.data(), sizeof(tempvar));
_current_index += sizeof(tempvar);
return tempvar;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_string
// Access: Public
@ -466,19 +50,6 @@ get_fixed_string(size_t size) {
return s.substr(0, zero_byte);
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::skip_bytes
// Access: Public
// Description: Skips over the indicated number of bytes in the
// datagram.
////////////////////////////////////////////////////////////////////
void DatagramIterator::
skip_bytes(size_t size) {
nassertv((int)size >= 0);
nassertv(_current_index + size <= _datagram->get_length());
_current_index += size;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::extract_bytes
// Access: Public
@ -496,46 +67,3 @@ extract_bytes(size_t size) {
return _datagram->get_message().substr(start, size);
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_remaining_bytes
// Access: Public
// Description: Returns the remaining bytes in the datagram as a
// string, but does not extract them from the iterator.
////////////////////////////////////////////////////////////////////
string DatagramIterator::
get_remaining_bytes() const {
nassertr(_datagram != (const Datagram *)NULL &&
_current_index <= _datagram->get_length(), "");
return _datagram->get_message().substr(_current_index);
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_remaining_size
// Access: Public
// Description: Return the bytes left in the datagram.
////////////////////////////////////////////////////////////////////
int DatagramIterator::
get_remaining_size() const {
return _datagram->get_length() - _current_index;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_datagram
// Access: Public
// Description: Return the datagram of this iterator.
////////////////////////////////////////////////////////////////////
const Datagram &DatagramIterator::
get_datagram() const {
return *_datagram;
}
////////////////////////////////////////////////////////////////////
// Function: DatagramIterator::get_current_index
// Access: Public
// Description: Returns the current position within the datagram of the
// next piece of data to extract.
////////////////////////////////////////////////////////////////////
size_t DatagramIterator::
get_current_index() const {
return _current_index;
}

View File

@ -25,39 +25,39 @@ PUBLISHED:
INLINE void operator = (const DatagramIterator &copy);
INLINE ~DatagramIterator();
bool get_bool();
PN_int8 get_int8();
PN_uint8 get_uint8();
INLINE bool get_bool();
INLINE PN_int8 get_int8();
INLINE PN_uint8 get_uint8();
PN_int16 get_int16();
PN_int32 get_int32();
PN_int64 get_int64();
PN_uint16 get_uint16();
PN_uint32 get_uint32();
PN_uint64 get_uint64();
float get_float32();
PN_float64 get_float64();
INLINE PN_int16 get_int16();
INLINE PN_int32 get_int32();
INLINE PN_int64 get_int64();
INLINE PN_uint16 get_uint16();
INLINE PN_uint32 get_uint32();
INLINE PN_uint64 get_uint64();
INLINE float get_float32();
INLINE PN_float64 get_float64();
PN_int16 get_be_int16();
PN_int32 get_be_int32();
PN_int64 get_be_int64();
PN_uint16 get_be_uint16();
PN_uint32 get_be_uint32();
PN_uint64 get_be_uint64();
float get_be_float32();
PN_float64 get_be_float64();
INLINE PN_int16 get_be_int16();
INLINE PN_int32 get_be_int32();
INLINE PN_int64 get_be_int64();
INLINE PN_uint16 get_be_uint16();
INLINE PN_uint32 get_be_uint32();
INLINE PN_uint64 get_be_uint64();
INLINE float get_be_float32();
INLINE PN_float64 get_be_float64();
string get_string();
string get_fixed_string(size_t size);
void skip_bytes(size_t size);
INLINE void skip_bytes(size_t size);
string extract_bytes(size_t size);
string get_remaining_bytes() const;
int get_remaining_size() const;
INLINE string get_remaining_bytes() const;
INLINE int get_remaining_size() const;
const Datagram &get_datagram() const;
size_t get_current_index() const;
INLINE const Datagram &get_datagram() const;
INLINE size_t get_current_index() const;
private:
const Datagram *_datagram;

View File

@ -1,92 +0,0 @@
// Filename: littleEndian.I
// Created by: drose (09Feb00)
//
////////////////////////////////////////////////////////////////////
#ifdef IS_BIG_ENDIAN
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::Constructor
// Access: Public
// Description: Reverses the bytes in the indicated string.
////////////////////////////////////////////////////////////////////
INLINE LittleEndian::
LittleEndian(const string &string) {
reverse_assign(string.data(), string.length());
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::Constructor
// Access: Public
// Description: Reverses the bytes in the indicated string.
////////////////////////////////////////////////////////////////////
INLINE LittleEndian::
LittleEndian(const char *data, size_t length) {
reverse_assign(data, length);
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::Copy Constructor
// Access: Public
// Description: Since this is assigned from another LittleEndian,
// presumably already reversed, this does *not* reverse
// the byte order.
////////////////////////////////////////////////////////////////////
INLINE LittleEndian::
LittleEndian(const LittleEndian &other) : _str(other._str) {
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::String Assignment Operator
// Access: Public
// Description: Reverses the bytes in the indicated string.
////////////////////////////////////////////////////////////////////
INLINE void LittleEndian::
operator =(const string &string) {
reverse_assign(string.data(), string.length());
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::Copy Assignment Operator
// Access: Public
// Description: Since this is assigned from another LittleEndian,
// presumably already reversed, this does *not* reverse
// the byte order.
////////////////////////////////////////////////////////////////////
INLINE void LittleEndian::
operator =(const LittleEndian &other) {
_str = other._str;
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::string Typecast Operator
// Access: Public
// Description: Returns the data as a string.
////////////////////////////////////////////////////////////////////
INLINE LittleEndian::
operator const string &() const {
return _str;
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::data
// Access: Public
// Description: Returns the data in the string.
////////////////////////////////////////////////////////////////////
INLINE const char *LittleEndian::
data() const {
return _str.data();
}
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::length
// Access: Public
// Description: Returns the number of bytes in the string.
////////////////////////////////////////////////////////////////////
INLINE size_t LittleEndian::
length() const {
return _str.length();
}
#endif // IS_BIG_ENDIAN

View File

@ -1,25 +0,0 @@
// Filename: littleEndian.cxx
// Created by: drose (09Feb00)
//
////////////////////////////////////////////////////////////////////
#include "littleEndian.h"
#ifdef IS_BIG_ENDIAN
////////////////////////////////////////////////////////////////////
// Function: LittleEndian::reverse_assign
// Access: Private
// Description: Actually does the data reversal.
////////////////////////////////////////////////////////////////////
void LittleEndian::
reverse_assign(const char *data, size_t length) {
_str = "";
_str.reserve(length);
for (size_t i = 0; i < length; i++) {
_str += data[length - 1 - i];
}
}
#endif // IS_BIG_ENDIAN

View File

@ -9,54 +9,21 @@
#include <pandabase.h>
#include "numeric_types.h"
#ifdef IS_BIG_ENDIAN
#include "nativeNumericData.h"
#include "reversedNumericData.h"
////////////////////////////////////////////////////////////////////
// Class : LittleEndian
// Description : LittleEndian is a special string-like class that
// automatically reverses the byte order when it is
// assigned from either a char buffer or a true
// string--but only when compiling for a bigendian
// architecture. On littleendian machines, LittleEndian
// is defined to map directly to string.
//
// This is a sneaky interface to automatically handle
// numeric conversions so that network data is always
// sent littleendian.
// Description : LittleEndian is a special class that automatically
// reverses the byte-order of numeric values for
// big-endian machines, and passes them through
// unchanged for little-endian machines.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS LittleEndian {
public:
INLINE LittleEndian(const string &string);
INLINE LittleEndian(const char *data, size_t length);
INLINE LittleEndian(const LittleEndian &other);
INLINE void operator =(const string &string);
INLINE void operator =(const LittleEndian &other);
INLINE operator const string &() const;
INLINE const char *data() const;
INLINE size_t length() const;
private:
void reverse_assign(const char *data, size_t length);
string _str;
};
#else // !IS_BIG_ENDIAN
#define LittleEndian string
#endif // IS_BIG_ENDIAN
#include "littleEndian.I"
#ifdef IS_LITTLE_ENDIAN
typedef NativeNumericData LittleEndian;
#else
typedef ReversedNumericData LittleEndian;
#endif
#endif

View File

@ -0,0 +1,58 @@
// Filename: nativeNumericData.I
// Created by: drose (09May01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: NativeNumericData::Constructor
// Access: Public
// Description: This constructor accepts the address of a numeric
// variable, and its sizeof.
////////////////////////////////////////////////////////////////////
INLINE NativeNumericData::
NativeNumericData(const void *data, size_t) :
_source(data)
{
}
////////////////////////////////////////////////////////////////////
// Function: NativeNumericData::Constructor
// Access: Public
// Description: This constructor accepts a string containing a packed
// numeric value, the offset within the string at which
// the numeric value starts, and the size of the numeric
// value.
//
// It is essential that the string not be destructed or
// modified as long as the NumericData object remains;
// it may just store a pointer into that string's
// internal buffer.
////////////////////////////////////////////////////////////////////
INLINE NativeNumericData::
NativeNumericData(const string &data, size_t start, size_t) {
_source = (void *)(data.data() + start);
}
////////////////////////////////////////////////////////////////////
// Function: NativeNumericData::store_value
// Access: Public
// Description: Copies the data, with byte reversal if appropriate,
// into the indicated numeric variable, whose address
// and sizeof are given.
////////////////////////////////////////////////////////////////////
INLINE void NativeNumericData::
store_value(void *dest, size_t length) {
memcpy(dest, _source, length);
}
////////////////////////////////////////////////////////////////////
// Function: NativeNumericData::append_to
// Access: Public
// Description: Packs the numeric data, with byte reversal if
// appropriate, onto the end of the given string.
////////////////////////////////////////////////////////////////////
INLINE void NativeNumericData::
append_to(string &dest, size_t length) {
dest.append((const char *)_source, length);
}

View File

@ -0,0 +1,6 @@
// Filename: nativeNumericData.cxx
// Created by: drose (09May01)
//
////////////////////////////////////////////////////////////////////
#include "nativeNumericData.h"

View File

@ -0,0 +1,49 @@
// Filename: nativeNumericData.h
// Created by: drose (09May01)
//
////////////////////////////////////////////////////////////////////
#ifndef NATIVENUMERICDATA_H
#define NATIVENUMERICDATA_H
#include <pandabase.h>
#include <string.h> // for memcpy()
////////////////////////////////////////////////////////////////////
// Class : NativeNumericData
// Description : NativeNumericData and ReversedNumericData work
// together to provide a sneaky interface for
// automatically byte-swapping numbers, when necessary,
// to transparency support big-endian and little-endian
// architectures.
//
// Both of these classes provide interfaces that accept
// a pointer to a numeric variable and the size of the
// number, and they can append that data to the end of a
// string, or memcpy it into another location.
//
// The difference is that NativeNumericData simply
// passes everything through unchanged, while
// ReversedNumericData always byte-swaps everything.
// Otherwise, they have the same interface.
//
// The transparent part comes from LittleEndian and
// BigEndian, which are typedeffed to be one of these or
// the other, according to the machine's architecture.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS NativeNumericData {
public:
INLINE NativeNumericData(const void *data, size_t length);
INLINE NativeNumericData(const string &data, size_t start, size_t length);
INLINE void store_value(void *dest, size_t length);
INLINE void append_to(string &dest, size_t length);
private:
const void *_source;
};
#include "nativeNumericData.I"
#endif

View File

@ -0,0 +1,57 @@
// Filename: reversedNumericData.I
// Created by: drose (09May01)
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: ReversedNumericData::Constructor
// Access: Public
// Description: This constructor accepts the address of a numeric
// variable, and its sizeof.
////////////////////////////////////////////////////////////////////
INLINE ReversedNumericData::
ReversedNumericData(const void *data, size_t length) {
reverse_assign((const char *)data, length);
}
////////////////////////////////////////////////////////////////////
// Function: ReversedNumericData::Constructor
// Access: Public
// Description: This constructor accepts a string containing a packed
// numeric value, the offset within the string at which
// the numeric value starts, and the size of the numeric
// value.
//
// It is essential that the string not be destructed or
// modified as long as the NumericData object remains;
// it may just store a pointer into that string's
// internal buffer.
////////////////////////////////////////////////////////////////////
INLINE ReversedNumericData::
ReversedNumericData(const string &data, size_t start, size_t length) {
reverse_assign(data.data() + start, length);
}
////////////////////////////////////////////////////////////////////
// Function: ReversedNumericData::store_value
// Access: Public
// Description: Copies the data, with byte reversal if appropriate,
// into the indicated numeric variable, whose address
// and sizeof are given.
////////////////////////////////////////////////////////////////////
INLINE void ReversedNumericData::
store_value(void *dest, size_t length) {
memcpy(dest, _data, length);
}
////////////////////////////////////////////////////////////////////
// Function: ReversedNumericData::append_to
// Access: Public
// Description: Packs the numeric data, with byte reversal if
// appropriate, onto the end of the given string.
////////////////////////////////////////////////////////////////////
INLINE void ReversedNumericData::
append_to(string &dest, size_t length) {
dest.append((const char *)_data, length);
}

View File

@ -1,25 +1,21 @@
// Filename: bigEndian.cxx
// Created by: drose (23Aug00)
// Filename: reversedNumericData.cxx
// Created by: drose (09May01)
//
////////////////////////////////////////////////////////////////////
#include "bigEndian.h"
#include "reversedNumericData.h"
#ifdef IS_LITTLE_ENDIAN
#include <notify.h>
////////////////////////////////////////////////////////////////////
// Function: BigEndian::reverse_assign
// Function: ReversedNumericData::reverse_assign
// Access: Private
// Description: Actually does the data reversal.
////////////////////////////////////////////////////////////////////
void BigEndian::
reverse_assign(const char *data, size_t length) {
_str = "";
_str.reserve(length);
void ReversedNumericData::
reverse_assign(const char *source, size_t length) {
nassertv(length <= max_numeric_size);
for (size_t i = 0; i < length; i++) {
_str += data[length - 1 - i];
_data[i] = source[length - 1 - i];
}
}
#endif // IS_LITTLE_ENDIAN

View File

@ -0,0 +1,54 @@
// Filename: reversedNumericData.h
// Created by: drose (09May01)
//
////////////////////////////////////////////////////////////////////
#ifndef REVERSEDNUMERICDATA_H
#define REVERSEDNUMERICDATA_H
#include <pandabase.h>
#include <string.h> // for memcpy()
// The maximum size of any numeric data type. At present, this is
// int64 and float64.
static const int max_numeric_size = 8;
////////////////////////////////////////////////////////////////////
// Class : ReversedNumericData
// Description : NativeNumericData and ReversedNumericData work
// together to provide a sneaky interface for
// automatically byte-swapping numbers, when necessary,
// to transparency support big-endian and little-endian
// architectures.
//
// Both of these classes provide interfaces that accept
// a pointer to a numeric variable and the size of the
// number, and they can append that data to the end of a
// string, or memcpy it into another location.
//
// The difference is that NativeNumericData simply
// passes everything through unchanged, while
// ReversedNumericData always byte-swaps everything.
// Otherwise, they have the same interface.
//
// The transparent part comes from LittleEndian and
// BigEndian, which are typedeffed to be one of these or
// the other, according to the machine's architecture.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS ReversedNumericData {
public:
INLINE ReversedNumericData(const void *data, size_t length);
INLINE ReversedNumericData(const string &data, size_t start, size_t length);
INLINE void store_value(void *dest, size_t length);
INLINE void append_to(string &dest, size_t length);
private:
void reverse_assign(const char *source, size_t length);
char _data[max_numeric_size];
};
#include "reversedNumericData.I"
#endif