All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Unique.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/Unique.cpp
22 
23  \brief Support for Unique serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/Unique.h"
30 #include "Field.h"
31 #include "Selector.h"
32 #include "Unique.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 #include <string>
39 
41 {
42  assert(reader.getNodeType() == te::xml::START_ELEMENT);
43  assert(reader.getElementLocalName() == "unique");
44 
45  std::auto_ptr<te::xsd::Unique> unique(new te::xsd::Unique(0));
46 
47  // Id
48  ReadIdentifiable(unique.get(), reader);
49 
50  // Name
51  std::size_t pos = reader.getAttrPosition("name");
52  assert(pos != std::string::npos);
53  unique->setName(new std::string(reader.getAttr(pos)));
54 
55  reader.next();
56 
57  // Grammar: (annotation?,(selector,field+))
58 
59  // Annotation
60  ReadAnnotated(unique.get(), reader);
61 
62  // Selector
63  if(reader.getElementLocalName() == "selector")
64  {
65  unique->setSelector(ReadSelector(reader));
66  return unique.release();
67  }
68 
69  // Fields
70  while(reader.getNodeType() == te::xml::START_ELEMENT && reader.getElementLocalName() == "field")
71  unique->addField(ReadField(reader));
72 
73  assert(reader.getNodeType() == te::xml::END_ELEMENT);
74  reader.next();
75 
76  return unique.release();
77 }
78 
80 {
81 }
Support for Selector serialization.
TESERIALIZATIONEXPORT te::xsd::Unique * ReadUnique(te::xml::Reader &reader)
Definition: Unique.cpp:40
This class models a XML reader object.
Definition: Reader.h:55
Support for Field serialization.
virtual bool next()=0
It gets the next event to be read.
void ReadAnnotated(te::xsd::Annotated *annotated, te::xml::Reader &reader)
Definition: Utils.cpp:50
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
TESERIALIZATIONEXPORT te::xsd::Field * ReadField(te::xml::Reader &reader)
Definition: Field.cpp:38
void ReadIdentifiable(te::xsd::Identifiable *identifiable, te::xml::Reader &reader)
Definition: Utils.cpp:41
TESERIALIZATIONEXPORT te::xsd::Selector * ReadSelector(te::xml::Reader &reader)
Definition: Selector.cpp:38
It models the unique element in an XML Schema.
Definition: Unique.h:43
Utility methods for Schema serialization.
Support for Unique serialization.
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.
virtual std::size_t getAttrPosition(const std::string &name) const =0
It returns the attribute position.
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