DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dueca::AmorphStore Class Reference

Amorphous storage object of variable size. More...

#include <AmorphStore.hxx>

Public Member Functions

 AmorphStore ()
 Constructor for an un-initialised store, has no memory.
 
 AmorphStore (char *store, unsigned capacity)
 Constructor for an initial store, with memory borrowed somewhere else.
 
 ~AmorphStore ()
 Destructor.
 
void acceptBuffer (char *store, unsigned capacity)
 initialise a store with borrowed memory.
 
void renewBuffer (unsigned capacity)
 re-initialise the store's memory.
 
const chargetToData () const
 access to the data of the store.
 
void startMark ()
 Ask for a mark, a 2-byte (uint16_t) number that contains the size of the data up to the end mark.
 
template<class T >
StoreMark< TcreateMark (T dum)
 Ask for a mark, a 2-byte (uint16_t) number that contains the size of the data or the number of data items up to the end mark.
 
template<class T >
unsigned finishMark (const StoreMark< T > &m)
 Finish the mark, this codes the size of the packed data since the mark.
 
template<class T >
void finishMark (const StoreMark< T > &m, T n)
 Finish the mark, this codes the number supplied to the call.
 
void endMark ()
 Call this after packing all data after the startMark() call.
 
void startBigMark ()
 Ask for a big mark, a 4-byte (uint32_t) number that contains the size of the data up to the end mark.
 
void endBigMark ()
 Call this after packing all data after the startBigMark() call.
 
const unsigned getSize () const
 query the current size of the stored data.
 
unsigned roundSize4 ()
 round off the size of the store to a multiple of four, necessary for word-wide communications hardware.
 
void setSize (unsigned p_index)
 Modify the current size of the stored data.
 
void reUse ()
 Reuse the store, meaning to flush it completely and start packing new data.
 
void reUse (unsigned capacity)
 Reuse the store, meaning to flush it completely and start packing new data.
 
bool isChoked () const
 If this returns true, there is no more room in the store.
 
void setChoked ()
 Flag the store as choked, i.e.
 
bool checkForRoom (const unsigned size) const
 Check for room in the store.
 
void packData (const float &f)
 Pack a float into the store.
 
void packData (const double &d)
 Pack a double into the store.
 
void packData (const char &i)
 Pack a char into the store.
 
void packData (const int8_t &i)
 Pack an int8_t into the store.
 
void packData (const int16_t &i)
 Pack an int16_t into the store.
 
void packData (const int32_t &i)
 Pack an int32_t into the store.
 
void packData (const int64_t &i)
 Pack an int64_t into the store.
 
void packData (const uint8_t &i)
 Pack an uint8_t into the store.
 
void packData (const uint16_t &i)
 Pack an uint16_t into the store.
 
void packData (const uint32_t &i)
 Pack an uint32_t into the store.
 
void placeData (const uint8_t &i, unsigned index2)
 Pack an uint8_t into the store at a specific spot; only for specialty work!
 
void placeData (const uint16_t &i, unsigned index2)
 Pack an uint16_t into the store.
 
void placeData (const uint32_t &i, unsigned index2)
 Pack an uint32_t into the store.
 
void packData (const uint64_t &i)
 Pack an uint64_t into the store.
 
void packData (const bool &b)
 Pack a bool into the store, fits in a byte.
 
void packData (const vstring &t)
 Pack a string of variable length into the store.
 
void packData (const char *c)
 Pack a 0-terminated c-string into the store.
 
void packData (const char *c, const unsigned length)
 Pack a string of certain known length into the store.
 
ostreamprint (ostream &o) const
 Print to stream, just for debugging purposed.
 

Detailed Description

Amorphous storage object of variable size.

The data from this object can be transported and unpacked again, using an AmorphReStore object. This is commonly used for network communication within DUECA. One application-level use is common, in combination with Snapshot handling.

Constructor & Destructor Documentation

◆ AmorphStore() [1/2]

dueca::AmorphStore::AmorphStore ( )

Constructor for an un-initialised store, has no memory.

Use acceptBuffer or renewBuffer to supply memory to this store.

