Quick Links:

bal | bbl | bdl | bsl

Classes | Public Member Functions

bdlcc::Queue< TYPE > Class Template Reference

#include <bdlcc_queue.h>

List of all members.

Classes

struct  InitialCapacity
struct  IsVector

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (Queue, bslma::UsesBslmaAllocator)
 Queue (bslma::Allocator *basicAllocator=0)
 Queue (int highWaterMark, bslma::Allocator *basicAllocator=0)
 Queue (const InitialCapacity &numItems, bslma::Allocator *basicAllocator=0)
 Queue (const InitialCapacity &numItems, int highWaterMark, bslma::Allocator *basicAllocator=0)
 Queue (const bdlc::Queue< TYPE > &srcQueue, bslma::Allocator *basicAllocator=0)
 Queue (const bdlc::Queue< TYPE > &srcQueue, int highWaterMark, bslma::Allocator *basicAllocator=0)
 ~Queue ()
void popBack (TYPE *buffer)
TYPE popBack ()
int timedPopBack (TYPE *buffer, const bsls::TimeInterval &timeout)
void popFront (TYPE *buffer)
TYPE popFront ()
int timedPopFront (TYPE *buffer, const bsls::TimeInterval &timeout)
void removeAll ()
void removeAll (bsl::vector< TYPE > *buffer)
void removeAll (std::vector< TYPE > *buffer)
void pushBack (const TYPE &item)
void pushFront (const TYPE &item)
int timedPushBack (const TYPE &item, const bsls::TimeInterval &timeout)
int timedPushFront (const TYPE &item, const bsls::TimeInterval &timeout)
void forcePushFront (const TYPE &item)
int tryPopFront (TYPE *buffer)
void tryPopFront (int maxNumItems)
void tryPopFront (int maxNumItems, bsl::vector< TYPE > *buffer)
void tryPopFront (int maxNumItems, std::vector< TYPE > *buffer)
int tryPopBack (TYPE *buffer)
void tryPopBack (int maxNumItems)
void tryPopBack (int maxNumItems, bsl::vector< TYPE > *buffer)
void tryPopBack (int maxNumItems, std::vector< TYPE > *buffer)
bslmt::Conditioncondition ()
bslmt::ConditioninsertCondition ()
bslmt::Mutexmutex ()
bslmt::ConditionnotEmptyCondition ()
bslmt::ConditionnotFullCondition ()
bdlc::Queue< TYPE > & queue ()
int highWaterMark () const
int length () const

Detailed Description

template<class TYPE>
class bdlcc::Queue< TYPE >

This class provides a thread-enabled implementation of an efficient, in-place, indexable, double-ended queue of parameterized TYPE values. Very efficient access to the underlying bdlc::Queue object is provided, as well as to a bslmt::Mutex and a bslmt::Condition variable, to facilitate thread-safe use of the bdlc::Queue. Note that Queue is not a value-semantic type, but the underlying bdlc::Queue is. In this regard, Queue is a thread-enabled handle for a bdlc::Queue.

See Component bdlcc_queue


Constructor & Destructor Documentation

template<class TYPE>
bdlcc::Queue< TYPE >::Queue ( bslma::Allocator basicAllocator = 0  )  [explicit]

Create a queue of objects of parameterized TYPE. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

