BoostUtils.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/BoostUtils.cpp
22 
23  \brief This file contains several utility functions for dealing with Boost containers and algorithms.
24 */
25 
26 // TerraLib
27 #include "BoostUtils.h"
28 
29 // Boost
30 #include <boost/lexical_cast.hpp>
31 #include <boost/property_tree/ptree.hpp>
32 
33 
34 //class std::locale::id boost::locale::info::id;
35 
36 void te::common::Convert(const boost::property_tree::ptree& p, std::map<std::string, std::string>& dict)
37 {
38  for(const boost::property_tree::ptree::value_type& v : p)
39  {
40  for(const boost::property_tree::ptree::value_type& v2 : v.second.get_child(""))
41  {
42  const std::string& f = v2.first;
43  const std::string& s = v2.second.data();
44 
45  dict[f] = s;
46  }
47  }
48 }
49 
50 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<std::pair<std::string, std::string> > & vp)
51 {
52  for(const boost::property_tree::ptree::value_type& v : p)
53  {
54  for(const boost::property_tree::ptree::value_type& v2 : v.second.get_child(""))
55  {
56  std::pair<std::string, std::string> in_pair;
57  in_pair.first = v2.first;
58  in_pair.second = v2.second.data();
59  vp.push_back(in_pair);
60  }
61  }
62 }
63 
64 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<std::string>& vect)
65 {
66  for(const boost::property_tree::ptree::value_type& v : p)
67  {
68  vect.push_back(v.second.data());
69  continue;
70  }
71 }
72 
73 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<unsigned char>& vectd)
74 {
75  for(const boost::property_tree::ptree::value_type& v : p)
76  {
77  vectd.push_back(boost::lexical_cast<unsigned char>(v.second.data()));
78  continue;
79  }
80 }
81 
82 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<double>& vectd)
83 {
84  for(const boost::property_tree::ptree::value_type& v : p)
85  {
86  vectd.push_back(boost::lexical_cast<double>(v.second.data()));
87  continue;
88  }
89 }
90 
91 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<size_t>& vect)
92 {
93  for(const boost::property_tree::ptree::value_type& v : p)
94  {
95  vect.push_back(boost::lexical_cast<size_t>(v.second.data()));
96  continue;
97  }
98 }
99 
100 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<std::vector<double> >& vect)
101 {
102  for(const boost::property_tree::ptree::value_type& v : p)
103  {
104  for(const boost::property_tree::ptree::value_type& v2 : v.second.get_child(""))
105  {
106  std::vector<double> envrep;
107  te::common::Convert(v2.second.get_child(""), envrep);
108  vect.push_back(envrep);
109  }
110  }
111 }
112 
113 void te::common::Convert(const boost::property_tree::ptree& p, std::vector<std::map<std::string, std::string> >& vectm)
114 {
115  for(const boost::property_tree::ptree::value_type& v : p)
116  {
117  // used to get the properties parameters into a map
118  std::map<std::string, std::string> dict;
119  for(const boost::property_tree::ptree::value_type& v2: v.second.get_child(""))
120  {
121  const std::string& f = v2.first;
122  const std::string& s = v2.second.data();
123 
124  dict[f] = s;
125  }
126  vectm.push_back(dict);
127  }
128 }
TECOMMONEXPORT void Convert(const boost::property_tree::ptree &p, std::map< std::string, std::string > &dict)
Converts a property tree node into a std::map<std::string, std::string>.
Definition: BoostUtils.cpp:36
te::gm::Polygon * p
This file contains several utility functions for dealing with Boost containers and algorithms...