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

a collection of properties mapping from name to the property itself More...

#include <property.h>

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

Public Types

typedef std::map< std::string, BaseProperty * > BaseClass
 
typedef BaseClass::iterator PropertyMapIterator
 
typedef BaseClass::const_iterator PropertyMapConstIterator
 

Public Member Functions

 ~PropertyMap ()
 
bool addProperty (BaseProperty *p)
 
bool eraseProperty (const std::string &name_)
 
template<typename P >
P * getProperty (const std::string &name_)
 
template<typename P >
const P * getProperty (const std::string &name_) const
 
template<typename P >
P * makeProperty (const std::string &name_, const typename P::ValueType &v)
 
bool updatePropertyFromString (const std::string &name, const std::string &value)
 
bool updateMapFromString (const std::string &values)
 
void writeToCSV (std::ostream &os) const
 

Detailed Description

a collection of properties mapping from name to the property itself

Definition at line 77 of file property.h.

Member Typedef Documentation

◆ BaseClass

typedef std::map<std::string, BaseProperty*> g2o::PropertyMap::BaseClass

Definition at line 80 of file property.h.

◆ PropertyMapConstIterator

typedef BaseClass::const_iterator g2o::PropertyMap::PropertyMapConstIterator

Definition at line 82 of file property.h.

◆ PropertyMapIterator

typedef BaseClass::iterator g2o::PropertyMap::PropertyMapIterator

Definition at line 81 of file property.h.

Constructor & Destructor Documentation

◆ ~PropertyMap()

g2o::PropertyMap::~PropertyMap ( )

Definition at line 56 of file property.cpp.

56 {
57 for (PropertyMapIterator it = begin(); it != end(); ++it) {
58 if (it->second) delete it->second;
59 }
60}
BaseClass::iterator PropertyMapIterator
Definition property.h:81

Member Function Documentation

◆ addProperty()

bool g2o::PropertyMap::addProperty ( BaseProperty p)

add a property to the map

Definition at line 43 of file property.cpp.

43 {
44 std::pair<PropertyMapIterator, bool> result = insert(make_pair(p->name(), p));
45 return result.second;
46}

References g2o::BaseProperty::name().

◆ eraseProperty()

bool g2o::PropertyMap::eraseProperty ( const std::string &  name_)

remove a property from the map

Definition at line 48 of file property.cpp.

48 {
49 PropertyMapIterator it = find(name);
50 if (it == end()) return false;
51 delete it->second;
52 erase(it);
53 return true;
54}

◆ getProperty() [1/2]

template<typename P >
P * g2o::PropertyMap::getProperty ( const std::string &  name_)
inline

return a property by its name

Definition at line 100 of file property.h.

100 {
101 PropertyMapIterator it = find(name_);
102 if (it == end()) return nullptr;
103 return dynamic_cast<P*>(it->second);
104 }

Referenced by PropertiesWidget::applyProperties().

◆ getProperty() [2/2]

template<typename P >
const P * g2o::PropertyMap::getProperty ( const std::string &  name_) const
inline

Definition at line 106 of file property.h.

106 {
107 PropertyMapConstIterator it = find(name_);
108 if (it == end()) return nullptr;
109 return dynamic_cast<P*>(it->second);
110 }
BaseClass::const_iterator PropertyMapConstIterator
Definition property.h:82

◆ makeProperty()

template<typename P >
P * g2o::PropertyMap::makeProperty ( const std::string &  name_,
const typename P::ValueType &  v 
)
inline

create a property and insert it

Definition at line 116 of file property.h.

116 {
117 PropertyMapIterator it = find(name_);
118 if (it == end()) {
119 P* p = new P(name_, v);
120 addProperty(p);
121 return p;
122 } else
123 return dynamic_cast<P*>(it->second);
124 }
bool addProperty(BaseProperty *p)
Definition property.cpp:43

Referenced by main(), g2o::OptimizationAlgorithmDogleg::OptimizationAlgorithmDogleg(), g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(), g2o::OptimizationAlgorithmWithHessian::OptimizationAlgorithmWithHessian(), and g2o::DrawAction::refreshPropertyPtrs().

◆ updateMapFromString()

bool g2o::PropertyMap::updateMapFromString ( const std::string &  values)

update the map based on a name=value string, e.g., name1=val1,name2=val2

Returns
true, if it was possible to update all parameters

Definition at line 83 of file property.cpp.

83 {
84 bool status = true;
85 vector<string> valuesMap = strSplit(values, ",");
86 for (size_t i = 0; i < valuesMap.size(); ++i) {
87 vector<string> m = strSplit(valuesMap[i], "=");
88 if (m.size() != 2) {
89 G2O_DEBUG("{}: unable to extract name=value pair from {}",
90 __PRETTY_FUNCTION__, valuesMap[i]);
91 continue;
92 }
93 string name = trim(m[0]);
94 string value = trim(m[1]);
95 status = status && updatePropertyFromString(name, value);
96 }
97 return status;
98}
bool updatePropertyFromString(const std::string &name, const std::string &value)
Definition property.cpp:62
#define G2O_DEBUG(...)
Definition logger.h:90
#define __PRETTY_FUNCTION__
Definition macros.h:90
std::string trim(const std::string &s)
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)

References __PRETTY_FUNCTION__, G2O_DEBUG, g2o::strSplit(), g2o::trim(), and updatePropertyFromString().

Referenced by g2o::OptimizationAlgorithm::updatePropertiesFromString().

◆ updatePropertyFromString()

bool g2o::PropertyMap::updatePropertyFromString ( const std::string &  name,
const std::string &  value 
)

update a specific property with a new value

Returns
true if the params is stored and update was carried out

Definition at line 62 of file property.cpp.

63 {
64 PropertyMapIterator it = find(name);
65 if (it == end()) return false;
66 it->second->fromString(value);
67 return true;
68}

Referenced by updateMapFromString().

◆ writeToCSV()

void g2o::PropertyMap::writeToCSV ( std::ostream &  os) const

Definition at line 70 of file property.cpp.

70 {
71 for (auto it = cbegin(); it != cend(); ++it) {
72 if (it != cbegin()) os << ",";
73 os << it->second->name();
74 }
75 os << std::endl;
76 for (auto it = cbegin(); it != cend(); ++it) {
77 if (it != cbegin()) os << ",";
78 os << it->second->toString();
79 }
80 os << std::endl;
81}

Referenced by main().


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