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 <vector>
30 #include <iostream>
31 
32 #include "macros.h"
33 
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 
43 
45  std::pair<PropertyMapIterator,bool> result = insert(make_pair(p->name(), p));
46  return result.second;
47  }
48 
49  bool PropertyMap::eraseProperty(const std::string& name) {
50  PropertyMapIterator it=find(name);
51  if (it==end())
52  return false;
53  delete it->second;
54  erase(it);
55  return true;
56  }
57 
59  for (PropertyMapIterator it=begin(); it!=end(); it++){
60  if (it->second)
61  delete it->second;
62  }
63  }
64 
65  bool PropertyMap::updatePropertyFromString(const std::string& name, const std::string& value)
66  {
67  PropertyMapIterator it = find(name);
68  if (it == end())
69  return false;
70  it->second->fromString(value);
71  return true;
72  }
73 
74  void PropertyMap::writeToCSV(std::ostream& os) const
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  }
87 
88  bool PropertyMap::updateMapFromString(const std::string& values)
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  }
104 
105 } // end namespace
BaseClass::iterator PropertyMapIterator
Definition: property.h:79
#define __PRETTY_FUNCTION__
Definition: macros.h:95
BaseClass::const_iterator PropertyMapConstIterator
Definition: property.h:80
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)
bool addProperty(BaseProperty *p)
Definition: property.cpp:44
std::string trim(const std::string &s)
virtual ~BaseProperty()
Definition: property.cpp:42
bool updatePropertyFromString(const std::string &name, const std::string &value)
Definition: property.cpp:65
void writeToCSV(std::ostream &os) const
Definition: property.cpp:74
bool eraseProperty(const std::string &name_)
Definition: property.cpp:49
virtual std::string toString() const =0
bool updateMapFromString(const std::string &values)
Definition: property.cpp:88
const std::string & name()
Definition: property.h:42


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47