BDE 4.14.0 Production release
|
#include <bdlcc_timequeue.h>
Classes | |
class | Key |
Public Types | |
typedef int | Handle |
Public Member Functions | |
TimeQueue (bslma::Allocator *basicAllocator=0) | |
TimeQueue (int numIndexBits, bslma::Allocator *basicAllocator=0) | |
TimeQueue (bool poolTimerMemory, bslma::Allocator *basicAllocator=0) | |
TimeQueue (int numIndexBits, bool poolTimerMemory, bslma::Allocator *basicAllocator=0) | |
~TimeQueue () | |
Destroy this time queue. | |
Handle | add (const bsls::TimeInterval &time, const DATA &data, int *isNewTop=0, int *newLength=0) |
Handle | add (const bsls::TimeInterval &time, const DATA &data, const Key &key, int *isNewTop=0, int *newLength=0) |
Handle | add (const TimeQueueItem< DATA > &item, int *isNewTop=0, int *newLength=0) |
int | popFront (TimeQueueItem< DATA > *buffer=0, int *newLength=0, bsls::TimeInterval *newMinTime=0) |
void | popLE (const bsls::TimeInterval &time) |
void | popLE (const bsls::TimeInterval &time, bsl::vector< TimeQueueItem< DATA > > *buffer, int *newLength=0, bsls::TimeInterval *newMinTime=0) |
void | popLE (const bsls::TimeInterval &time, std::vector< TimeQueueItem< DATA > > *buffer, int *newLength=0, bsls::TimeInterval *newMinTime=0) |
void | popLE (const bsls::TimeInterval &time, int maxTimers) |
void | popLE (const bsls::TimeInterval &time, int maxTimers, bsl::vector< TimeQueueItem< DATA > > *buffer, int *newLength=0, bsls::TimeInterval *newMinTime=0) |
void | popLE (const bsls::TimeInterval &time, int maxTimers, std::vector< TimeQueueItem< DATA > > *buffer, int *newLength=0, bsls::TimeInterval *newMinTime=0) |
int | remove (Handle handle, int *newLength=0, bsls::TimeInterval *newMinTime=0, TimeQueueItem< DATA > *item=0) |
int | remove (Handle handle, const Key &key, int *newLength=0, bsls::TimeInterval *newMinTime=0, TimeQueueItem< DATA > *item=0) |
void | removeAll (bsl::vector< TimeQueueItem< DATA > > *buffer=0) |
int | update (Handle handle, const bsls::TimeInterval &newTime, int *isNewTop=0) |
int | update (Handle handle, const Key &key, const bsls::TimeInterval &newTime, int *isNewTop=0) |
int | length () const |
bool | isRegisteredHandle (Handle handle) const |
bool | isRegisteredHandle (Handle handle, const Key &key) const |
int | minTime (bsls::TimeInterval *buffer) const |
int | countLE (const bsls::TimeInterval &time) const |
This parameterized class provides a public interface which is similar in structure and intent to Queue<DATA>
, with the exception that each item stored in the TimeQueue
has an associated time value. Items are retrieved or exchanged by proxy of a TimeQueueItem<DATA>
, and are referred to by an opaque data type TimeQueue::Handle
which serves to identify an individual element on the Time Queue. Idiomatic usage of TimeQueue
includes the member function popLE
, which finds all items on the queue whose bsls::TimeInterval
are less than a specified value and transfers those items to a provided vector of items, and the member function update
, which can update the time value for a specific TimeQueueItem
without removing it from the queue.
See bdlcc_timequeue
typedef int bdlcc::TimeQueue< DATA >::Handle |
Handle
defines an alias for uniquely identifying a valid node in the time queue. Handles are returned when nodes are added to the time queue, and must be supplied to the update
and remove
methods to identify existing nodes. When a node is removed, the handle value becomes invalid, though invalidated handle values are eventually reused. See the component-level documentation for more details.
|
explicit |
|
explicit |
Create an empty time queue. Optionally specify numIndexBits
to configure the number of index bits used by this object. If numIndexBits
is not specified a default value of 17 is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless 8 <= numIndexBits <= 24
. See the component-level documentation for more information regarding numIndexBits
.
|
explicit |
bdlcc::TimeQueue< DATA >::TimeQueue | ( | int | numIndexBits, |
bool | poolTimerMemory, | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
bdlcc::TimeQueue< DATA >::~TimeQueue | ( | ) |
TimeQueue< DATA >::Handle bdlcc::TimeQueue< DATA >::add | ( | const bsls::TimeInterval & | time, |
const DATA & | data, | ||
const Key & | key, | ||
int * | isNewTop = 0 , |
||
int * | newLength = 0 |
||
) |
Add a new item to this queue having the specified time
value, and associated data
. Optionally use the specified key
to uniquely identify the item in subsequent calls to remove
and update
. Optionally load into the optionally specified isNewTop
a non-zero value if the item is now the lowest item in this queue, and a 0 value otherwise. If specified, load into the optionally specified newLength
, the new number of items in this queue. Return a value that may be used to identify the newly added item in future calls to time queue on success, and -1 if the maximum queue length has been reached.
|
inline |
|
inline |
Add the value of the specified item
to this queue. Optionally load into the optionally specified isNewTop
a non-zero value if the replaces is now the lowest element in this queue, and a 0 value otherwise. If specified, load into the optionally specified newLength
, the new number of elements in this queue. Return a value that may be used to identify the newly added item in future calls to time queue on success, and -1 if the maximum queue length has been reached.
|
inline |
Return the number of items in this queue that have a time value less than or equal to the specified time
. Note that the value returned may be obsolete by the time it is received.
bool bdlcc::TimeQueue< DATA >::isRegisteredHandle | ( | Handle | handle | ) | const |
Return true
if an item having specified handle
is currently registered with this time queue and false otherwise.
bool bdlcc::TimeQueue< DATA >::isRegisteredHandle | ( | Handle | handle, |
const Key & | key | ||
) | const |
|
inline |
Return number of items in this queue. Note that the value returned may be obsolete by the time it is received.
|
inline |
Load into the specified buffer
, the time value of the lowest time in this queue. Return 0 on success, and a non-zero value if this queue is empty.
int bdlcc::TimeQueue< DATA >::popFront | ( | TimeQueueItem< DATA > * | buffer = 0 , |
int * | newLength = 0 , |
||
bsls::TimeInterval * | newMinTime = 0 |
||
) |
Atomically remove the top item from this queue, and optionally load into the optionally specified buffer
the time and associated data of the item removed. Optionally load into the optionally specified newLength
, the number of items remaining in the queue. Optionally load into the optionally specified newMinTime
the new lowest time in this queue. Return 0 on success, and a non-zero value if there are no items in the queue. Note that if DATA
follows the bdema
allocator model, the allocator of the buffer
is used to supply memory.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Remove from this queue up to the specified maxTimers
number of items that have a time value less than or equal to the specified time
, and optionally append into the optionally specified buffer
a list of the removed items, ordered by their corresponding time values (top item first). Optionally load into the optionally specified newLength
the number of items remaining in this queue, and into the optionally specified newMinTime
the lowest remaining time value in this queue. The behavior is undefined unless maxTimers >= 0
. Note that newMinTime
is only loaded if there are items remaining in the time queue; therefore, newLength
should be specified and examined to determine whether items remain, and newMinTime
used only when newLength > 0
. Also note that if DATA
follows the bdema
allocator model, the allocator of the buffer
vector is used to supply memory. Note finally that all the items appended into buffer
have a time value less than or equal to the elements remaining in this queue.
|
inline |
Remove from this queue all the items that have a time value less than or equal to the specified time
, and optionally append into the optionally specified buffer
a list of the removed items, ordered by their corresponding time values (top item first). Optionally load into the optionally specified newLength
the number of items remaining in this queue, and into the optionally specified newMinTime
the lowest remaining time value in this queue. Note that newMinTime
is only loaded if there are items remaining in the time queue; therefore, newLength
should be specified and examined to determine whether items remain, and newMinTime
used only when newLength > 0
. Also note that if DATA
follows the bdema
allocator model, the allocator of the buffer
vector is used to supply memory for the items appended to the buffer
.
int bdlcc::TimeQueue< DATA >::remove | ( | Handle | handle, |
const Key & | key, | ||
int * | newLength = 0 , |
||
bsls::TimeInterval * | newMinTime = 0 , |
||
TimeQueueItem< DATA > * | item = 0 |
||
) |
Remove from this queue the item having the specified handle
, and optionally load into the optionally specified item
the time and data values of the recently removed item. Optionally use the specified key
to uniquely identify the item. If specified, load into the optionally specified newMinTime
, the resulting lowest time value remaining in the queue. Return 0 on success, and a non-zero value if no item with the handle
exists in the queue. Note that if DATA
follows the bdema
allocator model, the allocator of the item
instance is used to supply memory.
int bdlcc::TimeQueue< DATA >::remove | ( | Handle | handle, |
int * | newLength = 0 , |
||
bsls::TimeInterval * | newMinTime = 0 , |
||
TimeQueueItem< DATA > * | item = 0 |
||
) |
void bdlcc::TimeQueue< DATA >::removeAll | ( | bsl::vector< TimeQueueItem< DATA > > * | buffer = 0 | ) |
Remove all the items from this queue. Optionally specify a buffer
in which to load the removed items. The resultant items in the buffer
are ordered by increasing time interval; items of equivalent time interval have arbitrary ordering. Note that the allocator of the buffer
vector is used to supply memory.
int bdlcc::TimeQueue< DATA >::update | ( | Handle | handle, |
const bsls::TimeInterval & | newTime, | ||
int * | isNewTop = 0 |
||
) |
int bdlcc::TimeQueue< DATA >::update | ( | Handle | handle, |
const Key & | key, | ||
const bsls::TimeInterval & | newTime, | ||
int * | isNewTop = 0 |
||
) |
Update the time value of the item having the specified handle
to the specified newTime
and optionally load into the optionally specified isNewTop
a non-zero value if the modified item is now the lowest time value in the time queue or zero otherwise. Return 0 on success, and a non-zero value if there is currently no item having the handle
registered with this time queue.