35 #pragma warning( push ) 
   40 #define _copysign copysign 
   61         BitStream( 
const unsigned int initialBytesToAllocate );
 
   73         BitStream( 
unsigned char* _data, 
const unsigned int lengthInBytes, 
bool _copyData );
 
   86         template <
class templateType>
 
   87             bool Serialize(
bool writeToBitstream, templateType &inOutTemplateVar);
 
   96         template <
class templateType>
 
   97             bool SerializeDelta(
bool writeToBitstream, templateType &inOutCurrentValue, 
const templateType &lastValue);
 
  103         template <
class templateType>
 
  104             bool SerializeDelta(
bool writeToBitstream, templateType &inOutCurrentValue);
 
  114         template <
class templateType>
 
  115             bool SerializeCompressed(
bool writeToBitstream, templateType &inOutTemplateVar);
 
  127         template <
class templateType>
 
  128             bool SerializeCompressedDelta(
bool writeToBitstream, templateType &inOutCurrentValue, 
const templateType &lastValue);
 
  132         template <
class templateType>
 
  133             bool SerializeCompressedDelta(
bool writeToBitstream, templateType &inOutTemplateVar);
 
  140         bool Serialize(
bool writeToBitstream,  
char* inOutByteArray, 
const unsigned int numberOfBytes );
 
  147         bool SerializeFloat16(
bool writeToBitstream, 
float &inOutFloat, 
float floatMin, 
float floatMax);
 
  154         template <
class serializationType, 
class sourceType >
 
  155         bool SerializeCasted( 
bool writeToBitstream, sourceType &value );
 
  165         template <
class templateType>
 
  166         bool SerializeBitsFromIntegerRange( 
bool writeToBitstream, templateType &value, 
const templateType minimum, 
const templateType maximum, 
bool allowOutsideRange=
false );
 
  168         template <
class templateType>
 
  169         bool SerializeBitsFromIntegerRange( 
bool writeToBitstream, templateType &value, 
const templateType minimum, 
const templateType maximum, 
const int requiredBits, 
bool allowOutsideRange=
false );
 
  179         template <
class templateType> 
 
  180             bool SerializeNormVector(
bool writeToBitstream,  templateType &x, templateType &y, templateType &z );
 
  189         template <
class templateType> 
 
  190             bool SerializeVector(
bool writeToBitstream,  templateType &x, templateType &y, templateType &z );
 
  199         template <
class templateType> 
 
  200             bool SerializeNormQuat(
bool writeToBitstream,  templateType &w, templateType &x, templateType &y, templateType &z);
 
  206         template <
class templateType> 
 
  207             bool SerializeOrthMatrix(
 
  208             bool writeToBitstream,
 
  209             templateType &m00, templateType &m01, templateType &m02,
 
  210             templateType &m10, templateType &m11, templateType &m12,
 
  211             templateType &m20, templateType &m21, templateType &m22 );
 
  224         bool SerializeBits(
bool writeToBitstream, 
unsigned char* inOutByteArray, 
const BitSize_t numberOfBitsToSerialize, 
const bool rightAlignedBits = 
true );
 
  229         template <
class templateType>
 
  230             void Write(
const templateType &inTemplateVar);
 
  235         template <
class templateType>
 
  236             void WritePtr(templateType *inTemplateVar);
 
  243         template <
class templateType>
 
  244             void WriteDelta(
const templateType ¤tValue, 
const templateType &lastValue);
 
  248         template <
class templateType>
 
  249             void WriteDelta(
const templateType ¤tValue);
 
  257         template <
class templateType>
 
  258             void WriteCompressed(
const templateType &inTemplateVar);
 
  268         template <
class templateType>
 
  269             void WriteCompressedDelta(
const templateType ¤tValue, 
const templateType &lastValue);
 
  272         template <
class templateType>
 
  273             void WriteCompressedDelta(
const templateType ¤tValue);
 
  279         template <
