Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
DynBlock.h
1 /*
2  * $Id$
3  * Copyright (c) 2004, Alfheim Corporation.
4  *
5  * elm/block/DynBlock.h -- interface for DynBlock class.
6  */
7 #ifndef ELM_BLOCK_DYNBLOCK_H
8 #define ELM_BLOCK_DYNBLOCK_H
9 
10 namespace elm { namespace block {
11 
12 // DynBlock class
13 class DynBlock {
14 public:
15  inline DynBlock(int capacity = 256, int increment = 64)
16  : _size(0), cap(capacity), inc(increment), buf(new char[capacity]) { }
17  inline ~DynBlock(void) { if(buf) delete [] buf; }
18  void put(const char *block, int size);
19  void get(char *block, int size, int pos);
20  char *alloc(int size);
21  inline int size(void) const { return _size; }
22  inline int capacity(void) const { return cap; }
23  inline int increment(void) const { return inc; }
24  inline void setSize(int new_size) { _size = new_size; }
25  inline void reset(void) { _size = 0; if(!buf) buf = new char[cap]; }
26  inline const char *base(void) const { return buf; }
27  inline char *detach(void)
28  { char *result = buf; buf = 0; return result; }
29 private:
30  int _size, cap, inc;
31  char *buf;
32  void grow(int min);
33 };
34 
35 } } // elm::block
36 
37 #endif // ELM_BLOCK_DYNBLOCK_H
elm::block::DynBlock::increment
int increment(void) const
Definition: DynBlock.h:23
elm::block::DynBlock::DynBlock
DynBlock(int capacity=256, int increment=64)
Definition: DynBlock.h:15
elm::min
const T & min(const T &x, const T &y)
Definition: compare.h:104
elm::block::DynBlock::~DynBlock
~DynBlock(void)
Definition: DynBlock.h:17
elm::block::DynBlock::alloc
char * alloc(int size)
Definition: block_DynBlock.cpp:139
elm::block::DynBlock::capacity
int capacity(void) const
Definition: DynBlock.h:22
elm::block::DynBlock::put
void put(const char *block, int size)
Definition: block_DynBlock.cpp:57
elm::block::DynBlock::size
int size(void) const
Definition: DynBlock.h:21
elm
Definition: adapter.h:26
elm::block::DynBlock::detach
char * detach(void)
Definition: DynBlock.h:27
elm::block::DynBlock::base
const char * base(void) const
Definition: DynBlock.h:26
elm::block::DynBlock::setSize
void setSize(int new_size)
Definition: DynBlock.h:24
elm::block::DynBlock::get
void get(char *block, int size, int pos)
Definition: block_DynBlock.cpp:77
elm::block::DynBlock::reset
void reset(void)
Definition: DynBlock.h:25
elm::block::DynBlock
Definition: DynBlock.h:13