g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
stuff
property.cpp
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
#include "
property.h
"
28
29
#include <iostream>
30
#include <vector>
31
32
#include "
logger.h
"
33
#include "
macros.h
"
34
#include "
string_tools.h
"
35
using namespace
std
;
36
37
namespace
g2o
{
38
39
BaseProperty::BaseProperty
(
const
std::string& name_) :
_name
(name_) {}
40
41
BaseProperty::~BaseProperty
() {}
42
43
bool
PropertyMap::addProperty
(
BaseProperty
* p) {
44
std::pair<PropertyMapIterator, bool> result = insert(make_pair(p->
name
(), p));
45
return
result.second;
46
}
47
48
bool
PropertyMap::eraseProperty
(
const
std::string& name) {
49
PropertyMapIterator
it = find(name);
50
if
(it == end())
return
false
;
51
delete
it->second;
52
erase(it);
53
return
true
;
54
}
55
56
PropertyMap::~PropertyMap
() {
57
for
(
PropertyMapIterator
it = begin(); it != end(); ++it) {
58
if
(it->second)
delete
it->second;
59
}
60
}
61
62
bool
PropertyMap::updatePropertyFromString
(
const
std::string& name,
63
const
std::string& value) {
64
PropertyMapIterator
it = find(name);
65
if
(it == end())
return
false
;
66
it->second->fromString(value);
67
return
true
;
68
}
69
70
void
PropertyMap::writeToCSV
(std::ostream& os)
const
{
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
}
82
83
bool
PropertyMap::updateMapFromString
(
const
std::string& values) {
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
}
99
100
}
// namespace g2o
g2o::BaseProperty
Definition
property.h:39
g2o::BaseProperty::_name
std::string _name
Definition
property.h:48
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::~BaseProperty
virtual ~BaseProperty()
Definition
property.cpp:41
g2o::PropertyMap::updateMapFromString
bool updateMapFromString(const std::string &values)
Definition
property.cpp:83
g2o::PropertyMap::~PropertyMap
~PropertyMap()
Definition
property.cpp:56
g2o::PropertyMap::updatePropertyFromString
bool updatePropertyFromString(const std::string &name, const std::string &value)
Definition
property.cpp:62
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::writeToCSV
void writeToCSV(std::ostream &os) const
Definition
property.cpp:70
g2o::PropertyMap::PropertyMapIterator
BaseClass::iterator PropertyMapIterator
Definition
property.h:81
G2O_DEBUG
#define G2O_DEBUG(...)
logger.h
macros.h
__PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__
Definition
macros.h:90
g2o
Definition
dl_wrapper.cpp:55
g2o::trim
std::string trim(const std::string &s)
Definition
string_tools.cpp:50
g2o::strSplit
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)
Definition
string_tools.cpp:135
std
Definition
jet.h:876
property.h
string_tools.h
Generated on
for g2o by
1.17.0