class templateType>
 
  280             bool Read(templateType &outTemplateVar);
 
  287         bool Read(
wchar_t *&varString);
 
  288         bool Read(
wchar_t *&varString, 
size_t varStringLength);
 
  296         template <
class templateType>
 
  297             bool ReadDelta(templateType &outTemplateVar);
 
  306         template <
class templateType>
 
  307             bool ReadCompressed(templateType &outTemplateVar);
 
  316         bool ReadCompressed(
wchar_t *&varString);
 
  317         bool ReadCompressed(
wchar_t *&varString, 
size_t varStringLength);
 
  329         template <
class templateType>
 
  330             bool ReadCompressedDelta(templateType &outTemplateVar);
 
  344         void Write( 
const char* inputByteArray, 
const unsigned int numberOfBytes );
 
  358         void WriteFloat16( 
float x, 
float floatMin, 
float floatMax );
 
  364         template <
class serializationType, 
class sourceType >
 
  365         void WriteCasted( 
const sourceType &value );
 
  374         template <
class templateType>
 
  375         void WriteBitsFromIntegerRange( 
const templateType value, 
const templateType minimum, 
const templateType maximum, 
bool allowOutsideRange=
false );
 
  377         template <
class templateType>
 
  378         void WriteBitsFromIntegerRange( 
const templateType value, 
const templateType minimum, 
const templateType maximum, 
const int requiredBits, 
bool allowOutsideRange=
false );
 
  386         template <
class templateType> 
 
  387         void WriteNormVector( templateType x, templateType y, templateType z );
 
  395         template <
class templateType> 
 
  396         void WriteVector( templateType x, templateType y, templateType z );
 
  403         template <
class templateType> 
 
  404         void WriteNormQuat( templateType w, templateType x, templateType y, templateType z);
 
  409         template <
class templateType> 
 
  410         void WriteOrthMatrix(
 
  411             templateType m00, templateType m01, templateType m02,
 
  412             templateType m10, templateType m11, templateType m12,
 
  413             templateType m20, templateType m21, templateType m22 );
 
  420         bool Read( 
char* output, 
const unsigned int numberOfBytes );
 
  426         bool ReadFloat16( 
float &outFloat, 
float floatMin, 
float floatMax );
 
  432         template <
class serializationType, 
class sourceType >
 
  433         bool ReadCasted( sourceType &value );
 
  442         template <
class templateType>
 
  443         bool ReadBitsFromIntegerRange( templateType &value, 
const templateType minimum, 
const templateType maximum, 
bool allowOutsideRange=
false );
 
  445         template <
class templateType>
 
  446         bool ReadBitsFromIntegerRange( templateType &value, 
const templateType minimum, 
const templateType maximum, 
const int requiredBits, 
bool allowOutsideRange=
false );
 
  455         template <
class templateType> 
 
  456         bool ReadNormVector( templateType &x, templateType &y, templateType &z );
 
  465         template <
class templateType> 
 
  466         bool ReadVector( templateType &x, templateType &y, templateType &z );
 
  474         template <
class templateType> 
 
  475         bool ReadNormQuat( templateType &w, templateType &x, templateType &y, templateType &z);
 
  481         template <
class templateType> 
 
  483             templateType &m00, templateType &m01, templateType &m02,
 
  484             templateType &m10, templateType &m11, templateType &m12,
 
  485             templateType &m20, templateType &m21, templateType &m22 );
 
  488         void ResetReadPointer( 
void );
 
  491         void ResetWritePointer( 
void );
 
  495         void AssertStreamEmpty( 
void );
 
  498         void PrintBits( 
char *out ) 
const;
 
  499         void PrintBits( 
char *out, 
size_t outLength ) 
const;
 
  500         void PrintBits( 
void ) 
const;
 
  501         void PrintHex( 
char *out) 
const;
 
  502         void PrintHex( 
char *out, 
size_t outLength ) 
const;
 
  503         void PrintHex( 
void ) 
const;
 
  507         void IgnoreBits( 
const BitSize_t numberOfBits );
 
  511         void IgnoreBytes( 
const unsigned int numberOfBytes );
 
  518         void SetWriteOffset( 
const BitSize_t offset );
 
  540         BitSize_t CopyData( 
unsigned char** _data ) 
const;
 
  544         void SetData( 
unsigned char *inByteArray );
 
  549         inline unsigned char* 
