aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bufferstore.h
blob: 4840689960b69294a29e230efc7e800b80b48338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef _bufferstore_h
#define _bufferstore_h

#include "bool.h"
class ostream;

class bufferStore {
public:
  bufferStore();
  bufferStore(const unsigned char*buff, long len);
  ~bufferStore();
  bufferStore(const bufferStore &a);
  void operator =(const bufferStore &a);

  // Reading Utils
  unsigned long getLen() const;
  unsigned char getByte(long pos) const;
  unsigned int getWord(long pos) const;
  unsigned int getDWord(long pos) const;
  const char* getString(long pos=0) const;
  void discardFirstBytes(int n);
  friend ostream &operator<<(ostream &s, const bufferStore &m);
  bool empty() const;

  // Writing utils
  void init();
  void init(const unsigned char*buff, long len);
  void addByte(unsigned char c);
  void addWord(int a);
  void addDWord(long a);
  void addString(const char* s);
  void addStringT(const char* s);
  void addBuff(const bufferStore &s, long maxLen=-1);
  
private:
  void checkAllocd(long newLen);

  long len;
  long lenAllocd;
  long start;
  unsigned char* buff;

  enum c { MIN_LEN = 300 };
};

inline bool bufferStore::empty() const {
  return (len-start) == 0;
}

#endif