// // NBO.cpp // #include #include // for NULL #include "NBO.h" NBO :: NBO () { ma_bytes[0] = 0; ma_bytes[1] = 0; ma_bytes[2] = 0; ma_bytes[3] = 0; } NBO :: NBO (int value) { setInt(value); } NBO :: NBO (unsigned int value) { setInt(value); } NBO :: NBO (char b1, char b2, char b3, char b4) { ma_bytes[0] = b1; ma_bytes[1] = b2; ma_bytes[2] = b3; ma_bytes[3] = b4; } NBO :: NBO (const char* a_bytes) { assert(a_bytes != NULL); ma_bytes[0] = a_bytes[0]; ma_bytes[1] = a_bytes[1]; ma_bytes[2] = a_bytes[2]; ma_bytes[3] = a_bytes[3]; } NBO :: NBO (const NBO& original) { ma_bytes[0] = original.ma_bytes[0]; ma_bytes[1] = original.ma_bytes[1]; ma_bytes[2] = original.ma_bytes[2]; ma_bytes[3] = original.ma_bytes[3]; } NBO& NBO :: operator= (int value) { setInt(value); return *this; } NBO& NBO :: operator= (unsigned int value) { setInt(value); return *this; } NBO& NBO :: operator= (const char* a_bytes) { assert(a_bytes != NULL); ma_bytes[0] = a_bytes[0]; ma_bytes[1] = a_bytes[1]; ma_bytes[2] = a_bytes[2]; ma_bytes[3] = a_bytes[3]; return *this; } NBO& NBO :: operator= (const NBO& original) { if(&original != this) { ma_bytes[0] = original.ma_bytes[0]; ma_bytes[1] = original.ma_bytes[1]; ma_bytes[2] = original.ma_bytes[2]; ma_bytes[3] = original.ma_bytes[3]; } return *this; } NBO :: ~NBO () {} NBO :: operator unsigned int () const { return getInt(); } char NBO :: operator[] (unsigned int index) const { assert(index < 4); return ma_bytes[index]; } char& NBO :: operator[] (unsigned int index) { assert(index < 4); return ma_bytes[index]; } unsigned int NBO :: getInt () const { return (((unsigned int)((unsigned char)(ma_bytes[0]))) << 24) | (((unsigned int)((unsigned char)(ma_bytes[1]))) << 16) | (((unsigned int)((unsigned char)(ma_bytes[2]))) << 8) | ((unsigned int)((unsigned char)(ma_bytes[3]))); } void NBO :: setInt (unsigned int value) { ma_bytes[0] = (char)((value >> 24) & 0xFF); ma_bytes[1] = (char)((value >> 16) & 0xFF); ma_bytes[2] = (char)((value >> 8) & 0xFF); ma_bytes[3] = (char)( value & 0xFF); } char NBO :: getByte (unsigned int index) const { assert(index < 4); return ma_bytes[index]; } void NBO :: setByte (unsigned int index, char value) { assert(index < 4); ma_bytes[index] = value; } void NBO :: setBytes (char b1, char b2, char b3, char b4) { ma_bytes[0] = b1; ma_bytes[1] = b2; ma_bytes[2] = b3; ma_bytes[3] = b4; } void NBO :: setArray (const char* a_bytes) { assert(a_bytes != NULL); ma_bytes[0] = a_bytes[0]; ma_bytes[1] = a_bytes[1]; ma_bytes[2] = a_bytes[2]; ma_bytes[3] = a_bytes[3]; }