GetData( 
void )
 const {
return data;}
 
  560         void WriteBits( 
const unsigned char* inByteArray, 
BitSize_t numberOfBitsToWrite, 
const bool rightAlignedBits = 
true );
 
  569         void WriteAlignedBytes( 
const unsigned char *inByteArray, 
const unsigned int numberOfBytesToWrite );
 
  572         void EndianSwapBytes( 
int byteOffset, 
int length );
 
  578         void WriteAlignedBytesSafe( 
const char *inByteArray, 
const unsigned int inputLength, 
const unsigned int maxBytesToWrite );
 
  587         bool ReadAlignedBytes( 
unsigned char *inOutByteArray, 
const unsigned int numberOfBytesToRead );
 
  593         bool ReadAlignedBytesSafe( 
char *inOutByteArray, 
int &inputLength, 
const int maxBytesToRead );
 
  594         bool ReadAlignedBytesSafe( 
char *inOutByteArray, 
unsigned int &inputLength, 
const unsigned int maxBytesToRead );
 
  599         bool ReadAlignedBytesSafeAlloc( 
char **outByteArray, 
int &inputLength, 
const unsigned int maxBytesToRead );
 
  600         bool ReadAlignedBytesSafeAlloc( 
char **outByteArray, 
unsigned int &inputLength, 
const unsigned int maxBytesToRead );
 
  624         bool ReadBits( 
unsigned char *inOutByteArray, 
BitSize_t numberOfBitsToRead, 
const bool alignBitsToRight = 
true );
 
  633         bool ReadBit( 
void );
 
  637         void AssertCopyData( 
void );
 
  642         void SetNumberOfBitsAllocated( 
const BitSize_t lengthInBits );
 
  645         void AddBitsAndReallocate( 
const BitSize_t numberOfBitsToWrite );
 
  649         BitSize_t GetNumberOfBitsAllocated(
void) 
const;
 
  652         bool Read(
char *varString);
 
  653         bool Read(
unsigned char *varString);
 
  656         void PadWithZeroToByteLength( 
unsigned int bytes );
 
  660         static int NumberOfLeadingZeroes( 
uint8_t x );
 
  661         static int NumberOfLeadingZeroes( 
uint16_t x );
 
  662         static int NumberOfLeadingZeroes( 
uint32_t x );
 
  663         static int NumberOfLeadingZeroes( 
uint64_t x );
 
  664         static int NumberOfLeadingZeroes( 
int8_t x );
 
  665         static int NumberOfLeadingZeroes( 
int16_t x );
 
  666         static int NumberOfLeadingZeroes( 
int32_t x );
 
  667         static int NumberOfLeadingZeroes( 
int64_t x );
 
  670         void WriteAlignedVar8(
const char *inByteArray);
 
  672         bool ReadAlignedVar8(
char *inOutByteArray);
 
  674         void WriteAlignedVar16(
const char *inByteArray);
 
  676         bool ReadAlignedVar16(
char *inOutByteArray);
 
  678         void WriteAlignedVar32(
const char *inByteArray);
 
  680         bool ReadAlignedVar32(
char *inOutByteArray);
 
  682         inline void Write(
const char * 
const inStringVar)
 
  686         inline void Write(
const wchar_t * 
const inStringVar)
 
  690         inline void Write(
const unsigned char * 
const inTemplateVar)
 
  692             Write((
const char*)inTemplateVar);
 
  694         inline void Write(
char * 
const inTemplateVar)
 
  696             Write((
const char*)inTemplateVar);
 
  698         inline void Write(
unsigned char * 
const inTemplateVar)
 
  700             Write((
const char*)inTemplateVar);
 
  702         inline void WriteCompressed(
const char * 
const inStringVar)
 
  706         inline void WriteCompressed(
const wchar_t * 
const inStringVar)
 
  710         inline void WriteCompressed(
const unsigned char * 
const inTemplateVar)
 
  712             WriteCompressed((
const char*) inTemplateVar);
 
  714         inline void WriteCompressed(
char * 
const inTemplateVar)
 
  716             WriteCompressed((
const char*) inTemplateVar);
 
  718         inline void WriteCompressed(
unsigned char * 
const inTemplateVar)
 
  720             WriteCompressed((
const char*) inTemplateVar);
 
  725 #ifndef __BITSTREAM_NATIVE_END 
  726             return IsNetworkOrder()==
