Beam-lib  2.16.3
This is the Beam C++ class library.
BBuffer.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BBuffer.h Buffer Class
3  * T.Barnaby, BEAM Ltd, 27/2/94
4  * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef BBUFFER_H
8 #define BBUFFER_H 1
9 
10 #include <BTypes.h>
11 #include <BString.h>
12 #include <BError.h>
13 #include <BComplex.h>
14 #include <BEndian.h>
15 
16 #if IS_BIG_ENDIAN
17 #define BBigEndian 1
18 #else
19 #define BBigEndian 0
20 #endif
21 
22 class BTimeStamp;
23 
24 class BBuffer {
26 public:
27  BBuffer(BUInt size = 0);
28  ~BBuffer();
29 
30  int setSize(BUInt32 size);
31  int setData(const void* data, BUInt32 size);
32  int writeData(BUInt32 pos, const void* data, BUInt32 size);
33 
34  char* data();
35  BUInt32 size();
36 
37  int resize(BUInt32 size){ return setSize(size); }
38 protected:
40  char* odata;
42 };
43 
44 class BBufferStore : public BBuffer{
45 public:
46  BBufferStore(BUInt size = 0, int swapBytes = BBigEndian);
47  ~BBufferStore();
48 
49  BUInt32 getPos();
50  void setPos(BUInt32 pos);
51 
53  void setHexString(BString s);
54 
55  int push(BInt8 v);
56  int push(BUInt8 v);
57  int push(BInt16 v);
58  int push(BUInt16 v);
59  int push(BInt32 v);
60  int push(BUInt32 v);
61  int push(BInt64 v);
62  int push(BUInt64 v);
63  int push(BFloat32 v);
64  int push(BFloat64 v);
65  int push(const BString& v);
66  int push(const BError& v);
67  int push(const BTimeStamp& v);
68  int push(const BComplex& v);
69  int push(BUInt32 nBytes, const void* data, const char* swapType = "1");
70 
71  int pop(BInt8& v);
72  int pop(BUInt8& v);
73  int pop(BInt16& v);
74  int pop(BUInt16& v);
75  int pop(BInt32& v);
76  int pop(BUInt32& v);
77  int pop(BInt64& v);
78  int pop(BUInt64& v);
79  int pop(BFloat32& v);
80  int pop(BFloat64& v);
81  int pop(BString& v);
82  int pop(BError& v);
83  int pop(BTimeStamp& v);
84  int pop(BComplex& v);
85  int pop(BUInt32 nBytes, void* data, const char* swapType = "1");
86 
87 protected:
90 };
91 
92 #endif
BUInt32 getPos()
Definition: BBuffer.cpp:85
int64_t BInt64
Definition: BTypes.h:22
Definition: BString.h:18
void setHexString(BString s)
Definition: BBuffer.cpp:115
float BFloat32
Definition: BTypes.h:24
Definition: BBuffer.h:44
int16_t BInt16
Definition: BTypes.h:18
~BBuffer()
Definition: BBuffer.cpp:23
BUInt32 odataSize
Definition: BBuffer.h:39
uint64_t BUInt64
Definition: BTypes.h:23
double BFloat64
Definition: BTypes.h:25
int pop(BInt8 &v)
Definition: BBuffer.cpp:242
#define BBigEndian
Definition: BBuffer.h:19
void setPos(BUInt32 pos)
Definition: BBuffer.cpp:89
Definition: BBuffer.h:24
int setData(const void *data, BUInt32 size)
Sets buffer data resized to contain the data.
Definition: BBuffer.cpp:57
BString getHexString()
Definition: BBuffer.cpp:93
BUInt32 osize
Definition: BBuffer.h:41
int32_t BInt32
Definition: BTypes.h:20
std::complex< double > BComplex
Definition: BComplex.h:16
int oswapBytes
Definition: BBuffer.h:89
BUInt32 size()
Size of the buffer in bytes.
Definition: BBuffer.cpp:31
BUInt32 BUInt
Definition: BTypes.h:30
uint32_t BUInt32
Definition: BTypes.h:21
BUInt32 opos
Definition: BBuffer.h:88
~BBufferStore()
Definition: BBuffer.cpp:82
uint16_t BUInt16
Definition: BTypes.h:19
char * data()
The data.
Definition: BBuffer.cpp:53
uint8_t BUInt8
Definition: BTypes.h:17
int setSize(BUInt32 size)
Sets the bufer size.
Definition: BBuffer.cpp:35
BBufferStore(BUInt size=0, int swapBytes=BBigEndian)
Definition: BBuffer.cpp:77
int resize(BUInt32 size)
Alternative to setSize()
Definition: BBuffer.h:37
int push(BInt8 v)
Definition: BBuffer.cpp:129
int writeData(BUInt32 pos, const void *data, BUInt32 size)
Writes data into buffer from offset pos.
Definition: BBuffer.cpp:67
Definition: BError.h:25
BBuffer(BUInt size=0)
Create and manipulate a data buffer. On creation the buffer size defaults to 1024 bytes.
Definition: BBuffer.cpp:16
int8_t BInt8
Definition: BTypes.h:16
Definition: BTimeStamp.h:15
char * odata
Definition: BBuffer.h:40