All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Writer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 // TerraLib
21 #include "Writer.h"
22 
23 // STL
24 #include <iostream>
25 
26 // Boost
27 #include <boost/lexical_cast.hpp>
28 
29 te::xml::Writer::Writer(std::ostream& ostr)
30  : m_ostr(ostr),
31  m_isOpened(false)
32 {
33 }
34 
36 {
37 }
38 
39 void te::xml::Writer::writeStartDocument(const std::string& encoding, const std::string& standalone)
40 {
41  m_ostr << "<?xml version=\"1.0\" encoding=\"" << encoding << "\" standalone=\"" << standalone << "\"?>";
42 }
43 
44 void te::xml::Writer::writeStartElement(const std::string& qName)
45 {
46  if(m_isOpened)
47  m_ostr << ">";
48 
49  m_ostr << "<" << qName;
50 
51  m_isOpened = true;
52 }
53 
54 void te::xml::Writer::writeElement(const std::string& qName, const std::string& value)
55 {
56  if(m_isOpened)
57  {
58  m_ostr << ">";
59  m_isOpened = false;
60  }
61 
62  m_ostr << "<" << qName << ">" << value << "</" << qName << ">";
63 }
64 
65 void te::xml::Writer::writeElement(const std::string& qName, const double& value)
66 {
67  writeElement(qName, boost::lexical_cast<std::string>(value));
68 }
69 
70 void te::xml::Writer::writeElement(const std::string& qName, boost::int32_t value)
71 {
72  writeElement(qName, boost::lexical_cast<std::string>(value));
73 }
74 
75 void te::xml::Writer::writeElement(const std::string& qName, boost::uint32_t value)
76 {
77  writeElement(qName, boost::lexical_cast<std::string>(value));
78 }
79 
80 void te::xml::Writer::writeElement(const std::string& qName, boost::int64_t value)
81 {
82  writeElement(qName, boost::lexical_cast<std::string>(value));
83 }
84 
85 void te::xml::Writer::writeElement(const std::string& qName, boost::uint64_t value)
86 {
87  writeElement(qName, boost::lexical_cast<std::string>(value));
88 }
89 
90 void te::xml::Writer::writeAttribute(const std::string& attName, const std::string& value)
91 {
92  m_ostr << " " << attName << "=\"" << value << "\"";
93 }
94 
95 void te::xml::Writer::writeAttribute(const std::string& attName, const double& value)
96 {
97  writeAttribute(attName, boost::lexical_cast<std::string>(value));
98 }
99 
100 void te::xml::Writer::writeAttribute(const std::string& attName, boost::int32_t value)
101 {
102  writeAttribute(attName, boost::lexical_cast<std::string>(value));
103 }
104 
105 void te::xml::Writer::writeAttribute(const std::string& attName, boost::uint32_t value)
106 {
107  writeAttribute(attName, boost::lexical_cast<std::string>(value));
108 }
109 
110 void te::xml::Writer::writeAttribute(const std::string& attName, boost::int64_t value)
111 {
112  writeAttribute(attName, boost::lexical_cast<std::string>(value));
113 }
114 
115 void te::xml::Writer::writeAttribute(const std::string& attName, boost::uint64_t value)
116 {
117  writeAttribute(attName, boost::lexical_cast<std::string>(value));
118 }
119 
120 void te::xml::Writer::writeValue(const std::string& value)
121 {
122  if(m_isOpened)
123  {
124  m_ostr << ">";
125  m_isOpened = false;
126  }
127 
128  m_ostr << value;
129 }
130 
131 void te::xml::Writer::writeValue(const double& value)
132 {
133  writeValue(boost::lexical_cast<std::string>(value));
134 }
135 
136 void te::xml::Writer::writeValue(boost::int32_t value)
137 {
138  writeValue(boost::lexical_cast<std::string>(value));
139 }
140 
141 void te::xml::Writer::writeValue(boost::uint32_t value)
142 {
143  writeValue(boost::lexical_cast<std::string>(value));
144 }
145 
146 void te::xml::Writer::writeValue(boost::int64_t value)
147 {
148  writeValue(boost::lexical_cast<std::string>(value));
149 }
150 
151 void te::xml::Writer::writeValue(boost::uint64_t value)
152 {
153  writeValue(boost::lexical_cast<std::string>(value));
154 }
155 
156 void te::xml::Writer::writeEndElement(const std::string& qName)
157 {
158  if(m_isOpened)
159  {
160  m_ostr << ">";
161  m_isOpened = false;
162  }
163 
164  m_ostr << "</" << qName << ">";
165 }
166 
167 //void te::xml::Writer::writeEndDocument(std::ostream& ostr)
168 //{
169 //
170 //}
171 
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
virtual void writeStartDocument(const std::string &encoding, const std::string &standalone)
Definition: Writer.cpp:39
virtual void writeAttribute(const std::string &attName, const std::string &value)
Definition: Writer.cpp:90
virtual void writeValue(const std::string &value)
Definition: Writer.cpp:120
virtual void writeElement(const std::string &qName, const std::string &value)
Definition: Writer.cpp:54
Writer(std::ostream &ostr)
Constructor.
Definition: Writer.cpp:29
virtual ~Writer()
Virtual destructor.
Definition: Writer.cpp:35
This class models a XML writer object.
virtual void writeEndElement(const std::string &qName)
Definition: Writer.cpp:156