false;
 
  731         inline static bool IsBigEndian(
void)
 
  733             return IsNetworkOrder();
 
  735         inline static bool IsNetworkOrder(
void) {
bool r = IsNetworkOrderInternal(); 
return r;}
 
  737         static bool IsNetworkOrderInternal(
void);
 
  738         static void ReverseBytes(
unsigned char *inByteArray, 
unsigned char *inOutByteArray, 
const unsigned int length);
 
  739         static void ReverseBytesInPlace(
unsigned char *inOutData,
const unsigned int length);
 
  748         BitStream& operator = ( 
const BitStream& invalid ) {
 
  756         void WriteCompressed( 
const unsigned char* inByteArray, 
const unsigned int size, 
const bool unsignedData );
 
  759         bool ReadCompressed( 
unsigned char* inOutByteArray, 
const unsigned int size, 
const bool unsignedData );
 
  777         template <
class templateType>
 
  780             if (writeToBitstream)
 
  781                 Write(inOutTemplateVar);
 
  783                 return Read(inOutTemplateVar);
 
  787         template <
class templateType>
 
  790             if (writeToBitstream)
 
  797         template <
class templateType>
 
  800             if (writeToBitstream)
 
  807         template <
class templateType>
 
  810             if (writeToBitstream)
 
  817         template <
class templateType>
 
  820             if (writeToBitstream)
 
  827         template <
class templateType>
 
  830             if (writeToBitstream)
 
  837         inline bool BitStream::Serialize(
bool writeToBitstream, 
char* inOutByteArray, 
const unsigned int numberOfBytes )
 
  839             if (writeToBitstream)
 
  840                 Write(inOutByteArray, numberOfBytes);
 
  842                 return Read(inOutByteArray, numberOfBytes);
 
  846         template <
class serializationType, 
class sourceType >
 
  849             if (writeToBitstream) WriteCasted<serializationType>(value);
 
  850             else return ReadCasted<serializationType>(value);
 
  854         template <
class templateType>
 
  860         template <
class templateType>
 
  868         template <
class templateType>
 
  871             if (writeToBitstream)
 
  878         template <
class templateType>
 
  881             if (writeToBitstream)
 
  888         template <
class templateType>
 
  891             if (writeToBitstream)
 
  898         template <
class templateType>
 
  900         bool writeToBitstream,
 
  901         templateType &m00, templateType &m01, templateType &m02,
 
  902         templateType &m10, templateType &m11, templateType &m12,
 
  903         templateType &m20, templateType &m21, templateType &m22 )
 
  905             if (writeToBitstream)
 
  914             if (writeToBitstream)
 
  915                 WriteBits(inOutByteArray,numberOfBitsToSerialize,rightAlignedBits);
 
  917                 return ReadBits(inOutByteArray,numberOfBitsToSerialize,rightAlignedBits);
 
  921     template <
