-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaticCharStream.h
58 lines (40 loc) · 1.04 KB
/
StaticCharStream.h
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
51
52
53
54
55
56
57
58
#ifndef __TELNET_STATICCHARSTREAM__
#define __TELNET_STATICCHARSTREAM__
namespace Telnet {
template <int StreamSize>
class StaticCharStream
{
private:
char buffer[StreamSize];
unsigned int mEndStream;
public:
StaticCharStream<StreamSize> & addChar( char c ) {
if( mEndStream >= StreamSize )
return *this;
buffer[mEndStream++] = c;
return *this;
}
StaticCharStream<StreamSize> & operator << (char c) {
return addChar(c);
}
char getAt(unsigned int index) const {
if( index <= mEndStream && index < StreamSize && index >= 0 )
return buffer[index];
else
return 0;
}
char operator [] ( unsigned int index ) const { return getAt(index); }
void reset() { mEndStream = 0; }
char last() const { return (mEndStream > 0) ? buffer[mEndStream-1] : 0; }
char right(int relative) const {
return ( (mEndStream - relative - 1) < 0 ) ? 0 : buffer[mEndStream - relative - 1];
}
char left( int relative) const {
return getAt(relative);
}
bool full() {
return mEndStream >= StreamSize ? true : false;
}
};
};
#endif