◆ AmorphStore() [2/2]

dueca::AmorphStore::AmorphStore ( char * store,
unsigned capacity )

Constructor for an initial store, with memory borrowed somewhere else.

This may be used to pack data in a buffer that is already present.

Parameters
storeArray for the data.
capacityMaximum capacity of the storage.

Member Function Documentation

◆ acceptBuffer()

void dueca::AmorphStore::acceptBuffer ( char * store,
unsigned capacity )

initialise a store with borrowed memory.

Parameters
storeArray for the data.
capacityMaximum capacity of the storage.

◆ renewBuffer()

void dueca::AmorphStore::renewBuffer ( unsigned capacity)

re-initialise the store's memory.

Note that this operation can be quite wasteful, it frees the memory previously allocated (if any, and if self-allocated), and allocates new memory.

Parameters
capacityMaximum capacity of the storage.

◆ getToData()

const char * dueca::AmorphStore::getToData ( ) const
inline

access to the data of the store.

Returns
A pointer to the data buffer.

◆ createMark()

template<class T >
StoreMark< T > dueca::AmorphStore::createMark ( T dum)
inline

Ask for a mark, a 2-byte (uint16_t) number that contains the size of the data or the number of data items up to the end mark.

Exceptions
AmorphStoreBoundarywhen no room.

◆ finishMark() [1/2]

template<class T >
unsigned dueca::AmorphStore::finishMark ( const StoreMark< T > & m)
inline

Finish the mark, this codes the size of the packed data since the mark.

Parameters
mStoreMark, created with createMark
Exceptions
MarkRangewhen mark too big for coded size

◆ finishMark() [2/2]

template<class T >
void dueca::AmorphStore::finishMark ( const StoreMark< T > & m,
T n )
inline

Finish the mark, this codes the number supplied to the call.

Parameters
mStoreMark, created with createMark
nValue to be stored

◆ endMark()

void dueca::AmorphStore::endMark ( )

Call this after packing all data after the startMark() call.

It writes the size of the data packed after the startMark call into the mark location.

◆ startBigMark()

void dueca::AmorphStore::startBigMark ( )

Ask for a big mark, a 4-byte (uint32_t) number that contains the size of the data up to the end mark.

Exceptions
AmorphStoreBoundarywhen no room.

◆ endBigMark()

void dueca::AmorphStore::endBigMark ( )

Call this after packing all data after the startBigMark() call.

It writes the size of the data packed after the startBigMark call into the mark location.

◆ getSize()

const unsigned dueca::AmorphStore::getSize ( ) const
inline

query the current size of the stored data.

Returns
Number of bytes currently packed.

◆ roundSize4()

unsigned dueca::AmorphStore::roundSize4 ( )
inline

round off the size of the store to a multiple of four, necessary for word-wide communications hardware.

Returns
Number of bytes packed, rounded off to multiple of 4.

◆ setSize()

void dueca::AmorphStore::setSize ( unsigned p_index)
inline

Modify the current size of the stored data.

Use this with extreme care, if you must.

Parameters
p_indexNew size of the packed data.

◆ reUse()

void dueca::AmorphStore::reUse ( unsigned capacity)
inline

Reuse the store, meaning to flush it completely and start packing new data.

Parameters
capacityIf non-zero, indicates the new capacity of the buffer. Use with care, you are responsible for ensuring enough buffer size.

◆ isChoked()

bool dueca::AmorphStore::isChoked ( ) const
inline

If this returns true, there is no more room in the store.

Returns
True if the store is full.

◆ setChoked()

void dueca::AmorphStore::setChoked ( )
inline

Flag the store as choked, i.e.

don't pack anything in it anymore.

◆ checkForRoom()

bool dueca::AmorphStore::checkForRoom ( const unsigned size) const
inline

Check for room in the store.

Returns
True if the requested number of bytes can still be packed.

◆ packData()

void dueca::AmorphStore::packData ( const char * c,
const unsigned length )

Pack a string of certain known length into the store.

It is your own responsibility to know the length when unpacking it again.


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