template<class TYPE>
bdlcc::Queue< TYPE >::Queue ( int  highWaterMark,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a queue of objects of parameterized TYPE having either the specified highWaterMark suggested maximum length if highWaterMark is positive, or no maximum length if highWaterMark is negative. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless highWaterMark != 0.

template<class TYPE>
bdlcc::Queue< TYPE >::Queue ( const InitialCapacity numItems,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a queue of objects of parameterized TYPE with sufficient initial capacity to accommodate up to the specified numItems values without subsequent reallocation. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

template<class TYPE>
bdlcc::Queue< TYPE >::Queue ( const InitialCapacity numItems,
int  highWaterMark,
bslma::Allocator basicAllocator = 0 
)

Create a queue of objects of parameterized TYPE with sufficient initial capacity to accommodate up to the specified numItems values without subsequent reallocation and having either the specified highWaterMark suggested maximum length if highWaterMark is positive, or no maximum length if highWaterMark is negative. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless highWaterMark != 0.

template<class TYPE>
bdlcc::Queue< TYPE >::Queue ( const bdlc::Queue< TYPE > &  srcQueue,
bslma::Allocator basicAllocator = 0 
)

IMPLICIT: Create a queue of objects of parameterized TYPE containing the sequence of TYPE values from the specified srcQueue. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

template<class TYPE>
bdlcc::Queue< TYPE >::Queue ( const bdlc::Queue< TYPE > &  srcQueue,
int  highWaterMark,
bslma::Allocator basicAllocator = 0 
)

Create a queue of objects of parameterized TYPE containing the sequence of TYPE values from the specified srcQueue and having either the specified highWaterMark suggested maximum length if highWaterMark is positive, or no maximum length if highWaterMark is negative. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless highWaterMark != 0.

template<class TYPE>
bdlcc::Queue< TYPE >::~Queue (  ) 

Destroy this container. The behavior is undefined unless all access or modification of the container has completed prior to this call.


Member Function Documentation

template<class TYPE>
bdlcc::Queue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( Queue< TYPE >  ,
bslma::UsesBslmaAllocator   
)
template<class TYPE>
void bdlcc::Queue< TYPE >::popBack ( TYPE *  buffer  ) 

Remove the last item in this queue and load that item into the specified buffer. If this queue is empty, block until an item is available.

template<class TYPE>
TYPE bdlcc::Queue< TYPE >::popBack (  ) 

Remove the last item in this queue and return that item value. If this queue is empty, block until an item is available.

template<class TYPE>
int bdlcc::Queue< TYPE >::timedPopBack ( TYPE *  buffer,
const bsls::TimeInterval timeout 
)

Remove the last item in this queue and load that item value into the specified buffer. If this queue is empty, block until an item is available or until the specified timeout (expressed as the ABSOLUTE time from 00:00:00 UTC, January 1, 1970) expires. Return 0 on success, and a non-zero value if the call timed out before an item was available.

template<class TYPE>
void bdlcc::Queue< TYPE >::popFront ( TYPE *  buffer  ) 

Remove the first item in this queue and load that item into the specified buffer. If the queue is empty, block until an item is available.

template<class TYPE>
TYPE bdlcc::Queue< TYPE >::popFront (  ) 

Remove the first item in this queue and return that item value. If the queue is empty, block until an item is available.

template<class TYPE>
int bdlcc::Queue< TYPE >::timedPopFront ( TYPE *  buffer,
const bsls::TimeInterval timeout 
)

Remove the first item in this queue and load that item value into the specified buffer. If this queue is empty, block until an item is available or until the specified timeout (expressed as the ABSOLUTE time from 00:00:00 UTC, January 1, 1970) expires. Return 0 on success, and a non-zero value if the call timed out before an item was available.

template<class TYPE>
void bdlcc::Queue< TYPE >::removeAll (  ) 
template<class TYPE>
void bdlcc::Queue< TYPE >::removeAll ( bsl::vector< TYPE > *  buffer  ) 
template<class TYPE>
void bdlcc::Queue< TYPE >::removeAll ( std::vector< TYPE > *  buffer  ) 

Remove all the items in this queue. If the optionally specified buffer is not 0, load into buffer a copy of the items removed in front to back order of the queue prior to removeAll.

template<class TYPE>
void bdlcc::Queue< TYPE >::pushBack ( const TYPE &  item  ) 

Append the specified item to the back of this queue. If the high-water mark is non-negative and the number of items in this queue is greater than or equal to the high-water mark, then block until the number of items in this queue is less than the high-water mark.

template<class TYPE>
void bdlcc::Queue< TYPE >::pushFront ( const TYPE &  item  ) 

Append the specified item to the front of this queue. If the high-water mark is non-negative and the number of items in this queue is greater than or equal to the high-water mark, then block until the number of items in this queue is less than the high-water mark.

template<class TYPE>
int bdlcc::Queue< TYPE >::timedPushBack ( const TYPE &  item,
const bsls::TimeInterval timeout 
)

Append the specified item to the back of this queue. If the high-water mark is non-negative and the number of items in this queue is greater than or equal to the high-water mark, then block until the number of items in this queue is less than the high-water mark or until the specified timeout (expressed as the ABSOLUTE time from 00:00:00 UTC, January 1, 1970) expires. Return 0 on success, and a non-zero value if the call timed out before the number of items in this queue fell below the high-water mark.

template<class TYPE>
int bdlcc::Queue< TYPE >::timedPushFront ( const TYPE &  item,
const bsls::TimeInterval timeout 
)

Append the specified item to the front of this queue. If the high water mark is non-negative and the number of items in this queue is greater than or equal to the high-water mark, then block until the number of items in this queue is less than the high-water mark or until the specified timeout (expressed as the ABSOLUTE time from 00:00:00 UTC, January 1, 1970) expires. Return 0 on success, and a non-zero value if the call timed out before the number of items in this queue fell below the high-water mark.

template<class TYPE>
void bdlcc::Queue< TYPE >::forcePushFront ( const TYPE &  item  ) 

Append the specified item to the front of this queue without regard for the high-water mark. Note that this method is provided to allow high priority items to be inserted when the queue is full (i.e., has a number of items greater than or equal to its high-water mark); pushFront and pushBack should be used for general use.

template<class TYPE>
int bdlcc::Queue< TYPE >::tryPopFront ( TYPE *  buffer  ) 

If this queue is non-empty, remove the first item, load that item into the specified buffer, and return 0 indicating success. If this queue is empty, return a non-zero value with no effect on buffer or the state of this queue. This method never blocks.

template<class TYPE>
void bdlcc::Queue< TYPE >::tryPopFront ( int  maxNumItems  ) 
template<class TYPE>
void bdlcc::Queue< TYPE >::tryPopFront ( int  maxNumItems,
bsl::vector< TYPE > *  buffer 
)
template<class TYPE>
void bdlcc::Queue< TYPE >::tryPopFront ( int  maxNumItems,
std::vector< TYPE > *  buffer 
)

Remove up to the specified maxNumItems from the front of this queue. Optionally specify a buffer into which the items removed from the queue are loaded. If buffer is non-null, the removed items are appended to it as if by repeated application of buffer->push_back(popFront()) while the queue is not empty and maxNumItems have not yet been removed. The behavior is undefined unless maxNumItems >= 0. This method never blocks.

template<class TYPE>
int bdlcc::Queue< TYPE >::tryPopBack ( TYPE *  buffer  ) 

If this queue is non-empty, remove the last item, load that item into the specified buffer, and return 0 indicating success. If this queue is empty, return a non-zero value with no effect on buffer or the state of this queue. This method never blocks.

template<class TYPE>
void bdlcc::Queue< TYPE >::tryPopBack ( int  maxNumItems  ) 
template<class TYPE>
void bdlcc::Queue< TYPE >::tryPopBack ( int  maxNumItems,
bsl::vector< TYPE > *  buffer 
)
template<class TYPE>
void bdlcc::Queue< TYPE >::tryPopBack ( int  maxNumItems,
std::vector< TYPE > *  buffer 
)

Remove up to the specified maxNumItems from the back of this queue. Optionally specify a buffer into which the items removed from the queue are loaded. If buffer is non-null, the removed items are appended to it as if by repeated application of buffer->push_back(popBack()) while the queue is not empty and maxNumItems have not yet been removed. This method never blocks. The behavior is undefined unless maxNumItems >= 0. Note that the ordering of the items in *buffer after the call is the reverse of the ordering they had in the queue.

template<class TYPE>
bslmt::Condition& bdlcc::Queue< TYPE >::condition (  ) 

Return a reference to the modifiable condition variable used by this queue to signal that the queue is not empty.

DEPRECATED Use notEmptyCondition instead.

template<class TYPE>
bslmt::Condition& bdlcc::Queue< TYPE >::insertCondition (  ) 

Return a reference to the modifiable condition variable used by this queue to signal that the queue is not full (i.e., has fewer items than its high-water mark).

DEPRECATED Use notFullCondition instead.

template<class TYPE>
bslmt::Mutex& bdlcc::Queue< TYPE >::mutex (  ) 

Return a reference to the modifiable mutex used by this queue to synchronize access to its underlying bdlc::Queue object.

template<class TYPE>
bslmt::Condition& bdlcc::Queue< TYPE >::notEmptyCondition (  ) 

Return the condition variable used by this queue to signal that the queue is not empty.

template<class TYPE>
bslmt::Condition& bdlcc::Queue< TYPE >::notFullCondition (  ) 

Return the condition variable used by this queue to signal that the queue is not full (i.e., has fewer items than its high-water mark).

template<class TYPE>
bdlc::Queue<TYPE>& bdlcc::Queue< TYPE >::queue (  ) 

Return a reference to the modifiable underlying bdlc::Queue object used by this queue. Any access to the returned queue MUST first lock the associated mutex object (see the mutex method) in a multi-threaded environment. And when items are directly added to the queue returned by this method, the associated condition variable (see the condition method) should be signaled to notify any waiting threads of the availability of the new data.

The (error-prone) usage of this method will be replaced by an appropriate smart-pointer-like proctor object in the future. Meanwhile, use this method with caution.

template<class TYPE>
int bdlcc::Queue< TYPE >::highWaterMark (  )  const

Return the high-water mark value for this queue. Note that a negative value indicates no suggested-maximum capacity, and is not necessarily the same negative value that was passed to the constructor.

template<class TYPE>
int bdlcc::Queue< TYPE >::length (  )  const

Return the number of elements in this queue. Note that if other threads are manipulating the queue, this information may be obsolete by the time it is returned.


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