11 #ifndef __TEXTWOLF_STATIC_BUFFER_HPP__
12 #define __TEXTWOLF_STATIC_BUFFER_HPP__
29 :m_pos(0),m_size(n),m_ar(0),m_allocated(true),m_overflow(false)
31 m_ar = (
char*)std::calloc( n,
sizeof(
char));
32 if (!m_ar)
throw std::bad_alloc();
48 ,m_allocated(o.m_allocated)
49 ,m_overflow(o.m_overflow)
51 m_ar = (
char*)std::malloc( m_size *
sizeof(
char));
52 if (!m_ar)
throw std::bad_alloc();
53 std::memcpy( m_ar, o.m_ar, m_size);
59 if (m_allocated && m_ar) std::free(m_ar);
86 void append(
const char* cc, std::size_t ccsize)
88 if (m_pos+ccsize > m_size)
91 ccsize = m_size - m_pos;
93 std::memcpy( m_ar+m_pos, cc, ccsize);
99 std::size_t
size()
const {
return m_pos;}
103 const char*
ptr()
const {
return m_ar;}
116 if (m_size<n) n=m_size;
133 char&
at( std::size_t ii)
const
StaticBuffer(std::size_t n)
Constructor.
Definition: staticbuffer.hpp:28
std::size_t size() const
Return the number of characters in the buffer.
Definition: staticbuffer.hpp:99
char operator[](std::size_t ii) const
random access of element
Definition: staticbuffer.hpp:124
Base class for structures that can throw exceptions for non recoverable errors.
Definition: exception.hpp:20
~StaticBuffer()
Destructor.
Definition: staticbuffer.hpp:57
StaticBuffer(const StaticBuffer &o)
Copy constructor.
Definition: staticbuffer.hpp:44
const char * ptr() const
Return the buffer content as 0-terminated string.
Definition: staticbuffer.hpp:103
Simple back insertion sequence for storing the outputs of textwolf in a contant size buffer...
Definition: staticbuffer.hpp:24
textwolf exception class
Definition: exception.hpp:48
StaticBuffer(char *p, std::size_t n, std::size_t i=0)
Constructor.
Definition: staticbuffer.hpp:36
void resize(std::size_t n, char c=0)
Shrinks the size of the buffer or expands it with c.
Definition: staticbuffer.hpp:108
void clear()
Clear the buffer content.
Definition: staticbuffer.hpp:63
bool overflow() const
check for array bounds write
Definition: staticbuffer.hpp:141
memory reserved for statically allocated table or memory block is too small. Increase the size of mem...
Definition: exception.hpp:27
Definition of exceptions with containing error codes thrown by textwolf.
char & at(std::size_t ii) const
random access of element reference
Definition: staticbuffer.hpp:133
void append(const char *cc, std::size_t ccsize)
Append an array of characters.
Definition: staticbuffer.hpp:86
void push_back(char ch)
Append one character.
Definition: staticbuffer.hpp:71