g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
stuff
property.h
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#ifndef G2O_PROPERTY_H_
28
#define G2O_PROPERTY_H_
29
30
#include <map>
31
#include <sstream>
32
#include <string>
33
34
#include "
g2o_stuff_api.h
"
35
#include "
string_tools.h
"
36
37
namespace
g2o
{
38
39
class
G2O_STUFF_API
BaseProperty
{
40
public
:
41
BaseProperty
(
const
std::string& name_);
42
virtual
~BaseProperty
();
43
const
std::string&
name
() {
return
_name
; }
44
virtual
std::string
toString
()
const
= 0;
45
virtual
bool
fromString
(
const
std::string& s) = 0;
46
47
protected
:
48
std::string
_name
;
49
};
50
51
template
<
typename
T>
52
class
Property
:
public
BaseProperty
{
53
public
:
54
typedef
T
ValueType
;
55
Property
(
const
std::string& name_) :
BaseProperty
(name_) {}
56
Property
(
const
std::string& name_,
const
T& v)
57
:
BaseProperty
(name_),
_value
(v) {}
58
void
setValue
(
const
T& v) {
_value
= v; }
59
const
T&
value
()
const
{
return
_value
; }
60
virtual
std::string
toString
()
const
{
61
std::stringstream sstr;
62
sstr <<
_value
;
63
return
sstr.str();
64
}
65
virtual
bool
fromString
(
const
std::string& s) {
66
bool
status =
convertString
(s,
_value
);
67
return
status;
68
}
69
70
protected
:
71
T
_value
;
72
};
73
77
class
G2O_STUFF_API
PropertyMap
78
:
protected
std::map<std::string, BaseProperty*> {
79
public
:
80
typedef
std::map<std::string, BaseProperty*>
BaseClass
;
81
typedef
BaseClass::iterator
PropertyMapIterator
;
82
typedef
BaseClass::const_iterator
PropertyMapConstIterator
;
83
84
~PropertyMap
();
85
89
bool
addProperty
(
BaseProperty
* p);
90
94
bool
eraseProperty
(
const
std::string& name_);
95
99
template
<
typename
P>
100
P*
getProperty
(
const
std::string& name_) {
101
PropertyMapIterator
it = find(name_);
102
if
(it == end())
return
nullptr
;
103
return
dynamic_cast<
P*
>
(it->second);
104
}
105
template
<
typename
P>
106
const
P*
getProperty
(
const
std::string& name_)
const
{
107
PropertyMapConstIterator
it = find(name_);
108
if
(it == end())
return
nullptr
;
109
return
dynamic_cast<
P*
>
(it->second);
110
}
111
115
template
<
typename
P>
116
P*
makeProperty
(
const
std::string& name_,
const
typename
P::ValueType& v) {
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
}
125
130
bool
updatePropertyFromString(
const
std::string& name,
131
const
std::string& value);
132
137
bool
updateMapFromString(
const
std::string& values);
138
139
void
writeToCSV(std::ostream& os)
const
;
140
141
using
BaseClass::begin;
142
using
BaseClass::const_iterator;
143
using
BaseClass::end;
144
using
BaseClass::iterator;
145
using
BaseClass::size;
146
};
147
148
typedef
Property<int>
IntProperty
;
149
typedef
Property<bool>
BoolProperty
;
150
typedef
Property<float>
FloatProperty
;
151
typedef
Property<double>
DoubleProperty
;
152
typedef
Property<std::string>
StringProperty
;
153
154
}
// namespace g2o
155
#endif
g2o::BaseProperty
Definition
property.h:39
g2o::BaseProperty::_name
std::string _name
Definition
property.h:48
g2o::BaseProperty::toString
virtual std::string toString() const =0
g2o::BaseProperty::BaseProperty
BaseProperty(const std::string &name_)
Definition
property.cpp:39
g2o::BaseProperty::name
const std::string & name()
Definition
property.h:43
g2o::BaseProperty::fromString
virtual bool fromString(const std::string &s)=0
g2o::PropertyMap
a collection of properties mapping from name to the property itself
Definition
property.h:78
g2o::PropertyMap::getProperty
const P * getProperty(const std::string &name_) const
Definition
property.h:106
g2o::PropertyMap::makeProperty
P * makeProperty(const std::string &name_, const typename P::ValueType &v)
Definition
property.h:116
g2o::PropertyMap::addProperty
bool addProperty(BaseProperty *p)
Definition
property.cpp:43
g2o::PropertyMap::eraseProperty
bool eraseProperty(const std::string &name_)
Definition
property.cpp:48
g2o::PropertyMap::getProperty
P * getProperty(const std::string &name_)
Definition
property.h:100
g2o::PropertyMap::BaseClass
std::map< std::string, BaseProperty * > BaseClass
Definition
property.h:80
g2o::PropertyMap::PropertyMapConstIterator
BaseClass::const_iterator PropertyMapConstIterator
Definition
property.h:82
g2o::PropertyMap::PropertyMapIterator
BaseClass::iterator PropertyMapIterator
Definition
property.h:81
g2o::Property
Definition
property.h:52
g2o::Property::ValueType
T ValueType
Definition
property.h:54
g2o::Property::Property
Property(const std::string &name_)
Definition
property.h:55
g2o::Property::setValue
void setValue(const T &v)
Definition
property.h:58
g2o::Property::fromString
virtual bool fromString(const std::string &s)
Definition
property.h:65
g2o::Property::Property
Property(const std::string &name_, const T &v)
Definition
property.h:56
g2o::Property::toString
virtual std::string toString() const
Definition
property.h:60
g2o::Property< int >::_value
int _value
Definition
property.h:71
g2o::Property::value
const T & value() const
Definition
property.h:59
g2o_stuff_api.h
G2O_STUFF_API
#define G2O_STUFF_API
Definition
g2o_stuff_api.h:56
g2o
Definition
dl_wrapper.cpp:55
g2o::BoolProperty
Property< bool > BoolProperty
Definition
property.h:149
g2o::StringProperty
Property< std::string > StringProperty
Definition
property.h:152
g2o::convertString
bool convertString(const std::string &s, T &x, bool failIfLeftoverChars=true)
Definition
string_tools.h:123
g2o::DoubleProperty
Property< double > DoubleProperty
Definition
property.h:151
g2o::IntProperty
Property< int > IntProperty
Definition
property.h:148
g2o::FloatProperty
Property< float > FloatProperty
Definition
property.h:150
string_tools.h
Generated on
for g2o by
1.17.0