ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
00001 00011 #ifndef BYTE_ARRAY_H 00012 #define BYTE_ARRAY_H 00013 00014 #include <argos3/core/utility/datatypes/datatypes.h> 00015 #include <argos3/core/utility/configuration/argos_exception.h> 00016 #include <vector> 00017 #include <iterator> 00018 00019 namespace argos { 00020 00027 class CByteArray { 00028 00029 public: 00030 00034 CByteArray() {} 00035 00039 CByteArray(const CByteArray& c_byte_array) : 00040 m_vecBuffer(c_byte_array.m_vecBuffer) {} 00041 00049 CByteArray(const UInt8* pun_buffer, 00050 size_t un_size); 00051 00058 CByteArray(size_t un_size, 00059 UInt8 un_value = 0); 00060 00065 inline size_t Size() const { 00066 return m_vecBuffer.size(); 00067 } 00068 00082 inline void Resize(size_t un_size, 00083 UInt8 un_value = 0) { 00084 m_vecBuffer.resize(un_size, un_value); 00085 } 00086 00091 inline bool Empty() const { 00092 return m_vecBuffer.empty(); 00093 } 00094 00103 inline const UInt8* ToCArray() const { 00104 return !Empty() ? &m_vecBuffer[0] : NULL; 00105 } 00106 00113 inline void Clear() { 00114 m_vecBuffer.clear(); 00115 } 00116 00122 void Zero(); 00123 00128 CByteArray& operator=(const CByteArray& c_byte_array); 00129 00136 inline UInt8& operator[](size_t un_index) { 00137 if(un_index >= Size()) THROW_ARGOSEXCEPTION("CByteArray: index out of bounds [index = " << un_index << ", size=" << Size() << "]"); 00138 return m_vecBuffer.at(un_index); 00139 } 00140 00147 inline UInt8 operator[](size_t un_index) const { 00148 if(un_index >= Size()) THROW_ARGOSEXCEPTION("CByteArray: index out of bounds [index = " << un_index << ", size=" << Size() << "]"); 00149 return m_vecBuffer.at(un_index); 00150 } 00151 00159 CByteArray& AddBuffer(const UInt8* pun_buffer, 00160 size_t un_size); 00161 00169 CByteArray& FetchBuffer(UInt8* pun_buffer, 00170 size_t un_size); 00171 00177 CByteArray& operator<<(UInt8 un_value); 00178 00185 CByteArray& operator>>(UInt8& un_value); 00186 00192 CByteArray& operator<<(SInt8 n_value); 00193 00200 CByteArray& operator>>(SInt8& n_value); 00201 00207 CByteArray& operator<<(UInt16 un_value); 00208 00215 CByteArray& operator>>(UInt16& un_value); 00216 00222 CByteArray& operator<<(SInt16 n_value); 00223 00230 CByteArray& operator>>(SInt16& n_value); 00231 00237 CByteArray& operator<<(UInt32 un_value); 00238 00245 CByteArray& operator>>(UInt32& un_value); 00246 00252 CByteArray& operator<<(SInt32 n_value); 00253 00260 CByteArray& operator>>(SInt32& n_value); 00261 00267 CByteArray& operator<<(UInt64 un_value); 00268 00275 CByteArray& operator>>(UInt64& un_value); 00276 00282 CByteArray& operator<<(SInt64 n_value); 00283 00290 CByteArray& operator>>(SInt64& n_value); 00291 00300 CByteArray& operator<<(unsigned long int un_value); 00301 00311 CByteArray& operator>>(unsigned long int& un_value); 00312 00321 CByteArray& operator<<(signed long int n_value); 00322 00332 CByteArray& operator>>(signed long int& n_value); 00333 00339 CByteArray& operator<<(Real f_value); 00340 00347 CByteArray& operator>>(Real& f_value); 00348 00354 CByteArray& operator<<(const std::string& str_value); 00355 00362 CByteArray& operator>>(std::string& str_value); 00363 00371 friend std::ostream& operator<<(std::ostream& c_os, const CByteArray& c_byte_array); 00372 00373 private: 00374 00375 std::vector<UInt8> m_vecBuffer; 00376 00377 }; 00378 00379 } 00380 00381 #endif