Homepage Demos Overview Downloads Tutorials Reference
Credits

ListMemBuf< T_t, MAX, idx_t > Class Template Reference

#include <ListMemBuf.h>

Inheritance diagram for ListMemBuf< T_t, MAX, idx_t >:

Inheritance graph
[legend]
List of all members.

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.

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
index_t getMaxCapacity () const
 returns the maximum number of objects which can be used at any given time
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
Toperator[] (unsigned int x)
 allows direct access to elements - be careful, can access 'free' elements this way
const Toperator[] (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
Tfront ()
 returns reference to first used entry
const Tfront () const
 returns const reference to first used entry
index_t end () const
 returns the one-past-end index
Tback ()
 returns reference to last used entry
const Tback () 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 Attributes

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]
 the main block of data
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>
typedef idx_t ListMemBuf< T_t, MAX, idx_t >::index_t
 

Allows outside access to index type.

Definition at line 30 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::countb(), ListMemBuf< T_t, MAX, idx_t >::countf(), ListMemBuf< T_t, MAX, idx_t >::erase(), 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< T_t, MAX, idx_t >::pop_back(), ListMemBuf< T_t, MAX, idx_t >::pop_free(), ListMemBuf< T_t, MAX, idx_t >::pop_front(), 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>
typedef T_t ListMemBuf< T_t, MAX, idx_t >::T
 

Allows outside access to storage type.

Definition at line 26 of file ListMemBuf.h.


Constructor & Destructor Documentation

template<class T, unsigned int MAX, class index_t>
ListMemBuf< T, MAX, index_t >::ListMemBuf  ) 
 

constructor

Definition at line 94 of file ListMemBuf.h.


Member Function Documentation

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
const T& ListMemBuf< T_t, MAX, idx_t >::back  )  const [inline]
 

returns const reference to last used entry

Definition at line 47 of file ListMemBuf.h.

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
T& ListMemBuf< T_t, MAX, idx_t >::back  )  [inline]
 

returns reference to last used entry

Definition at line 46 of file ListMemBuf.h.

Referenced by MotionSequenceMC< MAXMOVE >::clear(), WaypointEngine< MAX_WAY >::fixArc(), WaypointEngine< MAX_WAY >::LoadBuffer(), and SoundManager::selectChannels().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::begin  )  const [inline]
 

returns index of first used entry

Definition at line 41 of file ListMemBuf.h.

Referenced by WaypointEngine< MAX_WAY >::calcAbsoluteCoords(), ListMemBuf< T_t, MAX, idx_t >::countb(), ListMemBuf< T_t, MAX, idx_t >::countf(), MotionManager::getOutputs(), WaypointEngine< MAX_WAY >::go(), SoundManager::lookupPath(), SoundManager::PausePlay(), SoundManager::ReceivedMsg(), SoundManager::ResumePlay(), WaypointEngine< MAX_WAY >::SaveBuffer(), SoundManager::selectChannels(), MotionManager::setOutput(), MotionManager::setPID(), WaypointEngine< MAX_WAY >::setTargetWaypoint(), SoundManager::StopPlay(), and SoundManager::updateChannels().

template<class T, unsigned int MAX, class index_t>
void ListMemBuf< T, MAX, index_t >::clear  ) 
 

frees all used entries

Definition at line 210 of file ListMemBuf.h.

Referenced by MotionSequenceMC< MAXMOVE >::clear(), MotionManager::getOutputs(), and WaypointEngine< MAX_WAY >::LoadBuffer().

template<class T, unsigned int MAX, class index_t>
index_t ListMemBuf< T, MAX, index_t >::countb  )  const
 

for debugging, should equal size

Definition at line 112 of file ListMemBuf.h.

template<class T, unsigned int MAX, class index_t>
index_t ListMemBuf< T, MAX, index_t >::countf  )  const
 

for debugging, should equal size

Definition at line 103 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 [inline]
 

returns true if no objects are in use

Definition at line 36 of file ListMemBuf.h.

Referenced by SoundManager::StopPlay(), and MotionManager::updatePIDs().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::end  )  const [inline]
 

returns the one-past-end index

Definition at line 45 of file ListMemBuf.h.

