Loading...
Searching...
No Matches
LibThread::ByteBuf Class Reference

`#include <bytebuf.h>`

## Public Member Functions

| ByteBuf ()
| ByteBuf (const ByteBuf &other)
ByteBuf & | operator= (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.

: pos(0), count(0), cap(0) { }
LibThread::ByteBuf::pos
size_t pos
Definition bytebuf.h:19
LibThread::ByteBuf::count
size_t count
Definition bytebuf.h:17
LibThread::ByteBuf::cap
size_t cap
Definition bytebuf.h:18

## ByteBuf() [2/2]

LibThread::ByteBuf::ByteBuf | ( | const ByteBuf & | other | ) |

inline

Definition at line 23 of file bytebuf.h.

:
count(other.count), cap(other.cap), pos(0)
{
buf = allocate_space(cap);
memcpy(buf, other.buf, count);
}
LibThread::ByteBuf::buf
char * buf
Definition bytebuf.h:20
LibThread::allocate_space
char * allocate_space(size_t n)

## ~ByteBuf()

LibThread::ByteBuf::~ByteBuf | ( |  | ) |

inline

Definition at line 37 of file bytebuf.h.

{
free_space(cap, buf);
}
LibThread::free_space
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.

{
count = other.count;
cap = other.cap;
pos = 0;
buf = allocate_space(cap);
memcpy(buf, other.buf, count);
return *this;
}

## read()

template<typename T>

void LibThread::ByteBuf::read | ( | T & | value | ) |

inline

Definition at line 62 of file bytebuf.h.

{
read_bytes((char *)&value, sizeof(T));
}
LibThread::ByteBuf::read_bytes
void read_bytes(char *p, size_t n)
Definition bytebuf.h:53
T
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.

{
memcpy(p, buf+pos, n);
pos += n;
}
p
int p
Definition cfModGcd.cc:4086

## seek()

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

inline

Definition at line 65 of file bytebuf.h.

{
pos = p;
}

## size()

size_t LibThread::ByteBuf::size | ( |  | ) |

inline

Definition at line 40 of file bytebuf.h.

{ return count; }

## write()

template<typename T>

void LibThread::ByteBuf::write | ( | T & | value | ) |

inline

Definition at line 58 of file bytebuf.h.

{
write_bytes((char *)&value, sizeof(T));
}
LibThread::ByteBuf::write_bytes
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.

{
if (pos + n >= cap) {
char *newbuf = allocate_space(2 * cap);
memcpy(newbuf, buf, count);
free_space(cap, buf);
cap *= 2;
}
memcpy(buf+pos, p, n);
pos += n;
if (pos >= count)
count = pos;
}

## 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:

- Singular/dyn_modules/systhreads/bytebuf.h