knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::TokenQueue Class Reference

#include <TokenQueue.h>

Inheritance diagram for knowrob::TokenQueue:
Collaboration diagram for knowrob::TokenQueue:

Public Member Functions

 TokenQueue ()
 
 ~TokenQueue () override
 
TokenPtrfront ()
 
void pop ()
 
TokenPtr pop_front ()
 
bool empty () const
 
auto size () const
 
 TokenQueue ()
 
 ~TokenQueue () override
 
TokenPtrfront ()
 
void pop ()
 
TokenPtr pop_front ()
 
bool empty () const
 
auto size () const
 
- Public Member Functions inherited from knowrob::TokenStream
 TokenStream ()
 
virtual ~TokenStream ()
 
 TokenStream (const TokenStream &)=delete
 
virtual void close ()
 
bool isOpened () const
 
 TokenStream ()
 
virtual ~TokenStream ()
 
 TokenStream (const TokenStream &)=delete
 
virtual void close ()
 
bool isOpened () const
 

Protected Member Functions

void push (const TokenPtr &tok) override
 
void pushToQueue (const TokenPtr &tok)
 
void push (const TokenPtr &tok) override
 
void pushToQueue (const TokenPtr &tok)
 
- Protected Member Functions inherited from knowrob::TokenStream
virtual void push (Channel &channel, const TokenPtr &tok)
 
virtual void push (Channel &channel, const TokenPtr &tok)
 

Protected Attributes

std::queue< TokenPtrqueue_
 
std::condition_variable queue_CV_
 
std::mutex queue_mutex_
 
- Protected Attributes inherited from knowrob::TokenStream
std::list< std::shared_ptr< Channel > > channels_
 
std::atomic< bool > isOpened_
 
std::mutex channel_mutex_
 

Detailed Description

A queue of query results.

Definition at line 18 of file TokenQueue.h.

Constructor & Destructor Documentation

◆ TokenQueue() [1/2]

TokenQueue::TokenQueue ( )

Definition at line 11 of file TokenQueue.cpp.

◆ ~TokenQueue() [1/2]

TokenQueue::~TokenQueue ( )
override

Definition at line 14 of file TokenQueue.cpp.

14  {
15  if (isOpened()) {
17  }
18 }
void pushToQueue(const TokenPtr &tok)
Definition: TokenQueue.cpp:20
bool isOpened() const
Definition: TokenStream.cpp:44

◆ TokenQueue() [2/2]

knowrob::TokenQueue::TokenQueue ( )

◆ ~TokenQueue() [2/2]

knowrob::TokenQueue::~TokenQueue ( )
override

Member Function Documentation

◆ empty() [1/2]

bool knowrob::TokenQueue::empty ( ) const
inline
Returns
true if the queue is currently empty.

Definition at line 45 of file TokenQueue.h.

45 { return queue_.empty(); }
std::queue< TokenPtr > queue_
Definition: TokenQueue.h:53

◆ empty() [2/2]

bool knowrob::TokenQueue::empty ( ) const
inline
Returns
true if the queue is currently empty.

Definition at line 45 of file TokenQueue.h.

45 { return queue_.empty(); }

◆ front() [1/2]

TokenPtr & TokenQueue::front ( )

Get the front element of this queue without removing it. This will block until the queue is non empty.

Returns
the front element of the queue.

Definition at line 32 of file TokenQueue.cpp.

32  {
33  std::unique_lock<std::mutex> lock(queue_mutex_);
34  queue_CV_.wait(lock, [&] { return !queue_.empty(); });
35  return queue_.front();
36 }
std::mutex queue_mutex_
Definition: TokenQueue.h:55
std::condition_variable queue_CV_
Definition: TokenQueue.h:54

◆ front() [2/2]

TokenPtr& knowrob::TokenQueue::front ( )

Get the front element of this queue without removing it. This will block until the queue is non empty.

Returns
the front element of the queue.

◆ pop() [1/2]

void TokenQueue::pop ( )

Remove the front element of this queue.

Definition at line 38 of file TokenQueue.cpp.

38  {
39  std::lock_guard<std::mutex> lock(queue_mutex_);
40  queue_.pop();
41 }

◆ pop() [2/2]

void knowrob::TokenQueue::pop ( )

Remove the front element of this queue.

◆ pop_front() [1/2]

TokenPtr TokenQueue::pop_front ( )

Get front element and remove it from the queue.

Returns
the front element of the queue.

Definition at line 43 of file TokenQueue.cpp.

43  {
44  TokenPtr x = front();
45  pop();
46  return x;
47 }
TokenPtr & front()
Definition: TokenQueue.cpp:32
std::shared_ptr< const Token > TokenPtr
Definition: Token.h:74

◆ pop_front() [2/2]

TokenPtr knowrob::TokenQueue::pop_front ( )

Get front element and remove it from the queue.

Returns
the front element of the queue.

◆ push() [1/2]

void TokenQueue::push ( const TokenPtr tok)
overrideprotectedvirtual

Implements knowrob::TokenStream.

Definition at line 28 of file TokenQueue.cpp.

28  {
29  pushToQueue(tok);
30 }

◆ push() [2/2]

void knowrob::TokenQueue::push ( const TokenPtr tok)
overrideprotectedvirtual

Implements knowrob::TokenStream.

◆ pushToQueue() [1/2]

void TokenQueue::pushToQueue ( const TokenPtr tok)
protected

Definition at line 20 of file TokenQueue.cpp.

20  {
21  {
22  std::lock_guard<std::mutex> lock(queue_mutex_);
23  queue_.push(tok);
24  }
25  queue_CV_.notify_one();
26 }

◆ pushToQueue() [2/2]

void knowrob::TokenQueue::pushToQueue ( const TokenPtr tok)
protected

◆ size() [1/2]

auto knowrob::TokenQueue::size ( ) const
inline
Returns
number of currently queued elements.

Definition at line 50 of file TokenQueue.h.

50 { return queue_.size(); }

◆ size() [2/2]

auto knowrob::TokenQueue::size ( ) const
inline
Returns
number of currently queued elements.

Definition at line 50 of file TokenQueue.h.

50 { return queue_.size(); }

Member Data Documentation

◆ queue_

std::queue< TokenPtr > knowrob::TokenQueue::queue_
protected

Definition at line 53 of file TokenQueue.h.

◆ queue_CV_

std::condition_variable knowrob::TokenQueue::queue_CV_
protected

Definition at line 54 of file TokenQueue.h.

◆ queue_mutex_

std::mutex knowrob::TokenQueue::queue_mutex_
protected

Definition at line 55 of file TokenQueue.h.


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