Referenced by WaypointEngine< MAX_WAY >::calcAbsoluteCoords(), ListMemBuf< T_t, MAX, idx_t >::clear(), ListMemBuf< T_t, MAX, idx_t >::countb(), ListMemBuf< T_t, MAX, idx_t >::countf(), WaypointEngine< MAX_WAY >::cycle(), MotionManager::doAddMotion(), WaypointEngine< MAX_WAY >::fixArc(), MotionManager::getOutputs(), SoundManager::lookupPath(), ListMemBuf< T_t, MAX, idx_t >::new_back(), ListMemBuf< T_t, MAX, idx_t >::new_before(), ListMemBuf< T_t, MAX, idx_t >::new_front(), 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< T_t, MAX, idx_t >::push_free(), SoundManager::ReceivedMsg(), SoundManager::ResumePlay(), WaypointEngine< MAX_WAY >::SaveBuffer(), SoundManager::selectChannels(), MotionManager::setOutput(), MotionManager::setPID(), WaypointEngine< MAX_WAY >::setTargetWaypoint(), MotionManager::skip_ahead(), SoundManager::StopPlay(), ListMemBuf< T_t, MAX, idx_t >::swap(), WaypointEngine< MAX_WAY >::unpause(), and SoundManager::updateChannels().

template<class T, unsigned int MAX, class index_t>
void ListMemBuf< T, MAX, index_t >::erase index_t  x  ) 
 

removes element x from the used chain

Definition at line 194 of file ListMemBuf.h.

Referenced by SoundManager::endPlay(), MotionSequenceMC< MAXMOVE >::eraseKeyFrame(), SoundManager::PausePlay(), MotionManager::push_free(), SoundManager::Release(), MotionManager::setPID(), and SoundManager::StopPlay().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
const T& ListMemBuf< T_t, MAX, idx_t >::front  )  const [inline]
 

returns const reference to first used entry

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 >::front  )  [inline]
 

returns reference to first used entry

Definition at line 42 of file ListMemBuf.h.

Referenced by WaypointEngine< MAX_WAY >::go(), WaypointEngine< MAX_WAY >::SaveBuffer(), and MotionManager::updatePIDs().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::getMaxCapacity  )  const [inline]
 

returns the maximum number of objects which can be used at any given time

Definition at line 32 of file ListMemBuf.h.

Referenced by MotionSequenceMC< MAXMOVE >::getMaxFrames().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::new_after index_t  x  )  [inline]
 

inserts a 'blank' entry after element x in the used chain

Definition at line 62 of file ListMemBuf.h.

template<class T, unsigned int MAX, class index_t>
index_t ListMemBuf< T, MAX, index_t >::new_back  ) 
 

pushes a 'blank' entry on the back of the used list

Definition at line 137 of file ListMemBuf.h.

Referenced by MotionSequenceMC< MAXMOVE >::clear(), and ListMemBuf< T_t, MAX, idx_t >::new_before().

template<class T, unsigned int MAX, class index_t>
index_t ListMemBuf< T, MAX, index_t >::new_before index_t  x  ) 
 

inserts a 'blank' entry before element x in the used chain

Definition at line 153 of file ListMemBuf.h.

template<class T, unsigned int MAX, class index_t>
index_t ListMemBuf< T, MAX, index_t >::new_front  ) 
 

pushes a 'blank' entry on the front of the used list

Definition at line 121 of file ListMemBuf.h.

Referenced by SoundManager::Chain(), SoundManager::ChainBuffer(), SoundManager::ChainFile(), SoundManager::LoadBuffer(), ListMemBuf< T_t, MAX, idx_t >::new_before(), MotionSequenceMC< MAXMOVE >::newKeyFrame(), SoundManager::Play(), and MotionManager::pop_free().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::next index_t  x  )  const [inline]
 

returns the next used element following x

Definition at line 70 of file ListMemBuf.h.

Referenced by WaypointEngine< MAX_WAY >::calcAbsoluteCoords(), WaypointEngine< MAX_WAY >::checkNextWaypoint(), MotionSequenceMC< MAXMOVE >::clear(), ListMemBuf< T_t, MAX, idx_t >::countf(), MotionManager::getOutputs(), SoundManager::lookupPath(), SoundManager::PausePlay(), SoundManager::ReceivedMsg(), SoundManager::ResumePlay(), WaypointEngine< MAX_WAY >::SaveBuffer(), SoundManager::selectChannels(), MotionManager::setPID(), MotionSequenceMC< MAXMOVE >::setRange(), WaypointEngine< MAX_WAY >::setTargetWaypoint(), MotionManager::skip_ahead(), 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 [inline]
 

allows direct access to elements - be careful, can access 'free' elements this way

Definition at line 39 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  )  [inline]
 

allows direct access to elements - be careful, can access 'free' elements this way

Definition at line 38 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::push_free().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
void ListMemBuf< T_t, MAX, idx_t >::pop_back T ret  )  [inline]
 

pops the last of the used chain into ret

Definition at line 57 of file ListMemBuf.h.

template<class T, unsigned int MAX, class index_t>
void ListMemBuf< T, MAX, index_t >::pop_back  ) 
 

pops the last of the used chain

Definition at line 182 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::erase().

template<class T, unsigned int MAX, class index_t>
index_t ListMemBuf< T, MAX, index_t >::pop_free  )  [protected]
 

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 306 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  )  [inline]
 

