1/*
2    File:       CBufferSegment.h
3
4    Contains:   Interface to the CBufferSegment class
5
6*/
7
8#ifndef __CBUFFERSEGMENT_H
9#define __CBUFFERSEGMENT_H
10
11#include "CBuffer.h"
12
13enum {                                      // move this out of here!
14    kDefaultCBufferSize = (2048 + 20)       // max lap packet and some overhead and some slop
15};
16
17//--------------------------------------------------------------------------------
18//      CBufferSegment
19//--------------------------------------------------------------------------------
20class CBufferSegment : public CBuffer
21{
22    OSDeclareDefaultStructors(CBufferSegment);
23
24public:
25
26    static CBufferSegment * New(Size len = kDefaultCBufferSize);    // allocate and init a buffer of size len
27    static CBufferSegment * New(UByte *buffer, Size len);           // use existing buffer, don't alloc or free it
28    void free();
29    void Delete();                  // old style, same as release() for now ...
30
31    // get primitives
32
33    virtual int     Peek(void);
34    virtual int     Next(void);
35    virtual uintptr_t     Skip(void);
36    virtual int     Get(void);
37    virtual Size    Getn(UByte* p, Size n);
38    virtual int     CopyOut(UByte* p, Size& n);
39
40    // put primitives
41
42    virtual int     Put(int dataByte);
43    virtual Size    Putn(const UByte* p, Size n);
44    virtual int     CopyIn(const UByte* p, Size& n);
45
46    // misc
47
48    virtual void    Reset(void);
49
50    // position and size
51
52    virtual Long    Hide(Long count, int dir);
53    virtual Size    Seek(Long off, int dir);
54    virtual Size    Position(void) const;
55    virtual Size    GetSize(void) const;
56    virtual Boolean AtEOF(void) const;
57
58    // direct access for ... (needed anymore?)
59
60    UByte*      GetBufferPtr(void);
61    Size        GetBufferSize(void);
62    UInt8   *   GetBufferBase( void );
63
64private:
65
66    Boolean Init(UByte *buffer, Size len);
67
68    Boolean         fFreeMe;        // true if we allocated the buffer
69
70    UByte*          fBufBase;
71    UByte*          fBufEnd;
72    Size            fSize;
73
74    UByte*          fBase;
75    UByte*          fMark;
76    UByte*          fEnd;
77
78}; // CBufferSegment
79
80
81//--------------------------------------------------------------------------------
82//      CBufferSegment inlines
83//--------------------------------------------------------------------------------
84
85inline UByte* CBufferSegment::GetBufferPtr()
86    { return fBase; }
87
88inline Size CBufferSegment::GetBufferSize()
89    { return (Size) (fEnd - fBase); }
90
91inline UInt8 *  CBufferSegment::GetBufferBase() { return fBufBase; }
92inline void     CBufferSegment::Delete(void)    { this->release(); return; }
93
94#endif  /*  __BUFFERSEGMENT_H   */
95