class templateType>
 
  925 #pragma warning(disable:4127)   // conditional expression is constant 
  927         if (
sizeof(inTemplateVar)==1)
 
  928             WriteBits( ( 
unsigned char* ) & inTemplateVar, 
sizeof( templateType ) * 8, 
true );
 
  931 #ifndef __BITSTREAM_NATIVE_END 
  934                 unsigned char output[
sizeof(templateType)];
 
  935                 ReverseBytes((
unsigned char*)&inTemplateVar, output, 
sizeof(templateType));
 
  936                 WriteBits( ( 
unsigned char* ) output, 
sizeof(templateType) * 8, 
true );
 
  940                 WriteBits( ( 
unsigned char* ) & inTemplateVar, 
sizeof(templateType) * 8, 
true );
 
  944     template <
class templateType>
 
  948 #pragma warning(disable:4127)   // conditional expression is constant 
  950         if (
sizeof(templateType)==1)
 
  951             WriteBits( ( 
unsigned char* ) inTemplateVar, 
sizeof( templateType ) * 8, 
true );
 
  954 #ifndef __BITSTREAM_NATIVE_END 
  957                 unsigned char output[
sizeof(templateType)];
 
  958                 ReverseBytes((
unsigned char*) inTemplateVar, output, 
sizeof(templateType));
 
  959                 WriteBits( ( 
unsigned char* ) output, 
sizeof(templateType) * 8, 
true );
 
  963                 WriteBits( ( 
unsigned char* ) inTemplateVar, 
sizeof(templateType) * 8, 
true );
 
  991             WriteBits((
unsigned char*)&binaryAddress, 
sizeof(binaryAddress)*8, 
true);
 
  993             WriteBits((
unsigned char*)&p, 
sizeof(
unsigned short)*8, 
true);
 
  997 #if RAKNET_SUPPORT_IPV6==1 
 1012             data[( numberOfBitsUsed >> 3 ) + 0] = ((
unsigned char *)&inTemplateVar.
val)[0];
 
 1013             data[( numberOfBitsUsed >> 3 ) + 1] = ((
unsigned char *)&inTemplateVar.
val)[1];
 
 1014             data[( numberOfBitsUsed >> 3 ) + 2] = ((
unsigned char *)&inTemplateVar.
val)[2];
 
 1018             data[( numberOfBitsUsed >> 3 ) + 0] = ((
unsigned char *)&inTemplateVar.
val)[3];
 
 1019             data[( numberOfBitsUsed >> 3 ) + 1] = ((
unsigned char *)&inTemplateVar.
val)[2];
 
 1020             data[( numberOfBitsUsed >> 3 ) + 2] = ((
unsigned char *)&inTemplateVar.
val)[1];
 
 1023         numberOfBitsUsed+=3*8;
 
 1057         Write((
const char*)inTemplateVar);
 
 1062         Write((
const char*)inTemplateVar);
 
 1067         Write((
const char*)inTemplateVar);
 
 1075     template <
class templateType>
 
 1078         if (currentValue==lastValue)
 
 1085             Write(currentValue);
 
 1097         Write(currentValue);
 
 1102     template <
class templateType>
 
 1106         Write(currentValue);
 
 1115     template <
class templateType>
 
 1119 #pragma warning(disable:4127)   // conditional expression is constant 
 1121         if (
sizeof(inTemplateVar)==1)
 
 1122             WriteCompressed( ( 
unsigned char* ) & inTemplateVar, 
sizeof( templateType ) * 8, 
true );
 
 1125 #ifndef __BITSTREAM_NATIVE_END 
 1128                 unsigned char output[
sizeof(templateType)];
 
 1129                 ReverseBytes((
unsigned char*)&inTemplateVar, output, 
sizeof(templateType));
 
 1130                 WriteCompressed( ( 
unsigned char* ) output, 
sizeof(templateType) * 8, 
true );
 
 1134                 WriteCompressed( ( 
unsigned char* ) & inTemplateVar, 
sizeof(templateType) * 8, 
true );
 
 1141         Write(inTemplateVar);
 
 1147         Write(inTemplateVar);
 
 1159         Write(inTemplateVar);
 
 1166         RakAssert(inTemplateVar > -1.01f && inTemplateVar < 1.01f);
 
 1167         float varCopy=inTemplateVar;
 
 1168         if (varCopy < -1.0f)
 
 1172         Write((
unsigned short)((varCopy+1.0f)*32767.5f));
 
 1179         RakAssert(inTemplateVar > -1.01 && inTemplateVar < 1.01);
 
 1180         double varCopy=inTemplateVar;
 
 1181         if (varCopy < -1.0f)
 
 1234     template <
