All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
JSONTemplate.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 JSONTemplate.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "JSONTemplate.h"
30 #include "../property/Properties.h"
31 #include "../serialization/JSON.h"
32 #include "../enum/Enums.h"
33 
34 // STL
35 #include <iostream>
36 #include <fstream>
37 
39  AbstractTemplate(path)
40 {
41  m_type = Enums::getInstance().getEnumTemplateType()->getJsonType();
42 }
43 
45 {
46 
47 }
48 
49 bool te::layout::JSONTemplate::exportTemplate( std::vector<te::layout::Properties*> properties )
50 {
51  bool is_save = false;
52  /*If the file is opened for output operations and it already existed,
53  its previous content is deleted */
54  std::ofstream outputFile;
55  outputFile.open(m_path.c_str(), std::ios::trunc);
56  outputFile.close();
57 
58  JSON* json = new JSON;
59  json->loadFromProperties(properties);
60  json->setSerializationPath(m_path);
61 
62  is_save = json->serialize();
63 
64  if(json)
65  {
66  delete json;
67  json = 0;
68  }
69 
70  return is_save;
71 }
72 
73 std::vector<te::layout::Properties*> te::layout::JSONTemplate::importTemplate()
74 {
75  JSON* json = new JSON;
76  json->loadFromPath(m_path);
77  json->setSerializationPath(m_path);
78 
79  std::vector<te::layout::Properties*> props = json->retrieve();
80 
81  if(json)
82  {
83  delete json;
84  json = 0;
85  }
86 
87  return props;
88 }
89 
91 {
92  return true;
93 }
94 
95 
Implementation of .json for Serialization. It is a JSON file. Save or change a file ...
Definition: JSON.h:53
JSONTemplate(std::string path)
virtual bool exportTemplate(std::vector< te::layout::Properties * > properties)
virtual bool serialize()
Definition: JSON.cpp:59
Implementation of AbstractTemplate. Template that creates, saves, or change a .json file...
static Enums & getInstance()
It returns a reference to the singleton instance.
virtual void setSerializationPath(std::string path)
virtual std::vector< te::layout::Properties * > importTemplate()
Abstract class that represents a Template.
virtual bool deleteTemplate()
virtual std::vector< te::layout::Properties * > retrieve()
Definition: JSON.cpp:104
virtual void loadFromPath(std::string loadPath)
Definition: JSON.cpp:219
virtual void loadFromProperties(std::vector< te::layout::Properties * > properties)
Definition: JSON.cpp:256