8#include "daq/slc/system/BufferedReader.h"
10#include <daq/slc/base/IOException.h>
16BufferedReader::BufferedReader()
17 : m_memory(NULL), m_size(0), m_pos(0), m_allocated(false) {}
20 : m_memory(NULL), m_size(reader.m_size),
21 m_pos(reader.m_pos), m_allocated(reader.m_allocated)
24 m_memory =
new unsigned char [reader.m_size];
25 ::memcpy(m_memory, reader.m_memory, reader.m_size);
27 m_memory = reader.m_memory;
29 m_size = reader.m_size;
33BufferedReader::BufferedReader(
size_t size,
unsigned char* memory)
34 : m_memory(memory), m_size(size), m_pos(0), m_allocated(false)
37 m_memory =
new unsigned char[size];
42BufferedReader::~BufferedReader()
44 if (m_allocated && m_memory != NULL) {
54 m_allocated = reader.m_allocated;
56 m_memory =
new unsigned char [reader.m_size];
57 ::memcpy(m_memory, reader.m_memory, reader.m_size);
59 m_memory = reader.m_memory;
61 m_size = reader.m_size;
66void BufferedReader::copy(
const void* buffer,
size_t count)
69 memcpy(m_memory, buffer, count);
73 (
int)count, (
int)m_size));
77size_t BufferedReader::read(
void* buf,
const size_t count)
79 if (m_pos + count > size()) {
80 throw (
IOException(
"Out of buffer range: %d + %d > %d",
81 (
int)m_pos, (
int)count, (
int)m_size));
83 memcpy(buf, (m_memory + m_pos), count);
Abstract base class for different kinds of events.