class templateType>
 
 1237         if (currentValue==lastValue)
 
 1256         Write(currentValue);
 
 1261     template <
class templateType>
 
 1273         Write(currentValue);
 
 1278     template <
class templateType>
 
 1282 #pragma warning(disable:4127)   // conditional expression is constant 
 1284         if (
sizeof(outTemplateVar)==1)
 
 1285             return ReadBits( ( 
unsigned char* ) &outTemplateVar, 
sizeof(templateType) * 8, 
true );
 
 1288 #ifndef __BITSTREAM_NATIVE_END 
 1291                 unsigned char output[
sizeof(templateType)];
 
 1292                 if (
ReadBits( ( 
unsigned char* ) output, 
sizeof(templateType) * 8, 
true ))
 
 1294                     ReverseBytes(output, (
unsigned char*)&outTemplateVar, 
sizeof(templateType));
 
 1301                 return ReadBits( ( 
unsigned char* ) & outTemplateVar, 
sizeof(templateType) * 8, 
true );
 
 1313         if ( data[ readOffset >> 3 ] & ( 0x80 >> ( readOffset & 7 ) ) )   
 
 1314             outTemplateVar = 
true;
 
 1316             outTemplateVar = 
false;
 
 1329         unsigned char ipVersion;
 
 1333             outTemplateVar.
address.addr4.sin_family=AF_INET;
 
 1337             ReadBits( ( 
unsigned char* ) & binaryAddress, 
sizeof(binaryAddress) * 8, 
true );
 
 1339             outTemplateVar.
address.addr4.sin_addr.s_addr=~binaryAddress;
 
 1340             bool b = 
ReadBits(( 
unsigned char* ) & outTemplateVar.
address.addr4.sin_port, 
sizeof(outTemplateVar.
address.addr4.sin_port) * 8, 
true);
 
 1346 #if RAKNET_SUPPORT_IPV6==1 
 1347             bool b = 
ReadBits((
unsigned char*) &outTemplateVar.
address.addr6, 
sizeof(outTemplateVar.
address.addr6)*8, 
true);
 
 1365             ((
unsigned char *)&outTemplateVar.
val)[0]=data[ (readOffset >> 3) + 0];
 
 1366             ((
unsigned char *)&outTemplateVar.
val)[1]=data[ (readOffset >> 3) + 1];
 
 1367             ((
unsigned char *)&outTemplateVar.
val)[2]=data[ (readOffset >> 3) + 2];
 
 1368             ((
unsigned char *)&outTemplateVar.
val)[3]=0;
 
 1373             ((
unsigned char *)&outTemplateVar.
val)[3]=data[ (readOffset >> 3) + 0];
 
 1374             ((
unsigned char *)&outTemplateVar.
val)[2]=data[ (readOffset >> 3) + 1];
 
 1375             ((
unsigned char *)&outTemplateVar.
val)[1]=data[ (readOffset >> 3) + 2];
 
 1376             ((
unsigned char *)&outTemplateVar.
val)[0]=0;
 
 1386         return Read(outTemplateVar.
g);
 
 1424     template <
class templateType>
 
 1429         success=
Read(dataWritten);
 
 1431             success=
Read(outTemplateVar);
 
 1440         return Read(outTemplateVar);
 
 1449     template <
