Loading...
Searching...
No Matches
BoostUtils.h
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.h
22
23 \brief This file contains several utility functions for dealing with Boost containers and algorithms.
24
25 \ingroup common
26*/
27
28#ifndef __TERRALIB_COMMON_INTERNAL_BOOSTUTILS_H
29#define __TERRALIB_COMMON_INTERNAL_BOOSTUTILS_H
30
31// TerraLib
32#include "Config.h"
33
34// STL
35#include <map>
36#include <string>
37#include <vector>
38
39// Boost
40#include <boost/property_tree/ptree_fwd.hpp>
41#include <boost/unordered_map.hpp>
42
43
44namespace te
45{
46 namespace common
47 {
48 /*!
49 \brief This function can be applied to a map of pointers. It will delete each pointer in the map.
50
51 \param m The map of pointers to be cleaned.
52
53 \note It will not clear the map at the end of the cleanup.
54 */
55 template<class K, class V> inline void FreeContents(boost::unordered_map<K, V*>& m)
56 {
57 typename boost::unordered_map<K, V*>::const_iterator it = m.begin();
58 typename boost::unordered_map<K, V*>::const_iterator itend = m.end();
59
60 while(it != itend)
61 {
62 delete it->second;
63 ++it;
64 }
65 }
66
67 /*!
68 \brief Converts a property tree node into a std::map<std::string, std::string>.
69
70 \param p A node that can be converted to a std::map<std::string, std::string>.
71 \param dict The dictionary to output the key-value pairs.
72 */
73 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::map<std::string, std::string>& dict);
74
75 /*!
76 \brief Converts a property tree node into a std::vector<std::pair<std::string, std::string> >
77
78 \param p A node that can be converted to a std::vector<std::pair<std::string, std::string> >.
79 \param vp The vector of pairs returned.
80 */
81
82 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<std::pair<std::string, std::string> >& vp);
83
84 /*!
85 \brief Converts a property tree node into a std::vector<std::string>.
86
87 \param p A node that can be converted to a std::vector<std::string>.
88 \param vect The vector to output the values.
89 */
90 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<std::string>& vect);
91
92 /*!
93 \brief Converts a property tree node into a std::vector<unsigned char>.
94
95 \param p A node that can be converted to a std::vector<unsigned char>.
96 \param vectd The vector to output the values.
97 */
98 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<unsigned char>& vectd);
99
100 /*!
101 \brief Converts a property tree node into a std::vector<double>.
102
103 \param p A node that can be converted to a std::vector<double>.
104 \param vectd The vector to output the values.
105 */
106 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<double>& vectd);
107
108 /*!
109 \brief Converts a property tree node into a std::vector<size_t>.
110
111 \param p A node that can be converted to a std::vector<size_t>.
112 \param vectd The vector to output the values.
113 */
114 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<size_t>& vectd);
115
116 /*!
117 \brief Converts a property tree node into a std::vector<vector<std::string> >.
118
119 \param p A node that can be converted to a std::vector<vector<std::string> >.
120 \param vect The vector to output the values.
121 */
122 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<std::vector<double> >& vect);
123
124 /*!
125 \brief Converts a property tree node into a std::vector<std::map<std::string, std::string> >.
126
127 \param p A node that can be converted to a std::vector<std::map<std::string, std::string> >.
128 \param vect The vector to output the values.
129 */
130 TECOMMONEXPORT void Convert(const boost::property_tree::ptree& p, std::vector<std::map<std::string, std::string> >& vectm);
131
132 } // end namespace common
133} // end namespace te
134
135#endif // __TERRALIB_COMMON_INTERNAL_BOOSTUTILS_H
136
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map.
Definition: BoostUtils.h:55
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>.
TerraLib.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:66
Proxy configuration file for TerraView (see terraview_config.h).