oasys::BoundedPriorityQueue< T, TSize, TCompare > Class Template Reference

#include <BoundedPriorityQueue.h>

Inheritance diagram for oasys::BoundedPriorityQueue< T, TSize, TCompare >:

dtn::ProphetBundleQueue

List of all members.


Detailed Description

template<class T, class TSize, class TCompare = std::less<T>>
class oasys::BoundedPriorityQueue< T, TSize, TCompare >

BoundedPriorityQueue inherits from the std::priority_queue template to include capacity detection and to impose an arbitrary bound.

The default capacity is object size, but this can be overridden by supplying a TSize function pattern to read a different capacity from the T object.

Elements are sorted according to the priority provided by TCompare, which defaults to using the < operator, if the object defines one. This too can be overridden by supplying a comparator that detects a different priority from the T object.

Member function current() returns the current capacity. The maximum capacity is set by template variable, but can be updated by passing the new value to the constructor or set_max() method.

Bounds are enforced by the constructors and by push(). When a push() operation causes the BoundedPriorityQueue to exceed its maximum capacity, elements of least priority are dropped (by calling pop_back() on the underlying container) until the bound is no longer violated.

Other than the above exceptions, the default behavior is that of priority_queue

Definition at line 53 of file BoundedPriorityQueue.h.


Public Types

typedef std::vector< T > Sequence
typedef
std::priority_queue
< T, Sequence,
TCompare > 
PriorityQueue

Public Member Functions

 BoundedPriorityQueue (u_int max_size)
 Default constructor.
 BoundedPriorityQueue (const TCompare &comp, u_int max_size)
 Alternate constructor.
void push (const T &obj)
 Utilize priority_queue's default behavior, then update bounds tracking with new entry's TSize(), then enforce_bound.
void pop ()
 Decrement bounds tracking by this entry's TSize(), then utilize priority_queue's default pop() behavior.
u_int current () const
 Report current bound status.
u_int max () const
 Report maximum bound allowed.
void set_max (u_int max_size)
 Update to new maximum bound.

Protected Types

typedef
Sequence::const_iterator 
const_iterator
typedef
Sequence::iterator 
iterator

Protected Member Functions

const Sequencecontainer () const
void init ()
 Initialize bounds tracking, then enforce_bound.
void erase_member (iterator pos)
 Create a stub for derived classes to impose other policy upon object removal.
void enforce_bound ()
 Drop lowest priority elements until maximum bounds is no longer exceeded.

Protected Attributes

u_int cur_size_
 Current bound status.
u_int max_size_
 Maximum bound allowed.

Member Typedef Documentation

template<class T, class TSize, class TCompare = std::less<T>>
typedef std::vector<T> oasys::BoundedPriorityQueue< T, TSize, TCompare >::Sequence

Definition at line 59 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
typedef std::priority_queue<T,Sequence,TCompare> oasys::BoundedPriorityQueue< T, TSize, TCompare >::PriorityQueue

Definition at line 60 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
typedef Sequence::const_iterator oasys::BoundedPriorityQueue< T, TSize, TCompare >::const_iterator [protected]

Definition at line 141 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
typedef Sequence::iterator oasys::BoundedPriorityQueue< T, TSize, TCompare >::iterator [protected]

Definition at line 142 of file BoundedPriorityQueue.h.


Constructor & Destructor Documentation

template<class T, class TSize, class TCompare = std::less<T>>
oasys::BoundedPriorityQueue< T, TSize, TCompare >::BoundedPriorityQueue ( u_int  max_size  )  [inline]

Default constructor.

Parameters:
max defaults to template parameter, max_size

Definition at line 66 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
oasys::BoundedPriorityQueue< T, TSize, TCompare >::BoundedPriorityQueue ( const TCompare &  comp,
u_int  max_size 
) [inline]

Alternate constructor.

Parameters:
comp comparator object
max defaults to template parametr, max_size

Definition at line 79 of file BoundedPriorityQueue.h.


Member Function Documentation

template<class T, class TSize, class TCompare = std::less<T>>
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::push ( const T &  obj  )  [inline]

Utilize priority_queue's default behavior, then update bounds tracking with new entry's TSize(), then enforce_bound.

Definition at line 91 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::pop (  )  [inline]

Decrement bounds tracking by this entry's TSize(), then utilize priority_queue's default pop() behavior.

Reimplemented in dtn::ProphetBundleQueue.

Definition at line 102 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::current (  )  const [inline]

Report current bound status.

Definition at line 111 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::max (  )  const [inline]

Report maximum bound allowed.

Definition at line 119 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::set_max ( u_int  max_size  )  [inline]

Update to new maximum bound.

Definition at line 127 of file BoundedPriorityQueue.h.

Referenced by dtn::ProphetController::handle_max_usage_change().

template<class T, class TSize, class TCompare = std::less<T>>
const Sequence& oasys::BoundedPriorityQueue< T, TSize, TCompare >::container (  )  const [inline, protected]

Definition at line 136 of file BoundedPriorityQueue.h.

template<class T, class TSize, class TCompare = std::less<T>>
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::init (  )  [inline, protected]

Initialize bounds tracking, then enforce_bound.

Definition at line 147 of file BoundedPriorityQueue.h.

Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::BoundedPriorityQueue().

template<class T, class TSize, class TCompare = std::less<T>>
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::erase_member ( iterator  pos  )  [inline, protected]

Create a stub for derived classes to impose other policy upon object removal.

Definition at line 159 of file BoundedPriorityQueue.h.

Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::enforce_bound().

template<class T, class TSize, class TCompare = std::less<T>>
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::enforce_bound (  )  [inline, protected]

Drop lowest priority elements until maximum bounds is no longer exceeded.

Reimplemented in dtn::ProphetBundleQueue.

Definition at line 168 of file BoundedPriorityQueue.h.

Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::init(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::push(), and oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::set_max().


Member Data Documentation

template<class T, class TSize, class TCompare = std::less<T>>
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::cur_size_ [protected]

Current bound status.

Definition at line 187 of file BoundedPriorityQueue.h.

Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::current(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::init(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::pop(), and oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::push().

template<class T, class TSize, class TCompare = std::less<T>>
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::max_size_ [protected]

Maximum bound allowed.

Definition at line 188 of file BoundedPriorityQueue.h.

Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::max(), and oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::set_max().


The documentation for this class was generated from the following file:
Generated on Sat Sep 8 08:43:55 2007 for DTN Reference Implementation by  doxygen 1.5.3