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

#include <DataSourceHandler.h>

Inheritance diagram for knowrob::DataSourceHandler:

Public Member Functions

 DataSourceHandler ()=default
 
virtual ~DataSourceHandler ()=default
 
void addDataHandler (const std::string &format, const DataSourceLoader &fn)
 
bool loadDataSource (const DataSourcePtr &dataSource)
 
bool hasDataHandler (const DataSourcePtr &dataSource) const
 
 DataSourceHandler ()=default
 
virtual ~DataSourceHandler ()=default
 
void addDataHandler (const std::string &format, const DataSourceLoader &fn)
 
bool loadDataSource (const DataSourcePtr &dataSource)
 
bool hasDataHandler (const DataSourcePtr &dataSource) const
 

Protected Member Functions

virtual bool loadDataSourceWithUnknownFormat (const DataSourcePtr &)
 
virtual bool loadDataSourceWithUnknownFormat (const DataSourcePtr &)
 

Protected Attributes

std::map< std::string, DataSourceLoaderdataSourceHandler_
 

Detailed Description

An object that can load data sources.

Definition at line 20 of file DataSourceHandler.h.

Constructor & Destructor Documentation

◆ DataSourceHandler() [1/2]

knowrob::DataSourceHandler::DataSourceHandler ( )
default

◆ ~DataSourceHandler() [1/2]

virtual knowrob::DataSourceHandler::~DataSourceHandler ( )
virtualdefault

◆ DataSourceHandler() [2/2]

knowrob::DataSourceHandler::DataSourceHandler ( )
default

◆ ~DataSourceHandler() [2/2]

virtual knowrob::DataSourceHandler::~DataSourceHandler ( )
virtualdefault

Member Function Documentation

◆ addDataHandler() [1/2]

void knowrob::DataSourceHandler::addDataHandler ( const std::string &  format,
const DataSourceLoader fn 
)

Add a handler for a data source format.

Parameters
formatthe format name.
fnthe handler function.

◆ addDataHandler() [2/2]

void knowrob::DataSourceHandler::addDataHandler ( const std::string &  format,
const DataSourceLoader fn 
)

Add a handler for a data source format.

Parameters
formatthe format name.
fnthe handler function.

◆ hasDataHandler() [1/2]

bool DataSourceHandler::hasDataHandler ( const DataSourcePtr dataSource) const

Check if a handler for a data source is available.

Parameters
dataSourcea data source.
Returns
true if a handler is available.

Definition at line 24 of file DataSourceHandler.cpp.

24  {
25  return dataSourceHandler_.find(dataSource->format()) != dataSourceHandler_.end();
26 }
std::map< std::string, DataSourceLoader > dataSourceHandler_

◆ hasDataHandler() [2/2]

bool knowrob::DataSourceHandler::hasDataHandler ( const DataSourcePtr dataSource) const

Check if a handler for a data source is available.

Parameters
dataSourcea data source.
Returns
true if a handler is available.

◆ loadDataSource() [1/2]

bool DataSourceHandler::loadDataSource ( const DataSourcePtr dataSource)

Load a data source. The knowledge base system calls this function for each data source that is passed to the reasoner.

Parameters
dataSourcethe data source to load.

Definition at line 11 of file DataSourceHandler.cpp.

11  {
12  if (dataSource->format().empty()) {
13  return loadDataSourceWithUnknownFormat(dataSource);
14  } else {
15  auto it = dataSourceHandler_.find(dataSource->format());
16  if (it != dataSourceHandler_.end()) {
17  return it->second(dataSource);
18  } else {
19  return false;
20  }
21  }
22 }
virtual bool loadDataSourceWithUnknownFormat(const DataSourcePtr &)

◆ loadDataSource() [2/2]

bool knowrob::DataSourceHandler::loadDataSource ( const DataSourcePtr dataSource)

Load a data source. The knowledge base system calls this function for each data source that is passed to the reasoner.

Parameters
dataSourcethe data source to load.

◆ loadDataSourceWithUnknownFormat() [1/2]

virtual bool knowrob::DataSourceHandler::loadDataSourceWithUnknownFormat ( const DataSourcePtr )
inlineprotectedvirtual

Reimplemented in knowrob::PrologReasoner, and knowrob::PrologReasoner.

Definition at line 52 of file DataSourceHandler.h.

52 { return false; }

◆ loadDataSourceWithUnknownFormat() [2/2]

virtual bool knowrob::DataSourceHandler::loadDataSourceWithUnknownFormat ( const DataSourcePtr )
inlineprotectedvirtual

Reimplemented in knowrob::PrologReasoner, and knowrob::PrologReasoner.

Definition at line 52 of file DataSourceHandler.h.

52 { return false; }

Member Data Documentation

◆ dataSourceHandler_

std::map< std::string, DataSourceLoader > knowrob::DataSourceHandler::dataSourceHandler_
protected

Definition at line 50 of file DataSourceHandler.h.


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