00001
00020 #ifndef ARXX_BUFFER_H
00021 #define ARXX_BUFFER_H
00022
00023 #include <set>
00024 #include <stdexcept>
00025 #include <string>
00026 #include <vector>
00027
00028 #include "Common.h"
00029
00036 namespace Arxx
00037 {
00060 class Buffer
00061 {
00062 friend std::string sIndentation(Arxx::Buffer * pBuffer);
00063 public:
00069 typedef unsigned char value_type;
00070
00076 typedef value_type & reference;
00077
00083 typedef value_type * pointer;
00084
00090 typedef const value_type const_value_type;
00091
00097 typedef const_value_type * const_pointer;
00098
00104 typedef Arxx::u4byte size_type;
00105
00109 class Marker
00110 {
00111 public:
00112 typedef enum
00113 {
00114 LEFT,
00115 RIGHT
00116 } Alignment;
00117
00118 typedef enum
00119 {
00120 BEGIN = 0,
00121 END = 0xFFFFFFFF
00122 } Position;
00123
00131 Marker(const Arxx::Buffer & Buffer, Arxx::Buffer::size_type stPosition = 0, Arxx::Buffer::Marker::Alignment Alignment = LEFT);
00132
00138 ~Marker(void);
00139
00145 Arxx::Buffer::size_type stGetPosition(void) const;
00146
00152 void vSetPosition(Arxx::Buffer::size_type stPosition);
00153
00159 Arxx::Buffer::Marker::Alignment GetAlignment(void) const;
00160
00166 void vSetAlignment(Arxx::Buffer::Marker::Alignment Alignment);
00167
00173 bool bIsValid(void) const;
00174 private:
00180 const Arxx::Buffer * m_pBuffer;
00181
00185 Arxx::Buffer::size_type m_stPosition;
00186
00196 Alignment m_Alignment;
00197
00205 void vInvalidateBuffer(void);
00206 };
00207
00208 friend class Arxx::Buffer::Marker;
00209
00215 Buffer(void);
00216
00225 Buffer(Buffer & Buffer, size_type stPosition, size_type stLength);
00226
00234 virtual ~Buffer(void);
00235
00241 size_type stGetLength(void) const;
00242
00255 void vSetLength(size_type stLength = 0);
00256
00267 void vInsert(size_type stPosition, size_type stDataLength, const_pointer Data = 0);
00268
00276 void vDelete(size_type stPosition, size_type stLength);
00277
00286 value_type operator[](size_type stIndex) const;
00287
00296 reference operator[](size_type stIndex);
00297
00303 const_pointer GetBegin(void) const;
00304 protected:
00309 static const size_type m_stDataUpdated;
00310
00315 static const size_type m_stDataDeleted;
00316
00321 static const size_type m_stDataInserted;
00322 private:
00328 Buffer(const Buffer & Buffer);
00329
00335 Buffer & operator=(const Buffer & Buffer);
00336
00342 Buffer * m_pSupBuffer;
00343
00347 pointer m_Begin;
00348
00354 size_type m_stLength;
00355
00363 size_type m_stCapacity;
00364
00368 mutable std::set< Arxx::Buffer::Marker * > m_Markers;
00369
00375 size_type m_stPosition;
00376
00377 class SubBuffer;
00383 std::vector< SubBuffer * > m_SubBuffers;
00384
00390 bool m_bChanging;
00391
00397 void vRegister(Buffer & Buffer);
00398
00404 void vUnregister(Buffer & Buffer);
00405
00406 void vRegister(Arxx::Buffer::Marker & Marker) const;
00407
00408 void vUnregister(Arxx::Buffer::Marker & Marker) const;
00409
00419 void vWrite(Arxx::Buffer & Buffer, Arxx::Buffer::size_type stPosition, Arxx::Buffer::size_type stDataLength, Arxx::Buffer::const_pointer Data = 0);
00420
00456 void vParentDataChanged(size_type stChangeMode, size_type stPosition, size_type stLength);
00457 };
00458
00468 std::ostream & operator<<(std::ostream & OStream, const Arxx::Buffer & Buffer);
00469 };
00470
00471 #endif