class templateType>
 
 1453 #pragma warning(disable:4127)   // conditional expression is constant 
 1455         if (
sizeof(outTemplateVar)==1)
 
 1456             return ReadCompressed( ( 
unsigned char* ) &outTemplateVar, 
sizeof(templateType) * 8, 
true );
 
 1459 #ifndef __BITSTREAM_NATIVE_END 
 1462                 unsigned char output[
sizeof(templateType)];
 
 1463                 if (
ReadCompressed( ( 
unsigned char* ) output, 
sizeof(templateType) * 8, 
true ))
 
 1465                     ReverseBytes(output, (
unsigned char*)&outTemplateVar, 
sizeof(templateType));
 
 1472                 return ReadCompressed( ( 
unsigned char* ) & outTemplateVar, 
sizeof(templateType) * 8, 
true );
 
 1479         return Read(outTemplateVar);
 
 1485         return Read(outTemplateVar);
 
 1491         return Read(outTemplateVar);
 
 1497         return Read(outTemplateVar);
 
 1504         unsigned short compressedFloat;
 
 1505         if (
Read(compressedFloat))
 
 1507             outTemplateVar = ((float)compressedFloat / 32767.5f - 1.0f);
 
 1518         if (
Read(compressedFloat))
 
 1520             outTemplateVar = ((double)compressedFloat / 2147483648.0 - 1.0);
 
 1565     template <
class templateType>
 
 1570         success=
Read(dataWritten);
 
 1581         return Read(outTemplateVar);
 
 1584     template <
class destinationType, 
class sourceType >
 
 1587         destinationType val = (destinationType) value;
 
 1591     template <
class templateType>
 
 1597     template <
class templateType>
 
 1601         RakAssert(allowOutsideRange==
true || (value>=minimum && value<=maximum));
 
 1602         if (allowOutsideRange)
 
 1604             if (value<minimum || value>maximum)
 
 1612         templateType valueOffMin=value-minimum;
 
 1615             unsigned char output[
sizeof(templateType)];
 
 1616             ReverseBytes((
unsigned char*)&valueOffMin, output, 
sizeof(templateType));
 
 1621             WriteBits((
unsigned char*) &valueOffMin,requiredBits);
 
 1625     template <
class templateType> 
 
 1629         RakAssert(x <= 1.01 && y <= 1.01 && z <= 1.01 && x >= -1.01 && y >= -1.01 && z >= -1.01);
 
 1637     template <
class templateType> 
 
 1640         templateType magnitude = sqrt(x * x + y * y + z * z);
 
 1641         Write((
float)magnitude);
 
 1642         if (magnitude > 0.00001f)
 
 1653     template <
class templateType> 
 
 1656         Write((
bool)(w<0.0));
 
 1657         Write((
bool)(x<0.0));
 
 1658         Write((
bool)(y<0.0));
 
 1659         Write((
bool)(z<0.0));
 
 1660         Write((
unsigned short)(fabs(x)*65535.0));
 
 1661         Write((
unsigned short)(fabs(y)*65535.0));
 
 1662         Write((
unsigned short)(fabs(z)*65535.0));
 
 1666     template <
class templateType> 
 
 1668         templateType m00, templateType m01, templateType m02,
 
 1669         templateType m10, templateType m11, templateType m12,
 
 1670         templateType m20, templateType m21, templateType m22 )
 
 1681         sum = 1 + m00 + m11 + m22;
 
 1682         if (sum < 0.0f) sum=0.0f;
 
 1683         qw = sqrt( sum  ) / 2;
 
 1684         sum = 1 + m00 - m11 - m22;
 
 1685         if (sum < 0.0f) sum=0.0f;
 
 1686         qx = sqrt( sum  ) / 2;
 
 1687         sum = 1 - m00 + m11 - m22;
 
 1688         if (sum < 0.0f) sum=0.0f;
 
 1689         qy = sqrt( sum  ) / 2;
 
 1690         sum = 1 - m00 - m11 + m22;
 
 1691         if (sum < 0.0f) sum=0.0f;
 
 1692         qz = sqrt( sum  ) / 2;
 
 1693         if (qw < 0.0) qw=0.0;
 
 1694         if (qx < 0.0) qx=0.0;
 
 1695         if (qy < 0.0) qy=0.0;
 
 1696         if (qz < 0.0) qz=0.0;
 
 1697         qx = 