pops the front of the chain into ret

Definition at line 52 of file ListMemBuf.h.

template<class T, unsigned int MAX, class index_t>
void ListMemBuf< T, MAX, index_t >::pop_front  ) 
 

pops the front of the used chain

Definition at line 170 of file ListMemBuf.h.

Referenced by SoundManager::ChainBuffer(), SoundManager::ChainFile(), ListMemBuf< T_t, MAX, idx_t >::erase(), and MotionManager::updatePIDs().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::prev index_t  x  )  const [inline]
 

returns the preceeding used element following x

Definition at line 71 of file ListMemBuf.h.

Referenced by MotionSequenceMC< MAXMOVE >::clear(), ListMemBuf< T_t, MAX, idx_t >::countb(), WaypointEngine< MAX_WAY >::fixArc(), SoundManager::selectChannels(), MotionSequenceMC< MAXMOVE >::setRange(), and SoundManager::StopPlay().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::push_after index_t  x,
const T data
[inline]
 

inserts a 'blank' entry after element x in the used chain and assigns data to it

Definition at line 63 of file ListMemBuf.h.

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::push_back const T data  )  [inline]
 

pushes an entry on the back of the used chain and assigns data to it

Definition at line 55 of file ListMemBuf.h.

Referenced by WaypointEngine< MAX_WAY >::addAbsoluteWaypoint(), WaypointEngine< MAX_WAY >::addEgocentricWaypoint(), WaypointEngine< MAX_WAY >::addOffsetWaypoint(), SoundManager::selectChannels(), and MotionManager::setPID().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::push_before index_t  x,
const T data
[inline]
 

inserts a 'blank' entry before element x in the used chain and assigns data to it

Definition at line 60 of file ListMemBuf.h.

template<class T, unsigned int MAX, class index_t>
void ListMemBuf< T, MAX, index_t >::push_free index_t  x  )  [protected]
 

pushes x onto the back of the free list

See also:
pop_free()

Definition at line 322 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::erase(), ListMemBuf< T_t, MAX, idx_t >::ListMemBuf(), ListMemBuf< T_t, MAX, idx_t >::pop_back(), and ListMemBuf< T_t, MAX, idx_t >::pop_front().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::push_front const T data  )  [inline]
 

pushes an entry on the front of the used chain and assigns data to it

Definition at line 50 of file ListMemBuf.h.

Referenced by SoundManager::Play(), SoundManager::ResumePlay(), and MotionManager::setOutput().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::size  )  const [inline]
 

returns the current number of objects in use

Definition at line 33 of file ListMemBuf.h.

Referenced by SoundManager::CopyTo(), WaypointEngine< MAX_WAY >::getBinSize(), MotionSequenceMC< MAXMOVE >::getUsedFrames(), MotionManager::InitAccess(), SoundManager::PlayBuffer(), SoundManager::PlayFile(), SoundManager::selectChannels(), and WaypointEngine< MAX_WAY >::setTargetWaypoint().

template<class T, unsigned int MAX, class index_t>
void ListMemBuf< T, MAX, index_t >::swap index_t  a,
index_t  b
 

swaps the two entries' position in the list

Definition at line 224 of file ListMemBuf.h.

Referenced by MotionManager::getOutputs().


Member Data Documentation

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::activeBack [protected]
 

end of used chain

Definition at line 87 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::clear(), 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(), and ListMemBuf< T_t, MAX, idx_t >::swap().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::activeBegin [protected]
 

beginning of used chain

Definition at line 86 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::clear(), 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(), and ListMemBuf< T_t, MAX, idx_t >::swap().

template<class T_t, unsigned int MAX, class idx_t = unsigned short>
index_t ListMemBuf< T_t, MAX, idx_t >::cursize [protected]
 

current number of used elements

Definition at line 90 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>
entry_t ListMemBuf< T_t, MAX, idx_t >::entries[MAX_ENTRIES] [protected]
 

the main block of data

Definition at line 85 of file ListMemBuf.h.

Referenced by 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_before(), ListMemBuf< T_t, MAX, idx_t >::new_front(), 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< 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>
index_t ListMemBuf< T_t, MAX, idx_t >::freeBack [protected]
 

end of free chain

Definition at line 89 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>
index_t ListMemBuf< T_t, MAX, idx_t >::freeBegin [protected]
 

beginning of free chain

Definition at line 88 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::clear(), 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>
const unsigned int ListMemBuf< T_t, MAX, idx_t >::MAX_ENTRIES = MAX [static]
 

Allows outside access to number of entries.

Definition at line 28 of file ListMemBuf.h.

Referenced by ListMemBuf< T_t, MAX, idx_t >::ListMemBuf().


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

Tekkotsu v2.2.1
Generated Tue Nov 23 16:37:48 2004 by Doxygen 1.3.9.1