g2o
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 76 of file property.h.

Member Typedef Documentation

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

Definition at line 79 of file property.h.

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

Definition at line 81 of file property.h.

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

Definition at line 80 of file property.h.

Constructor & Destructor Documentation

g2o::PropertyMap::~PropertyMap ( )

Definition at line 58 of file property.cpp.

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

Member Function Documentation

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

add a property to the map

Definition at line 44 of file property.cpp.

References g2o::BaseProperty::name().

44  {
45  std::pair<PropertyMapIterator,bool> result = insert(make_pair(p->name(), p));
46  return result.second;
47  }
bool g2o::PropertyMap::eraseProperty ( const std::string &  name_)

remove a property from the map

Definition at line 49 of file property.cpp.

49  {
50  PropertyMapIterator it=find(name);
51  if (it==end())
52  return false;
53  delete it->second;
54  erase(it);
55  return true;
56  }
BaseClass::iterator PropertyMapIterator
Definition: property.h:80
template<typename P >
P* g2o::PropertyMap::getProperty ( const std::string &  name_)
inline

return a property by its name

Definition at line 99 of file property.h.

100  {
101  PropertyMapIterator it=find(name_);
102  if (it==end())
103  return 0;
104  return dynamic_cast<P*>(it->second);
105  }
BaseClass::iterator PropertyMapIterator
Definition: property.h:80
template<typename P >
const P* g2o::PropertyMap::getProperty ( const std::string &  name_) const
inline

Definition at line 107 of file property.h.

108  {
109  PropertyMapConstIterator it=find(name_);
110  if (it==end())
111  return 0;
112  return dynamic_cast<P*>(it->second);
113  }
BaseClass::const_iterator PropertyMapConstIterator
Definition: property.h:81
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 119 of file property.h.

References values.

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

120  {
121  PropertyMapIterator it=find(name_);
122  if (it==end()){
123  P* p=new P(name_, v);
124  addProperty(p);
125  return p;
126  } else
127  return dynamic_cast<P*>(it->second);
128  }
BaseClass::iterator PropertyMapIterator
Definition: property.h:80
bool addProperty(BaseProperty *p)
Definition: property.cpp:44
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 88 of file property.cpp.

References __PRETTY_FUNCTION__, g2o::BaseProperty::name(), g2o::strSplit(), and g2o::trim().

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

89  {
90  bool status = true;
91  vector<string> valuesMap = strSplit(values, ",");
92  for (size_t i = 0; i < valuesMap.size(); ++i) {
93  vector<string> m = strSplit(valuesMap[i], "=");
94  if (m.size() != 2) {
95  cerr << __PRETTY_FUNCTION__ << ": unable to extract name=value pair from " << valuesMap[i] << endl;
96  continue;
97  }
98  string name = trim(m[0]);
99  string value = trim(m[1]);
100  status = status && updatePropertyFromString(name, value);
101  }
102  return status;
103  }
#define __PRETTY_FUNCTION__
Definition: macros.h:89
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the explicitly state the reprensentation poses are represented by poses by VERTEX_XYZRPY In the Quaternions and other representations could be but note that it is up to the SLAM algorithm to choose the internal representation of the angles The keyword is followed by a unique vertex ID and an optional initialization of the values
Definition: protocol.txt:7
std::string trim(const std::string &s)
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)
bool updatePropertyFromString(const std::string &name, const std::string &value)
Definition: property.cpp:65
bool g2o::PropertyMap::updatePropertyFromString ( const std::string &  name,
const std::string &  value 
)

update a specfic property with a new value

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

Definition at line 65 of file property.cpp.

66  {
67  PropertyMapIterator it = find(name);
68  if (it == end())
69  return false;
70  it->second->fromString(value);
71  return true;
72  }
BaseClass::iterator PropertyMapIterator
Definition: property.h:80
void g2o::PropertyMap::writeToCSV ( std::ostream &  os) const

Definition at line 74 of file property.cpp.

References g2o::BaseProperty::name(), and g2o::BaseProperty::toString().

Referenced by main().

75  {
76  for (PropertyMapConstIterator it=begin(); it!=end(); it++){
77  BaseProperty* p =it->second;
78  os << p->name() << ", ";
79  }
80  os << std::endl;
81  for (PropertyMapConstIterator it=begin(); it!=end(); it++){
82  BaseProperty* p =it->second;
83  os << p->toString() << ", ";
84  }
85  os << std::endl;
86  }
BaseClass::const_iterator PropertyMapConstIterator
Definition: property.h:81

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