All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvgParameter.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 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/serialization/se/SvgParameter.cpp
22 
23  \brief Support for SvgParameter serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/SvgParameter.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "../fe/Expression.h"
31 #include "ParameterValue.h"
32 #include "SvgParameter.h"
33 
34 // STL
35 #include <cassert>
36 #include <memory>
37 
39 {
40  assert(reader.getNodeType() == te::xml::START_ELEMENT);
41  assert(reader.getElementLocalName() == "SvgParameter");
42  assert(reader.hasAttrs());
43 
44  std::string name = reader.getAttr("name");
45  assert(!name.empty());
46 
47  std::auto_ptr<te::se::SvgParameter> svgParam(new te::se::SvgParameter(name));
48 
49  reader.next();
50 
51  // Expression TODO: (n's expressions?)
53 
54  if(reader.getNodeType() == te::xml::VALUE)
55  {
56  p->m_mixedData = new std::string(reader.getElementValue());
57  reader.next();
58  }
59  else
60  {
61  p->m_expression = Expression::getInstance().read(reader);
62  }
63 
64  svgParam->add(p);
65 
66  assert(reader.getNodeType() == te::xml::END_ELEMENT);
67  reader.next();
68 
69  return svgParam.release();
70 }
71 
73 {
74  if(p == 0)
75  return;
76 
77  writer.writeStartElement("se:SvgParameter");
78 
79  writer.writeAttribute("name", p->getName());
80 
81  Save(static_cast<const te::se::ParameterValue*>(p), writer);
82 
83  writer.writeEndElement("se:SvgParameter");
84 }
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:191
This class models a XML reader object.
Definition: Reader.h:55
virtual bool hasAttrs() const =0
It tells if the element has attributes in the case of an element node.
virtual bool next()=0
It gets the next event to be read.
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
virtual void writeAttribute(const std::string &attName, const std::string &value)
Definition: Writer.cpp:90
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node.
virtual void writeEndElement(const std::string &qName)
Definition: Writer.cpp:156
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
te::fe::Expression * m_expression
Parameter from an expression.
TESERIALIZATIONEXPORT te::se::SvgParameter * ReadSvgParameter(te::xml::Reader &reader)
std::string * m_mixedData
Parameter from a mixed data content.
virtual NodeType getNodeType() const =0
It return the type of node read.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
Definition: SvgParameter.h:48
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
std::string getName() const
virtual std::string getAttr(const std::string &name) const =0
It returns the attribute value in the case of an element node with valid attributes.
This class models a XML writer object.
Definition: Writer.h:52