My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
LibThread::ByteBuf Class Reference

#include <bytebuf.h>

Public Member Functions

 ByteBuf ()
 
 ByteBuf (const ByteBuf &other)
 
ByteBufoperator= (const ByteBuf &other)
 
 ~ByteBuf ()
 
size_t size ()
 
void write_bytes (char *p, size_t n)
 
void read_bytes (char *p, size_t n)
 
template<typename T >
void write (T &value)
 
template<typename T >
void read (T &value)
 
void seek (size_t p)
 

Private Attributes

size_t count
 
size_t cap
 
size_t pos
 
char * buf
 

Detailed Description

Definition at line 15 of file bytebuf.h.

Constructor & Destructor Documentation

◆ ByteBuf() [1/2]

LibThread::ByteBuf::ByteBuf ( )
inline

Definition at line 22 of file bytebuf.h.

22: pos(0), count(0), cap(0) { }

◆ ByteBuf() [2/2]

LibThread::ByteBuf::ByteBuf ( const ByteBuf other)
inline

Definition at line 23 of file bytebuf.h.

23 :
24 count(other.count), cap(other.cap), pos(0)
25 {
27 memcpy(buf, other.buf, count);
28 }
char * allocate_space(size_t n)

◆ ~ByteBuf()

LibThread::ByteBuf::~ByteBuf ( )
inline

Definition at line 37 of file bytebuf.h.

37 {
39 }
void free_space(size_t n, char *p)

Member Function Documentation

◆ operator=()

ByteBuf & LibThread::ByteBuf::operator= ( const ByteBuf other)
inline

Definition at line 29 of file bytebuf.h.

29 {
30 count = other.count;
31 cap = other.cap;
32 pos = 0;
34 memcpy(buf, other.buf, count);
35 return *this;
36 }

◆ read()

template<typename T >
void LibThread::ByteBuf::read ( T value)
inline

Definition at line 62 of file bytebuf.h.

62 {
63 read_bytes((char *)&value, sizeof(T));
64 }
void read_bytes(char *p, size_t n)
Definition: bytebuf.h:53
STATIC_VAR jList * T
Definition: janet.cc:30

◆ read_bytes()

void LibThread::ByteBuf::read_bytes ( char *  p,
size_t  n 
)
inline

Definition at line 53 of file bytebuf.h.

53 {
54 memcpy(p, buf+pos, n);
55 pos += n;
56 }
int p
Definition: cfModGcd.cc:4078

◆ seek()

void LibThread::ByteBuf::seek ( size_t  p)
inline

Definition at line 65 of file bytebuf.h.

65 {
66 pos = p;
67 }

◆ size()

size_t LibThread::ByteBuf::size ( )
inline

Definition at line 40 of file bytebuf.h.

40{ return count; }

◆ write()

template<typename T >
void LibThread::ByteBuf::write ( T value)
inline

Definition at line 58 of file bytebuf.h.

58 {
59 write_bytes((char *)&value, sizeof(T));
60 }
void write_bytes(char *p, size_t n)
Definition: bytebuf.h:41

◆ write_bytes()

void LibThread::ByteBuf::write_bytes ( char *  p,
size_t  n 
)
inline

Definition at line 41 of file bytebuf.h.

41 {
42 if (pos + n >= cap) {
43 char *newbuf = allocate_space(2 * cap);
44 memcpy(newbuf, buf, count);
46 cap *= 2;
47 }
48 memcpy(buf+pos, p, n);
49 pos += n;
50 if (pos >= count)
51 count = pos;
52 }

Field Documentation

◆ buf

char* LibThread::ByteBuf::buf
private

Definition at line 20 of file bytebuf.h.

◆ cap

size_t LibThread::ByteBuf::cap
private

Definition at line 18 of file bytebuf.h.

◆ count

size_t LibThread::ByteBuf::count
private

Definition at line 17 of file bytebuf.h.

◆ pos

size_t LibThread::ByteBuf::pos
private

Definition at line 19 of file bytebuf.h.


The documentation for this class was generated from the following file: