Library of Assembled Shared Sources
xml_o_file.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @class lass::io::XmlOFile
46 * @brief Output stream for writing a selection of geometric primitives to XML files.
47 *
48 * if you open a XmlOFile with @a iOpenMode (or without a second argument), the file is opened
49 * and that's it. Not automatic content is written to it:
50 *
51 * @code
52 * {
53 * XmlOFile a("foo.xml");
54 * a << "spam\n"
55 * }
56 *
57 * // foo.xml:
58 * // spam
59 *
60 * {
61 * XmlOFile b("bar.xml, std::ios::trunc);
62 * b << "eggs\n"
63 * }
64 *
65 * // bar.xml:
66 * // eggs
67 * @endcode
68 *
69 * However, if your second argument is the name of your root element, then a standard XML
70 * declaration will be written to it and the root element will be opened. When the file is
71 * closed, this root element will be closed automatically as well.
72 *
73 * @code
74 * {
75 * XmlOFile c("fun.xml", "root");
76 * c << "ham\n"
77 * }
78 *
79 * // fun.xml:
80 * // <?xml version="1.0"?>
81 * // <root>
82 * // ham
83 * // </root>
84 * @endcode
85 */
86
87
88
89#ifndef LASS_GUARDIAN_OF_INCLUSION_IO_XML_O_FILE_H
90#define LASS_GUARDIAN_OF_INCLUSION_IO_XML_O_FILE_H
91
92
93
94#include "io_common.h"
95#include "xml_o_stream.h"
96
97namespace lass
98{
99
100namespace io
101{
102
104class LASS_DLL XmlOFile: public XmlOStream
105{
106public:
107 XmlOFile();
108 XmlOFile(const char* iFilename, std::ios::openmode iOpenMode = std::ios::out | std::ios::trunc);
109 XmlOFile(const char* iFilename, const char* iRoot);
110 XmlOFile(const std::string& iFilename, std::ios::openmode iOpenMode = std::ios::out | std::ios::trunc);
111 XmlOFile(const std::string& iFilename, const std::string& iRoot);
112 virtual ~XmlOFile();
113
114 void open(const char* iFilename, std::ios::openmode iOpenMode = std::ios::out | std::ios::trunc);
115 void open(const char* iFilename, const char* iRoot);
116 void open(const std::string& iFilename, std::ios::openmode iOpenMode = std::ios::out | std::ios::trunc);
117 void open(const std::string& iFilename, const std::string& iRoot);
118 void close();
119 bool is_open();
120
121 XmlOFile& operator<<( char iIn ) override;
122 XmlOFile& operator<<( signed char iIn ) override;
123 XmlOFile& operator<<( unsigned char iIn ) override;
124 XmlOFile& operator<<( signed short iIn ) override;
125 XmlOFile& operator<<( unsigned short iIn ) override;
126 XmlOFile& operator<<( signed int iIn ) override;
127 XmlOFile& operator<<( unsigned int iIn ) override;
128 XmlOFile& operator<<( signed long iIn ) override;
129 XmlOFile& operator<<( unsigned long iIn ) override;
130 XmlOFile& operator<<( float iIn ) override;
131 XmlOFile& operator<<( double iIn ) override;
132 XmlOFile& operator<<( long double iIn ) override;
133 XmlOFile& operator<<( bool iIn ) override;
134 XmlOFile& operator<<( const void* iIn ) override;
135 XmlOFile& operator<<( const char* iIn ) override;
136 XmlOFile& operator<<( const std::string& iIn ) override;
137
138 XmlOFile& operator<<( std::ostream& (*iIn) (std::ostream&) ) override;
139
140private:
141
142 std::ofstream file_;
143 std::string root_;
144};
145
146
147
148}
149
150}
151
152#endif
Output stream for writing a selection of geometric primitives to XML files.
#define LASS_DLL
DLL interface: import or export symbols?
streams, binary streams, vrmlstreams, ...
Library for Assembled Shared Sources.
Definition config.h:53