g2o
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
g2o::ParameterContainer Class Reference

map id to parameters More...

#include <parameter_container.h>

Inheritance diagram for g2o::ParameterContainer:
Inheritance graph
[legend]
Collaboration diagram for g2o::ParameterContainer:
Collaboration graph
[legend]

Public Types

typedef std::map< int, Parameter * > BaseClass
 

Public Member Functions

 ParameterContainer (bool isMainStorage_=true)
 
virtual ~ParameterContainer ()
 
bool addParameter (Parameter *p)
 add parameter to the container
 
ParametergetParameter (int id)
 return a parameter based on its ID
 
const ParametergetParameter (int id) const
 return a parameter based on its ID
 
ParameterdetachParameter (int id)
 remove a parameter from the container, i.e., the user now owns the pointer
 
virtual bool read (std::istream &is, const std::map< std::string, std::string > *renamedMap=0)
 read parameters from a stream
 
virtual bool write (std::ostream &os) const
 write the data to a stream
 
bool isMainStorage () const
 
void clear ()
 

Protected Attributes

bool _isMainStorage
 

Detailed Description

map id to parameters

Definition at line 41 of file parameter_container.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 43 of file parameter_container.h.

Constructor & Destructor Documentation

◆ ParameterContainer()

g2o::ParameterContainer::ParameterContainer ( bool  isMainStorage_ = true)

create a container for the parameters.

Parameters
isMainStorage_pointers to the parameters are owned by this container, i.e., freed in its constructor

Definition at line 43 of file parameter_container.cpp.

44 : _isMainStorage(isMainStorage_) {}

◆ ~ParameterContainer()

g2o::ParameterContainer::~ParameterContainer ( )
virtual

Definition at line 54 of file parameter_container.cpp.

References clear().

Member Function Documentation

◆ addParameter()

bool g2o::ParameterContainer::addParameter ( Parameter p)

add parameter to the container

Definition at line 56 of file parameter_container.cpp.

56 {
57 if (p->id() < 0) return false;
58 iterator it = find(p->id());
59 if (it != end()) return false;
60 insert(make_pair(p->id(), p));
61 return true;
62}

References g2o::Parameter::id().

Referenced by read().

◆ clear()

void g2o::ParameterContainer::clear ( )

Definition at line 46 of file parameter_container.cpp.

46 {
47 if (!_isMainStorage) return;
48 for (iterator it = begin(); it != end(); ++it) {
49 delete it->second;
50 }
51 BaseClass::clear();
52}

References _isMainStorage.

Referenced by g2o::OptimizableGraph::clearParameters(), and ~ParameterContainer().

◆ detachParameter()

Parameter * g2o::ParameterContainer::detachParameter ( int  id)

remove a parameter from the container, i.e., the user now owns the pointer

Definition at line 76 of file parameter_container.cpp.

76 {
77 iterator it = find(id);
78 if (it == end()) return nullptr;
79 Parameter* p = it->second;
80 erase(it);
81 return p;
82}

◆ getParameter() [1/2]

Parameter * g2o::ParameterContainer::getParameter ( int  id)

return a parameter based on its ID

Definition at line 64 of file parameter_container.cpp.

64 {
65 iterator it = find(id);
66 if (it == end()) return nullptr;
67 return it->second;
68}

◆ getParameter() [2/2]

const Parameter * g2o::ParameterContainer::getParameter ( int  id) const

return a parameter based on its ID

Definition at line 70 of file parameter_container.cpp.

70 {
71 const_iterator it = find(id);
72 if (it == end()) return nullptr;
73 return it->second;
74}

◆ isMainStorage()

bool g2o::ParameterContainer::isMainStorage ( ) const
inline

Definition at line 65 of file parameter_container.h.

65{ return _isMainStorage; }

References _isMainStorage.

◆ read()

bool g2o::ParameterContainer::read ( std::istream &  is,
const std::map< std::string, std::string > *  renamedMap = 0 
)
virtual

read parameters from a stream

Definition at line 95 of file parameter_container.cpp.

97 {
98 stringstream currentLine;
99 string token;
100
101 Factory* factory = Factory::instance();
103 elemBitset[HyperGraph::HGET_PARAMETER] = 1;
104
105 while (1) {
106 int bytesRead = readLine(is, currentLine);
107 if (bytesRead == -1) break;
108 currentLine >> token;
109 if (bytesRead == 0 || token.size() == 0 || token[0] == '#') continue;
110 if (_renamedTypesLookup && _renamedTypesLookup->size() > 0) {
111 map<string, string>::const_iterator foundIt =
112 _renamedTypesLookup->find(token);
113 if (foundIt != _renamedTypesLookup->end()) {
114 token = foundIt->second;
115 }
116 }
117
118 HyperGraph::HyperGraphElement* element =
119 factory->construct(token, elemBitset);
120 if (!element) // not a parameter or otherwise unknown tag
121 continue;
122 assert(element->elementType() == HyperGraph::HGET_PARAMETER &&
123 "Should be a param");
124
125 Parameter* p = static_cast<Parameter*>(element);
126 int pid;
127 currentLine >> pid;
128 p->setId(pid);
129 bool r = p->read(currentLine);
130 if (!r) {
131 G2O_ERROR("{}: Error reading data {} for parameter {}",
133 delete p;
134 } else {
135 if (!addParameter(p)) {
136 G2O_ERROR("{}: Parameter of type: {} id: {} already defined",
138 }
139 }
140 } // while read line
141
142 return true;
143}
static Factory * instance()
return the instance
Definition factory.cpp:46
std::bitset< HyperGraph::HGET_NUM_ELEMS > GraphElemBitset
Definition hyper_graph.h:70
bool addParameter(Parameter *p)
add parameter to the container
SlamParser::Parser::token token
#define G2O_ERROR(...)
Definition logger.h:89
#define __PRETTY_FUNCTION__
Definition macros.h:90
int readLine(std::istream &is, std::stringstream &currentLine)

References __PRETTY_FUNCTION__, addParameter(), g2o::Factory::construct(), g2o::HyperGraph::HyperGraphElement::elementType(), G2O_ERROR, g2o::Factory::instance(), g2o::Parameter::read(), g2o::readLine(), and g2o::Parameter::setId().

◆ write()

bool g2o::ParameterContainer::write ( std::ostream &  os) const
virtual

write the data to a stream

Definition at line 84 of file parameter_container.cpp.

84 {
85 Factory* factory = Factory::instance();
86 for (const_iterator it = begin(); it != end(); ++it) {
87 os << factory->tag(it->second) << " ";
88 os << it->second->id() << " ";
89 it->second->write(os);
90 os << endl;
91 }
92 return true;
93}

References g2o::Factory::instance(), and g2o::Factory::tag().

Member Data Documentation

◆ _isMainStorage

bool g2o::ParameterContainer::_isMainStorage
protected

Definition at line 72 of file parameter_container.h.

Referenced by clear(), and isMainStorage().


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