00001
00034 #ifndef LL_LLBUFFER_H
00035 #define LL_LLBUFFER_H
00036
00044 #include <list>
00045 #include <vector>
00046
00051 class LLChannelDescriptors
00052 {
00053 public:
00054
00055 enum { E_CHANNEL_COUNT = 3 };
00056 LLChannelDescriptors() : mBaseChannel(0) {}
00057 explicit LLChannelDescriptors(S32 base) : mBaseChannel(base) {}
00058 S32 in() const { return mBaseChannel; }
00059 S32 out() const { return mBaseChannel + 1; }
00060
00061 protected:
00062 S32 mBaseChannel;
00063 };
00064
00065
00079 class LLSegment
00080 {
00081 public:
00082 LLSegment();
00083 LLSegment(S32 channel, U8* data, S32 data_len);
00084 ~LLSegment();
00085
00090 bool isOnChannel(S32 channel) const;
00091
00095 S32 getChannel() const;
00096
00100 void setChannel(S32 channel);
00101
00109 U8* data() const;
00110
00114 S32 size() const;
00115
00124 bool operator==(const LLSegment& rhs) const;
00125
00126 protected:
00127 S32 mChannel;
00128 U8* mData;
00129 S32 mSize;
00130 };
00131
00140 class LLBuffer
00141 {
00142 public:
00147 virtual ~LLBuffer() {}
00148
00162 virtual bool createSegment(S32 channel, S32 size, LLSegment& segment) = 0;
00163
00175 virtual bool reclaimSegment(const LLSegment& segment) = 0;
00176
00183 virtual bool containsSegment(const LLSegment& segment) const = 0;
00184
00191 virtual S32 capacity() const = 0;
00192 };
00193
00202 class LLHeapBuffer : public LLBuffer
00203 {
00204 public:
00208 LLHeapBuffer();
00209
00215 explicit LLHeapBuffer(S32 size);
00216
00223 LLHeapBuffer(const U8* src, S32 len);
00224
00228 virtual ~LLHeapBuffer();
00229
00237 S32 bytesLeft() const;
00238
00252 virtual bool createSegment(S32 channel, S32 size, LLSegment& segment);
00253
00268 virtual bool reclaimSegment(const LLSegment& segment);
00269
00276 virtual bool containsSegment(const LLSegment& segment) const;
00277
00281 virtual S32 capacity() const { return mSize; }
00282
00283 protected:
00284 U8* mBuffer;
00285 S32 mSize;
00286 U8* mNextFree;
00287 S32 mReclaimedBytes;
00288
00289 private:
00294 void allocate(S32 size);
00295 };
00296
00304 class LLBufferArray
00305 {
00306 public:
00307 typedef std::vector<LLBuffer*> buffer_list_t;
00308 typedef buffer_list_t::iterator buffer_iterator_t;
00309 typedef buffer_list_t::const_iterator const_buffer_iterator_t;
00310 typedef std::list<LLSegment> segment_list_t;
00311 typedef segment_list_t::const_iterator const_segment_iterator_t;
00312 typedef segment_list_t::iterator segment_iterator_t;
00313 enum { npos = 0xffffffff };
00314
00315 LLBufferArray();
00316 ~LLBufferArray();
00317
00318
00319
00321
00325 static LLChannelDescriptors makeChannelConsumer(
00326 const LLChannelDescriptors& channels);
00327
00338 LLChannelDescriptors nextChannel();
00340
00341
00342
00344
00348 S32 capacity() const;
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00370 bool append(S32 channel, const U8* src, S32 len);
00371
00383 bool prepend(S32 channel, const U8* src, S32 len);
00384
00397 bool insertAfter(
00398 segment_iterator_t segment,
00399 S32 channel,
00400 const U8* src,
00401 S32 len);
00402
00411 S32 countAfter(S32 channel, U8* start) const;
00412
00431 U8* readAfter(S32 channel, U8* start, U8* dest, S32& len) const;
00432
00443 U8* seek(S32 channel, U8* start, S32 delta) const;
00445
00446
00447
00449
00459 bool takeContents(LLBufferArray& source);
00461
00462
00463
00465
00482 segment_iterator_t splitAfter(U8* address);
00483
00489 segment_iterator_t beginSegment();
00490
00496 segment_iterator_t endSegment();
00497
00507 const_segment_iterator_t getSegment(U8* address) const;
00508
00518 segment_iterator_t getSegment(U8* address);
00519
00538 segment_iterator_t constructSegmentAfter(U8* address, LLSegment& segment);
00539
00551 segment_iterator_t makeSegment(S32 channel, S32 length);
00552
00559 bool eraseSegment(const segment_iterator_t& iter);
00561
00562 protected:
00581 bool copyIntoBuffers(
00582 S32 channel,
00583 const U8* src,
00584 S32 len,
00585 std::vector<LLSegment>& segments);
00586
00587 protected:
00588 S32 mNextBaseChannel;
00589 buffer_list_t mBuffers;
00590 segment_list_t mSegments;
00591 };
00592
00593 #endif // LL_LLBUFFER_H