32 #include "../../../../common/Exception.h"
33 #include "../../../../common/STLUtils.h"
34 #include "../../../../common/Translator.h"
39 #include <boost/property_tree/json_parser.hpp>
40 #include <boost/foreach.hpp>
41 #include "boost/system/system_error.hpp"
61 std::ostringstream buf;
64 boost::property_tree::ptree array = retrievePTree();
68 boost::property_tree::write_json (buf, array,
false);
71 std::ofstream outputFile;
72 outputFile.open(m_serializationPath, std::ios::out | std::ios::app);
76 catch(boost::property_tree::json_parser::json_parser_error &je)
78 std::string errmsg =
"Error parsing: " + je.filename() +
": " + je.message();
82 catch (std::ofstream::failure e)
84 std::cerr << e.what() << std::endl;
85 std::string errmsg =
"Exception opening/reading/closing file: \n ";
90 catch (std::exception
const& e)
92 std::cerr << e.what() << std::endl;
106 std::vector<te::layout::Properties*> propsRetrieve;
111 boost::property_tree::ptree::assoc_iterator it1 = m_array.find(
"template");
112 boost::property_tree::ptree::assoc_iterator it_nofound = m_array.not_found();
114 if (it1 == it_nofound)
115 return propsRetrieve;
117 boost::property_tree::ptree subtree = (*it1).second;
122 std::stringstream ss;
125 std::string s_prop =
"properties_"+ ss.str();
127 boost::property_tree::ptree::assoc_iterator it2 = subtree.find(s_prop);
128 boost::property_tree::ptree::assoc_iterator it_nofound2 = subtree.not_found();
130 if (it2 == it_nofound2)
131 return propsRetrieve;
133 boost::property_tree::ptree subtree1 = (*it2).second;
135 boost::property_tree::ptree::assoc_iterator itName = subtree1.find(
"name");
136 boost::property_tree::ptree::assoc_iterator it_nofoundName = subtree1.not_found();
138 if (itName == it_nofoundName)
139 return propsRetrieve;
144 boost::property_tree::ptree tree;
146 BOOST_FOREACH(
const boost::property_tree::ptree::value_type &v, subtree.get_child(s_prop))
148 if(v.first.compare(
"object_type") == 0)
154 if(v.first.compare(
"type") == 0)
163 std::string val = v.first;
167 retrieveSubPTree(tree, prop);
171 propsRetrieve.push_back(props);
175 return propsRetrieve;
181 boost::property_tree::ptree tree;
182 BOOST_FOREACH(
const boost::property_tree::ptree::value_type &v, subTree.get_child(
"") )
185 if(v.first.compare(
"type") == 0)
193 std::string val = v.first;
199 retrieveSubPTree(tree, proper);
205 return m_array.empty();
210 m_loadPath = loadPath;
212 std::ifstream inputFile;
216 inputFile.open(m_loadPath);
218 if (!inputFile.is_open())
221 boost::property_tree::json_parser::read_json(inputFile, m_array);
224 catch(boost::property_tree::json_parser::json_parser_error &je)
226 std::string errmsg =
"Error parsing: " + je.filename() +
": " + je.message();
231 catch (std::ifstream::failure &e)
233 std::cerr << e.what() << std::endl;
234 std::string errmsg =
"Exception opening/reading/closing file: \n ";
239 catch (std::exception
const& e)
241 std::cerr << e.what() << std::endl;
247 m_properties = properties;
249 std::vector<te::layout::Properties*>::iterator it;
250 std::vector<te::layout::Property>::iterator ity;
252 boost::property_tree::ptree rootArray;
253 boost::property_tree::ptree childArray;
255 rootArray.push_back(std::make_pair(
"name", m_rootKey));
258 for(it = m_properties.begin(); it != m_properties.end(); ++it)
264 std::vector<te::layout::Property> vec = props->
getProperties();
271 for(ity = vec.begin(); ity != vec.end(); ++ity)
276 searchProperty(prop, childArray);
278 if(!childArray.empty())
280 std::stringstream ss;
283 std::string s_prop =
"properties_"+ ss.str();
284 rootArray.push_back(std::make_pair(s_prop, childArray));
288 m_array.push_back(std::make_pair(
"template", rootArray));
295 std::vector<Property> props =
property.getSubProperty();
297 std::vector<Property>::iterator it;
299 for(it = props.begin(); it != props.end(); ++it)
303 boost::property_tree::ptree childArray;
306 array.push_back(std::make_pair(
"child",childArray));
308 searchProperty(prop, childArray);
virtual void searchProperty(Property property, boost::property_tree::ptree array)
virtual bool addProperty(Property property)
void addSubProperty(Property property)
std::string convertToString()
std::string getLayoutAbstractObjectType(int enumVal)
virtual std::vector< Property > getProperties()
void setValue(typename ValueType value, LayoutPropertyDataType type)
std::string getLayoutPropertyDataType(int enumVal)
virtual LayoutAbstractObjectType getTypeObj()
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
virtual boost::property_tree::ptree retrievePTree()
#define TR_LAYOUT(message)
It marks a string in order to get translated. This is a special mark used in the Terrralib Layout mod...
virtual void retrieveSubPTree(boost::property_tree::ptree subTree, Property &prop)
LayoutPropertyDataType getType()
void setName(std::string name)
virtual std::vector< te::layout::Properties * > retrieve()
virtual void setTypeObj(LayoutAbstractObjectType type)
virtual void loadFromPath(std::string loadPath)
std::vector< te::layout::Property > getSubProperty()
virtual void loadFromProperties(std::vector< te::layout::Properties * > properties)