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

#include <TripleContainer.h>

Inheritance diagram for knowrob::TripleViewBatch:
Collaboration diagram for knowrob::TripleViewBatch:

Public Member Functions

 TripleViewBatch (uint32_t batchSize)
 
auto size () const
 
void reset ()
 
void add (const TriplePtr &triple)
 
ConstGenerator cgenerator () const override
 
MutableGenerator generator () override
 
 TripleViewBatch (uint32_t batchSize)
 
auto size () const
 
void reset ()
 
void add (const TriplePtr &triple)
 
ConstGenerator cgenerator () const override
 
MutableGenerator generator () override
 
- Public Member Functions inherited from knowrob::MutableTripleContainer
iterator begin ()
 
bool isMutable () const override
 
iterator begin ()
 
bool isMutable () const override
 
- Public Member Functions inherited from knowrob::TripleContainer
virtual ~TripleContainer ()=default
 
iterator begin () const
 
bool empty () const
 
virtual ~TripleContainer ()=default
 
iterator begin () const
 
bool empty () const
 

Protected Attributes

std::vector< TriplePtrdata_
 
uint32_t batchSize_
 
std::size_t actualSize_
 

Additional Inherited Members

- Public Types inherited from knowrob::MutableTripleContainer
using MutableGenerator = std::function< TriplePtr *()>
 
using MutableGenerator = std::function< TriplePtr *()>
 
- Public Types inherited from knowrob::TripleContainer
using ConstGenerator = std::function< const TriplePtr *()>
 
using ConstGenerator = std::function< const TriplePtr *()>
 
- Static Public Member Functions inherited from knowrob::MutableTripleContainer
static iterator end ()
 
static iterator end ()
 
- Static Public Member Functions inherited from knowrob::TripleContainer
static iterator end ()
 
static iterator end ()
 

Detailed Description

A batch of framed triples that attempts to take over ownership of the triples that are added to it.

Definition at line 157 of file TripleContainer.h.

Constructor & Destructor Documentation

◆ TripleViewBatch() [1/2]

TripleViewBatch::TripleViewBatch ( uint32_t  batchSize)
explicit

Definition at line 38 of file TripleContainer.cpp.

39  : data_(batchSize), batchSize_(batchSize), actualSize_(0) {
40 }
std::vector< TriplePtr > data_

◆ TripleViewBatch() [2/2]

knowrob::TripleViewBatch::TripleViewBatch ( uint32_t  batchSize)
explicit

Member Function Documentation

◆ add() [1/2]

void TripleViewBatch::add ( const TriplePtr triple)

Adds a triple to the batch, and attempts to take over ownership of the triple. If this fails, a new copy of the triple is created and added to the batch.

Parameters
triplea triple.

Definition at line 42 of file TripleContainer.cpp.

42  {
43  if (actualSize_ < batchSize_) {
44  auto &entry = data_[actualSize_++];
45  if (entry.owned && entry.ptr) {
46  delete entry.ptr;
47  }
48  if (triple.owned) {
49  entry.ptr = triple.ptr;
50  entry.owned = true;
51  triple.owned = false;
52  } else {
53  entry.ptr = new TripleCopy(*triple.ptr);
54  entry.owned = true;
55  }
56  }
57 }
TripleTemplate< std::string > TripleCopy
Definition: Triple.h:577
Triple * ptr
Definition: Triple.h:590

◆ add() [2/2]

void knowrob::TripleViewBatch::add ( const TriplePtr triple)

Adds a triple to the batch, and attempts to take over ownership of the triple. If this fails, a new copy of the triple is created and added to the batch.

Parameters
triplea triple.

◆ cgenerator() [1/2]

TripleContainer::ConstGenerator TripleViewBatch::cgenerator ( ) const
overridevirtual
Returns
a generator function that returns a const pointer to a triple.

Implements knowrob::TripleContainer.

Definition at line 59 of file TripleContainer.cpp.

59  {
60  return [this, i = std::size_t(0)]() mutable -> const TriplePtr * {
61  if (i < actualSize_) return &data_[i++];
62  return nullptr;
63  };
64 }

◆ cgenerator() [2/2]

ConstGenerator knowrob::TripleViewBatch::cgenerator ( ) const
overridevirtual
Returns
a generator function that returns a const pointer to a triple.

Implements knowrob::TripleContainer.

◆ generator() [1/2]

MutableTripleContainer::MutableGenerator TripleViewBatch::generator ( )
overridevirtual
Returns
a generator function that returns a pointer to a triple.

Implements knowrob::MutableTripleContainer.

Definition at line 66 of file TripleContainer.cpp.

66  {
67  return [this, i = std::size_t(0)]() mutable -> TriplePtr * {
68  if (i < actualSize_) return &data_[i++];
69  return nullptr;
70  };
71 }

◆ generator() [2/2]

MutableGenerator knowrob::TripleViewBatch::generator ( )
overridevirtual
Returns
a generator function that returns a pointer to a triple.

Implements knowrob::MutableTripleContainer.

◆ reset() [1/2]

void knowrob::TripleViewBatch::reset ( )
inline

Resets the batch to an empty state.

Definition at line 169 of file TripleContainer.h.

169 { actualSize_ = 0; }

◆ reset() [2/2]

void knowrob::TripleViewBatch::reset ( )
inline

Resets the batch to an empty state.

Definition at line 169 of file TripleContainer.h.

169 { actualSize_ = 0; }

◆ size() [1/2]

auto knowrob::TripleViewBatch::size ( ) const
inline
Returns
the actual size of the batch.

Definition at line 164 of file TripleContainer.h.

164 { return actualSize_; }

◆ size() [2/2]

auto knowrob::TripleViewBatch::size ( ) const
inline
Returns
the actual size of the batch.

Definition at line 164 of file TripleContainer.h.

164 { return actualSize_; }

Member Data Documentation

◆ actualSize_

std::size_t knowrob::TripleViewBatch::actualSize_
protected

Definition at line 187 of file TripleContainer.h.

◆ batchSize_

uint32_t knowrob::TripleViewBatch::batchSize_
protected

Definition at line 186 of file TripleContainer.h.

◆ data_

std::vector< TriplePtr > knowrob::TripleViewBatch::data_
protected

Definition at line 185 of file TripleContainer.h.


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