30 #include "../property/Property.h" 
   31 #include "../property/Properties.h" 
   32 #include "../../../common/Exception.h" 
   33 #include "../../../common/STLUtils.h" 
   34 #include "../../../common/Translator.h" 
   35 #include "../Config.h" 
   36 #include "../enum/Enums.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.c_str(), 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;  
 
  124     std::stringstream ss;
 
  127     std::string s_prop = 
"properties_"+ ss.str();
 
  129     boost::property_tree::ptree::assoc_iterator it2 = subtree.find(s_prop); 
 
  130     boost::property_tree::ptree::assoc_iterator it_nofound2 = subtree.not_found();
 
  132     if (it2 == it_nofound2)
 
  133       return propsRetrieve;
 
  135     boost::property_tree::ptree subtree1 = (*it2).second;
 
  137     boost::property_tree::ptree::assoc_iterator itName = subtree1.find(
"name");
 
  138     boost::property_tree::ptree::assoc_iterator it_nofoundName = subtree1.not_found();
 
  140     if (itName == it_nofoundName)
 
  141       return propsRetrieve;
 
  148     boost::property_tree::ptree tree;
 
  150     BOOST_FOREACH(
const boost::property_tree::ptree::value_type &v, subtree.get_child(s_prop)) 
 
  152       if(v.first.compare(
"object_type") == 0)
 
  154         EnumType* type = enumObj->getEnum(v.second.data());
 
  159       if(v.first.compare(
"type") == 0)
 
  171         std::string val = v.first;
 
  175         retrieveSubPTree(tree, prop);
 
  179     propsRetrieve.push_back(props);
 
  183   return propsRetrieve;
 
  191   boost::property_tree::ptree tree;
 
  192   BOOST_FOREACH( 
const boost::property_tree::ptree::value_type &v, subTree.get_child(
"") ) 
 
  195     if(v.first.compare(
"type") == 0)
 
  204       std::string val = v.first;
 
  210     retrieveSubPTree(tree, proper);
 
  216   return m_array.empty();
 
  221   m_loadPath = loadPath;
 
  223   std::ifstream inputFile;
 
  227     inputFile.open(m_loadPath.c_str());
 
  229     if (!inputFile.is_open())
 
  232     boost::property_tree::json_parser::read_json(inputFile, m_array);
 
  235   catch(boost::property_tree::json_parser::json_parser_error &je)
 
  237     std::string errmsg = 
"Error parsing: " + je.filename() + 
": " + je.message();
 
  242   catch (std::ifstream::failure &e) 
 
  244     std::cerr << e.what() << std::endl;
 
  245     std::string errmsg = 
"Exception opening/reading/closing file: \n ";
 
  250   catch (std::exception 
const& e)
 
  252     std::cerr << e.what() << std::endl;
 
  258   m_properties = properties;
 
  260   std::vector<te::layout::Properties*>::iterator it;
 
  261   std::vector<te::layout::Property>::iterator ity;
 
  263   boost::property_tree::ptree rootArray;
 
  264   boost::property_tree::ptree childArray;
 
  266   rootArray.add(
"name", m_rootKey);
 
  269   for(it = m_properties.begin(); it != m_properties.end(); ++it)
 
  275     std::vector<te::layout::Property> vec = props->
getProperties();
 
  283     for(ity = vec.begin(); ity != vec.end(); ++ity)
 
  290       searchProperty(prop, childArray, childArray);
 
  292     if(!childArray.empty())
 
  294       std::stringstream ss;
 
  297       std::string s_prop = 
"properties_"+ ss.str();
 
  298       rootArray.push_back(std::make_pair(s_prop, childArray));
 
  303   m_array.push_back(std::make_pair(
"template", rootArray));
 
  314     std::vector<Property>::iterator it;
 
  316     for(it = props.begin(); it != props.end(); ++it)
 
  320       boost::property_tree::ptree childArray;
 
  325       std::string s_name = prop.
getName() + 
"_child";
 
  327       child.push_back(std::make_pair(s_name,childArray));
 
  329       searchProperty(prop, array, childArray);
 
  332     std::string s_nameChild = propCopy.
getName() + 
"_child";
 
  334       array.push_back(std::make_pair(s_nameChild,child));
 
void clear()
Reset state of this object. Null state. 
 
std::string getName()
Method that returns the name of this property. 
 
Class to represent a graphic object (MVC component) and widget object (MVC widget) type enumeration...
 
virtual bool addProperty(Property property)
Adds the specified property to the set of properties for this object. 
 
Variant getValue()
Returns stored value. 
 
virtual EnumDataType * getEnumDataType()
Returns data type enumeration. 
 
void addSubProperty(Property property)
 
std::string getName()
Returns name. 
 
virtual std::string convertToString()
Converts the value to a string. 
 
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
 
virtual std::vector< Property > getProperties()
Returns set of all properties. 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
virtual void searchProperty(Property &property, boost::property_tree::ptree &array, boost::property_tree::ptree &child)
 
virtual EnumObjectType * getEnumObjectType()
Returns graphic object (MVC component) and widget object (MVC widget) type enumeration. 
 
virtual void setTypeObj(EnumType *type)
Sets object type that owns these properties. 
 
virtual void fromPtree(boost::property_tree::ptree tree, EnumType *type)
 
static Enums & getInstance()
It returns a reference to the singleton instance. 
 
virtual EnumType * getTypeObj()
Returns object type that owns these properties. 
 
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
 
Class acts like a union for some C++/TerraLib5 data types. Responsible for storing the value...
 
virtual EnumType * getEnum(int enumId) const 
Searching for a value of the enumeration by id. 
 
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
 
virtual boost::property_tree::ptree retrievePTree()
 
void setValue(ValueType value, EnumType *type)
Stores a copy of value. 
 
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
 
virtual void retrieveSubPTree(boost::property_tree::ptree subTree, Property &prop)
 
void setName(std::string name)
Sets the name of this property. 
 
Implementation of .json for Serialization. It is a JSON file. Save or change a file ...
 
virtual std::vector< te::layout::Properties * > retrieve()
 
virtual void loadFromPath(std::string loadPath)
 
std::vector< te::layout::Property > getSubProperty()
 
virtual void loadFromProperties(std::vector< te::layout::Properties * > properties)
 
EnumType * getType()
Returns the type of this property. 
 
A property acts like a attribute member of a object and stores the state of this attribute. A set of properties stores the state of an object. Any data type, not included in the convertValue method in the class te::layout::Variant, it will be by default "std::string" value.