Last change
on this file since 1722 was
1675,
checked in by rgrieder, 16 years ago
|
Please always set svn property eol-style to 'native'. That avoids problems with line endings on different platforms.
|
-
Property svn:eol-style set to
native
|
File size:
1.4 KB
|
Line | |
---|
1 | #include "Bytestream.h" |
---|
2 | #include <assert.h> |
---|
3 | |
---|
4 | #define DEFAULT_SIZE 100 // bytes |
---|
5 | #define RESIZE_AMOUNT 100 |
---|
6 | |
---|
7 | Bytestream::Bytestream(){ |
---|
8 | data_ = new DATA_TYPE[DEFAULT_SIZE+1]; |
---|
9 | readIterator_ = 0; |
---|
10 | writeIterator_ = 0; |
---|
11 | maxSize_ = DEFAULT_SIZE; |
---|
12 | } |
---|
13 | |
---|
14 | Bytestream::Bytestream( unsigned int size ){ |
---|
15 | data_ = new DATA_TYPE[ size+1 ]; |
---|
16 | readIterator_ = 0; |
---|
17 | writeIterator_ = 0; |
---|
18 | maxSize_ = size; |
---|
19 | } |
---|
20 | |
---|
21 | Bytestream::Bytestream( DATA_TYPE *data, unsigned int size, bool empty ){ |
---|
22 | data_ = data; |
---|
23 | if(empty) |
---|
24 | writeIterator_ = 0; |
---|
25 | else |
---|
26 | writeIterator_ = size; |
---|
27 | readIterator_ = 0; |
---|
28 | maxSize_ = size; |
---|
29 | } |
---|
30 | |
---|
31 | Bytestream::~Bytestream(){ |
---|
32 | delete [] data_; |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | void Bytestream::write( void *data, unsigned int length ){ |
---|
37 | if(writeIterator_+length > maxSize_){ |
---|
38 | maxSize_ += RESIZE_AMOUNT; |
---|
39 | data_ = (DATA_TYPE* )realloc(data_, maxSize_); |
---|
40 | } |
---|
41 | memcpy( &data_[writeIterator_], &data, length ); |
---|
42 | writeIterator_+= length; |
---|
43 | } |
---|
44 | |
---|
45 | void Bytestream::read( void *data, unsigned int length ){ |
---|
46 | assert(readIterator_+length <= maxSize_); |
---|
47 | memcpy( &data, &data_[readIterator_], length ); |
---|
48 | readIterator_ += length; |
---|
49 | assert(readIterator_<=maxSize_); |
---|
50 | } |
---|
51 | |
---|
52 | void Bytestream::readString(std::string& s){ |
---|
53 | void readString(std::string& s); |
---|
54 | readIterator_ += s.length()+1; |
---|
55 | assert(readIterator_<=maxSize_); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
Note: See
TracBrowser
for help on using the repository browser.