15 #include "croflexception.h"
47 static std::set<cmemory*> cmemory_list;
48 static pthread_mutex_t memlock;
49 static int memlockcnt;
51 std::pair<uint8_t*, size_t> data;
53 #define CMEMORY_DEFAULT_SIZE 0
66 size_t len = CMEMORY_DEFAULT_SIZE);
244 length()
const {
return data.second; };
397 operator<< (std::ostream& os,
cmemory const& mem) {
398 os <<
indent(0) <<
"<cmemory: ";
399 os <<
"data:" << (
void*)mem.data.first <<
" ";
400 os <<
"datalen:" << (
int)mem.data.second <<
" ";
401 os <<
">" << std::endl;
403 unsigned int const width = 32;
405 if (mem.data.second > 0) {
406 for (
unsigned int i=0; i < mem.data.second; i++) {
407 if (0 == (i % width)) {
411 << std::dec << (i/width) <<
": " << std::hex
413 << std::setfill(
' ');
416 os << std::setfill(
'0')
418 << std::hex << (int)(*(mem.
somem() + i)) << std::dec
423 if (0 == ((i+1) % 8))
425 if (0 == ((i+1) % width))
virtual std::string toString() const
map onto std::string instance
Definition: cmemory.cc:314
virtual void pack(uint8_t *buf, size_t buflen)
Copies content of this cmemory instance to specified buffer.
Definition: cmemory.cc:292
size_t memlen() const
Returns length of allocated memory area.
Definition: cmemory.cc:109
cmemory & operator+=(cmemory const &m)
Append operator with assignment to this cmemory instance.
Definition: cmemory.cc:193
bool operator!=(cmemory const &m) const
Comparison operator (unequal).
Definition: cmemory.cc:232
uint8_t * somem() const
Returns pointer to start of allocated memory area.
Definition: cmemory.cc:101
bool operator==(cmemory const &m) const
Comparison operator.
Definition: cmemory.cc:219
bool operator<(cmemory const &m) const
Less than operator.
Definition: cmemory.cc:129
cmemory operator+(cmemory const &m)
Append operator with assignment to temporary cmemory instance.
Definition: cmemory.cc:207
virtual ~cmemory()
Destructor. Calls C-function free() for allocated memory area.
Definition: cmemory.cc:69
virtual uint8_t * resize(size_t len)
Resizes allocated memory area by calling C-function realloc().
Definition: cmemory.cc:253
cmemory operator&(cmemory const &m) const
AND operator.
Definition: cmemory.cc:175
uint8_t & operator[](size_t index) const
Index operator.
Definition: cmemory.cc:117
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
bool operator>(cmemory const &m) const
Less than operator.
Definition: cmemory.cc:152
cmemory & operator=(cmemory const &m)
Assignment operator.
Definition: cmemory.cc:85
virtual void assign(uint8_t *buf, size_t buflen)
Overwrites memory area with plain buffer specified. Resizes internal memory as necessary.
Definition: cmemory.cc:241
cmemory(size_t len=CMEMORY_DEFAULT_SIZE)
Constructor. Allocates a new memory area with specified size (default: 1024 bytes).
Definition: cmemory.cc:13
uint8_t * insert(uint8_t *ptr, size_t len)
Inserts len bytes at pointer ptr into allocated memory area.
Definition: cmemory.cc:354
virtual bool empty() const
Returns boolean value empty/non empty.
Definition: cmemory.h:372
unsigned int find_first_of(uint8_t value, unsigned int start)
Returns index of first byte with value "value" found in allocated memory area starting at offset "sta...
Definition: cmemory.cc:437
Definition: croflexception.h:27
virtual void unpack(uint8_t *buf, size_t buflen)
Copies content of specified buffer into this cmemory instance .
Definition: cmemory.cc:304
void clear()
Clears the allocated memory area by setting all bytes to 0.
Definition: cmemory.cc:281