ListMemBuf< T_t, MAX, idx_t > Class Template Reference
Provides some degree of dynamic allocation of a templated type from a buffer of set size.
More...
#include <ListMemBuf.h>
Detailed Description
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
class ListMemBuf< T_t, MAX, idx_t >
Provides some degree of dynamic allocation of a templated type from a buffer of set size.
Think of this as a self-contained mini-malloc...
This is handy for classes which inhabit a shared memory region, where it's a bad idea to have pointers to other memory. By instantiating one of these in your class, you can allocate space internally for up to MAX objects of type T_t. ListMemBuf will worry about keeping track of which ones are in use or are free.
Each time you request a entry to be created, the destructor will be called followed by the the defaul constructor before it is given to you, so the fields should be reliably 'fresh', not what was in the entry last time it was used.
Definition at line 20 of file ListMemBuf.h.
List of all members.
Classes |
struct | entry_t |
| holds data about an entry in the free/used lists More...
|
Public Types |
typedef T_t | T |
| Allows outside access to storage type.
|
typedef idx_t | index_t |
| Allows outside access to index type.
|
Public Member Functions |
| ListMemBuf () |
| constructor
|
| ~ListMemBuf () |
| destructor
|
index_t | size () const |
| returns the current number of objects in use
|
index_t | countf () const |
| for debugging, should equal size
|
index_t | countb () const |
| for debugging, should equal size
|
bool | empty () const |
| returns true if no objects are in use
|
T & | operator[] (unsigned int x) |
| allows direct access to elements - be careful, can access 'free' elements this way
|
const T & | operator[] (unsigned int x) const |
| allows direct access to elements - be careful, can access 'free' elements this way
|
index_t | begin () const |
| returns index of first used entry
|
T & | front () |
| returns reference to first used entry
|
const T & | front () const |
| returns const reference to first used entry
|
index_t | end () const |
| returns the one-past-end index
|
T & | back () |
| returns reference to last used entry
|
const T & | back () const |
| returns const reference to last used entry
|
index_t | new_front () |
| pushes a 'blank' entry on the front of the used list
|
index_t | push_front (const T &data) |
| pushes an entry on the front of the used chain and assigns data to it
|
void | pop_front () |
| pops the front of the used chain
|
void | pop_front (T &ret) |
| pops the front of the chain into ret
|
index_t | new_back () |
| pushes a 'blank' entry on the back of the used list
|
index_t | push_back (const T &data) |
| pushes an entry on the back of the used chain and assigns data to it
|
void | pop_back () |
| pops the last of the used chain
|
void | pop_back (T &ret) |
| pops the last of the used chain into ret
|
index_t | new_before (index_t x) |
| inserts a 'blank' entry before element x in the used chain
|
index_t | push_before (index_t x, const T &data) |
| inserts a 'blank' entry before element x in the used chain and assigns data to it
|
index_t | new_after (index_t x) |
| inserts a 'blank' entry after element x in the used chain
|
index_t | push_after (index_t x, const T &data) |
| inserts a 'blank' entry after element x in the used chain and assigns data to it
|
void | erase (index_t x) |
| removes element x from the used chain
|
void | clear () |
| frees all used entries
|
void | swap (index_t a, index_t b) |
| swaps the two entries' position in the list
|
index_t | next (index_t x) const |
| returns the next used element following x
|
index_t | prev (index_t x) const |
| returns the preceeding used element following x
|
Static Public Member Functions |
static index_t | getMaxCapacity () |
| returns the maximum number of objects which can be used at any given time
|
Static Public Attributes |
static const unsigned int | MAX_ENTRIES = MAX |
| Allows outside access to number of entries.
|
Protected Member Functions |
index_t | pop_free () |
| removes an element from the front of the free list, returns its index
|
void | push_free (index_t x) |
| pushes x onto the back of the free list
|
Protected Attributes |
entry_t | entries [MAX_ENTRIES==0?1:MAX_ENTRIES] |
| the main block of data; must have at least 1 element due to limitation of older compilers
|
index_t | activeBegin |
| beginning of used chain
|
index_t | activeBack |
| end of used chain
|
index_t | freeBegin |
| beginning of free chain
|
index_t | freeBack |
| end of free chain
|
index_t | cursize |
| current number of used elements
|
Member Typedef Documentation
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
Allows outside access to index type.
Definition at line 31 of file ListMemBuf.h.
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
Allows outside access to storage type.
Definition at line 27 of file ListMemBuf.h.
Constructor & Destructor Documentation
template<class T , unsigned int MAX, class index_t >
template<class T , unsigned int MAX, class index_t >
Member Function Documentation
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
returns const reference to last used entry
Definition at line 51 of file ListMemBuf.h.
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
returns index of first used entry
Definition at line 45 of file ListMemBuf.h.
Referenced by RegionRegistry< MAX_REGIONS, NAME_LEN >::begin(), MotionManager::begin(), ListMemBuf< T_t, MAX, idx_t >::countb(), ListMemBuf< T_t, MAX, idx_t >::countf(), MotionManager::doAddMotion(), MotionManager::getOutputs(), SoundManager::lookupPath(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::lookupReceiver(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::markRead(), MotionManager::motionReport(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::oldest(), SemaphoreManager::operator=(), SoundManager::pausePlay(), SoundManager::ProcessMsg(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::readMessage(), MotionManager::RemoveAccess(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), SoundManager::resumePlay(), SoundManager::selectChannels(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), MotionManager::setOutput(), MotionManager::setPID(), SoundManager::stopPlay(), SoundManager::updateChannels(), MotionManager::~MotionManager(), and SoundManager::~SoundManager().
template<class T , unsigned int MAX, class index_t >
template<class T , unsigned int MAX, class index_t >
for debugging, should equal size
Definition at line 124 of file ListMemBuf.h.
template<class T , unsigned int MAX, class index_t >
for debugging, should equal size
Definition at line 115 of file ListMemBuf.h.
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
bool ListMemBuf< T_t, MAX, idx_t >::empty |
( |
|
) |
const |
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
returns the one-past-end index
Definition at line 49 of file ListMemBuf.h.
Referenced by MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReceiver(), ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::countb(), ListMemBuf< T_t, MAX, idx_t >::countf(), MotionManager::doAddMotion(), RegionRegistry< MAX_REGIONS, NAME_LEN >::end(), MotionManager::end(), RegionRegistry< MAX_REGIONS, NAME_LEN >::findRegion(), MotionManager::getOutputs(), SemaphoreManager::getSemaphore(), SemaphoreManager::init(), SemaphoreManager::invalid(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::isEnd(), ListMemBuf< T_t, MAX, idx_t >::ListMemBuf(), SoundManager::lookupPath(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::lookupReceiver(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::markRead(), MotionManager::motionReport(), ListMemBuf< T_t, MAX, idx_t >::new_back(), ListMemBuf< T_t, MAX, idx_t >::new_before(), ListMemBuf< T_t, MAX, idx_t >::new_front(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::newest(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::next(), SemaphoreManager::operator=(), SoundManager::pausePlay(), ListMemBuf< T_t, MAX, idx_t >::pop_back(), ListMemBuf< T_t, MAX, idx_t >::pop_free(), ListMemBuf< T_t, MAX, idx_t >::pop_front(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::prev(), SoundManager::ProcessMsg(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_after(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_back(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_before(), ListMemBuf< T_t, MAX, idx_t >::push_free(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_front(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::readMessage(), MotionManager::RemoveAccess(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), SoundManager::resumePlay(), SoundManager::selectChannels(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), MotionManager::setOutput(), MotionManager::setPID(), MotionManager::skip_ahead(), SoundManager::stopPlay(), ListMemBuf< T_t, MAX, idx_t >::swap(), and SoundManager::updateChannels().
template<class T , unsigned int MAX, class index_t >
removes element x from the used chain
Definition at line 206 of file ListMemBuf.h.
Referenced by SoundManager::endPlay(), RegionRegistry< MAX_REGIONS, NAME_LEN >::erase(), MotionSequenceMC< MAXMOVE >::eraseKeyFrame(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::markRead(), SemaphoreManager::operator=(), SoundManager::pausePlay(), SoundManager::play(), MotionManager::push_free(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::readMessage(), SoundManager::release(), SemaphoreManager::releaseSemaphore(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), MotionManager::setPID(), SoundManager::stopPlay(), and SoundManager::~SoundManager().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
const T& ListMemBuf< T_t, MAX, idx_t >::front |
( |
|
) |
const |
returns const reference to first used entry
Definition at line 47 of file ListMemBuf.h.
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
template<class T , unsigned int MAX, class index_t >
template<class T , unsigned int MAX, class index_t >
template<class T , unsigned int MAX, class index_t >
pushes a 'blank' entry on the front of the used list
Definition at line 133 of file ListMemBuf.h.
Referenced by SoundManager::chain(), SoundManager::chainBuffer(), SoundManager::chainFile(), SemaphoreManager::getSemaphore(), SemaphoreManager::init(), SoundManager::loadBuffer(), ListMemBuf< T_t, MAX, idx_t >::new_before(), MotionSequenceMC< MAXMOVE >::newKeyFrame(), SoundManager::play(), MotionManager::pop_free(), and ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_front().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
returns the next used element following x
Definition at line 74 of file ListMemBuf.h.
Referenced by ListMemBuf< T_t, MAX, idx_t >::countf(), MotionManager::doAddMotion(), MotionManager::getOutputs(), ListMemBuf< T_t, MAX, idx_t >::ListMemBuf(), SoundManager::lookupPath(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::lookupReceiver(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::markRead(), MotionManager::motionReport(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::new_after(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::newer(), RegionRegistry< MAX_REGIONS, NAME_LEN >::next(), MotionManager::next(), SemaphoreManager::operator=(), SoundManager::pausePlay(), SoundManager::ProcessMsg(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::readMessage(), MotionManager::RemoveAccess(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), SoundManager::resumePlay(), SoundManager::selectChannels(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), MotionManager::setPID(), MotionSequenceMC< MAXMOVE >::setRange(), MotionManager::skip_ahead(), ListMemBuf< T_t, MAX, idx_t >::swap(), and SoundManager::updateChannels().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
const T& ListMemBuf< T_t, MAX, idx_t >::operator[] |
( |
unsigned int |
x |
) |
const |
allows direct access to elements - be careful, can access 'free' elements this way
Definition at line 43 of file ListMemBuf.h.
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
T& ListMemBuf< T_t, MAX, idx_t >::operator[] |
( |
unsigned int |
x |
) |
|
allows direct access to elements - be careful, can access 'free' elements this way
Definition at line 42 of file ListMemBuf.h.
Referenced by ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_after(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_back(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_before(), ListMemBuf< T_t, MAX, idx_t >::push_free(), and ListMemBuf< Move, MAXMOVE, Move_idx_t >::push_front().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
void ListMemBuf< T_t, MAX, idx_t >::pop_back |
( |
T & |
ret |
) |
|
template<class T , unsigned int MAX, class index_t >
template<class T , unsigned int MAX, class index_t >
removes an element from the front of the free list, returns its index
free list is a queue... pop front, push back - hopefully more robust with multi-threads is purposely sloppy with unused links, a little faster
Definition at line 319 of file ListMemBuf.h.
Referenced by ListMemBuf< T_t, MAX, idx_t >::new_back(), ListMemBuf< T_t, MAX, idx_t >::new_before(), and ListMemBuf< T_t, MAX, idx_t >::new_front().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
void ListMemBuf< T_t, MAX, idx_t >::pop_front |
( |
T & |
ret |
) |
|
template<class T , unsigned int MAX, class index_t >
pops the front of the used chain
Definition at line 182 of file ListMemBuf.h.
Referenced by SoundManager::chainBuffer(), SoundManager::chainFile(), ListMemBuf< T_t, MAX, idx_t >::erase(), SemaphoreManager::init(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), MotionManager::updatePIDs(), and MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::~MessageQueue().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
returns the preceeding used element following x
Definition at line 75 of file ListMemBuf.h.
Referenced by ListMemBuf< T_t, MAX, idx_t >::countb(), ListMemBuf< T_t, MAX, idx_t >::new_before(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::newest(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::older(), MotionManager::RemoveAccess(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), SoundManager::selectChannels(), MotionSequenceMC< MAXMOVE >::setRange(), SoundManager::stopPlay(), and ListMemBuf< T_t, MAX, idx_t >::swap().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
inserts a 'blank' entry after element x in the used chain and assigns data to it
Definition at line 67 of file ListMemBuf.h.
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
pushes an entry on the back of the used chain and assigns data to it
Definition at line 59 of file ListMemBuf.h.
Referenced by MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReceiver(), RegionRegistry< MAX_REGIONS, NAME_LEN >::registerRegion(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), and MotionManager::setPID().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
inserts a 'blank' entry before element x in the used chain and assigns data to it
Definition at line 64 of file ListMemBuf.h.
template<class T , unsigned int MAX, class index_t >
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
returns the current number of objects in use
Definition at line 34 of file ListMemBuf.h.
Referenced by SemaphoreManager::available(), SoundManager::CopyTo(), MotionSequenceMC< MAXMOVE >::getUsedFrames(), MotionManager::InitAccess(), MotionManager::motionReport(), SoundManager::playBuffer(), SoundManager::playFile(), SoundManager::resumePlay(), SoundManager::selectChannels(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), MotionManager::size(), and SemaphoreManager::used().
template<class T , unsigned int MAX, class index_t >
Member Data Documentation
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
end of used chain
Definition at line 91 of file ListMemBuf.h.
Referenced by ListMemBuf< Move, MAXMOVE, Move_idx_t >::back(), ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::erase(), ListMemBuf< T_t, MAX, idx_t >::new_back(), ListMemBuf< T_t, MAX, idx_t >::new_front(), ListMemBuf< T_t, MAX, idx_t >::pop_back(), ListMemBuf< T_t, MAX, idx_t >::pop_front(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::prev(), and ListMemBuf< T_t, MAX, idx_t >::swap().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
beginning of used chain
Definition at line 90 of file ListMemBuf.h.
Referenced by ListMemBuf< Move, MAXMOVE, Move_idx_t >::begin(), ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::erase(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::front(), ListMemBuf< T_t, MAX, idx_t >::new_back(), ListMemBuf< T_t, MAX, idx_t >::new_front(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::next(), ListMemBuf< T_t, MAX, idx_t >::pop_back(), ListMemBuf< T_t, MAX, idx_t >::pop_front(), and ListMemBuf< T_t, MAX, idx_t >::swap().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
current number of used elements
Definition at line 94 of file ListMemBuf.h.
Referenced by ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::empty(), ListMemBuf< T_t, MAX, idx_t >::pop_free(), ListMemBuf< T_t, MAX, idx_t >::push_free(), and ListMemBuf< Move, MAXMOVE, Move_idx_t >::size().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
the main block of data; must have at least 1 element due to limitation of older compilers
Definition at line 89 of file ListMemBuf.h.
Referenced by ListMemBuf< Move, MAXMOVE, Move_idx_t >::back(), ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::erase(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::front(), ListMemBuf< T_t, MAX, idx_t >::ListMemBuf(), ListMemBuf< T_t, MAX, idx_t >::new_back(), ListMemBuf< T_t, MAX, idx_t >::new_before(), ListMemBuf< T_t, MAX, idx_t >::new_front(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::next(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::operator[](), ListMemBuf< T_t, MAX, idx_t >::pop_back(), ListMemBuf< T_t, MAX, idx_t >::pop_free(), ListMemBuf< T_t, MAX, idx_t >::pop_front(), ListMemBuf< Move, MAXMOVE, Move_idx_t >::prev(), ListMemBuf< T_t, MAX, idx_t >::push_free(), and ListMemBuf< T_t, MAX, idx_t >::swap().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
end of free chain
Definition at line 93 of file ListMemBuf.h.
Referenced by ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::ListMemBuf(), ListMemBuf< T_t, MAX, idx_t >::pop_free(), and ListMemBuf< T_t, MAX, idx_t >::push_free().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
beginning of free chain
Definition at line 92 of file ListMemBuf.h.
Referenced by ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::ListMemBuf(), ListMemBuf< T_t, MAX, idx_t >::pop_free(), and ListMemBuf< T_t, MAX, idx_t >::push_free().
template<class T_t, unsigned int MAX, class idx_t = unsigned short>
The documentation for this class was generated from the following file:
|