_copysign( (
double) qx, (
double) (m21 - m12) );
 
 1698         qy = 
_copysign( (
double) qy, (
double) (m02 - m20) );
 
 1699         qz = 
_copysign( (
double) qz, (
double) (m10 - m01) );
 
 1704     template <
class serializationType, 
class sourceType >
 
 1707         serializationType val;
 
 1708         bool success = 
Read(val);
 
 1709         value=(sourceType) val;
 
 1713     template <
class templateType>
 
 1719     template <
class templateType>
 
 1723         if (allowOutsideRange)
 
 1725             bool isOutsideRange;
 
 1726             Read(isOutsideRange);
 
 1730         unsigned char output[
sizeof(templateType)];
 
 1731         memset(output,0,
sizeof(output));
 
 1732         bool success = 
ReadBits(output,requiredBits);
 
 1737             memcpy(&value,output,
sizeof(output));
 
 1745     template <
class templateType> 
 
 1758     template <
class templateType> 
 
 1763         if (!
Read(magnitude))
 
 1765         if (magnitude>0.00001f)
 
 1774             float cx=0.0f,cy=0.0f,cz=0.0f;
 
 1795     template <
class templateType> 
 
 1798         bool cwNeg=
false, cxNeg=
false, cyNeg=
false, czNeg=
false;
 
 1799         unsigned short cx,cy,cz;
 
 1810         x=(templateType)(cx/65535.0);
 
 1811         y=(templateType)(cy/65535.0);
 
 1812         z=(templateType)(cz/65535.0);
 
 1816         float difference = 1.0f - x*x - y*y - z*z;
 
 1817         if (difference < 0.0f)
 
 1819         w = (templateType)(sqrt(difference));
 
 1826     template <
class templateType> 
 
 1828         templateType &m00, templateType &m01, templateType &m02,
 
 1829         templateType &m10, templateType &m11, templateType &m12,
 
 1830         templateType &m20, templateType &m21, templateType &m22 )
 
 1838         double sqw = (double)qw*(
double)qw;
 
 1839         double sqx = (double)qx*(
double)qx;
 
 1840         double sqy = (double)qy*(
double)qy;
 
 1841         double sqz = (double)qz*(
double)qz;
 
 1842         m00 =  (templateType)(sqx - sqy - sqz + sqw); 
 
 1843         m11 = (templateType)(-sqx + sqy - sqz + sqw);
 
 1844         m22 = (templateType)(-sqx - sqy + sqz + sqw);
 
 1846         double tmp1 = (double)qx*(
double)qy;
 
 1847         double tmp2 = (double)qz*(
double)qw;
 
 1848         m10 = (templateType)(2.0 * (tmp1 + tmp2));
 
 1849         m01 = (templateType)(2.0 * (tmp1 - tmp2));
 
 1851         tmp1 = (double)qx*(
double)qz;
 
 1852         tmp2 = (double)qy*(
double)qw;
 
 1853         m20 =(templateType)(2.0 * (tmp1 - tmp2));
 
 1854         m02 = (templateType)(2.0 * (tmp1 + tmp2));
 
 1855         tmp1 = (double)qy*(
double)qz;
 
 1856         tmp2 = (double)qx*(
double)qw;
 
 1857         m21 = (templateType)(2.0 * (tmp1 + tmp2));
 
 1858         m12 = (templateType)(2.0 * (tmp1 - tmp2));
 
 1863     template <
class templateType>
 
 1869     template <
class templateType>
 
 1872         bool success = in.
Read(c);
 
 1882 #pragma warning( pop )