MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
writer.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  *
42  * Software, Files, Libraries and all other items referenced in this clause refers only
43  * to the contents of this file and associated documentation.
44  *
45  * Pugixml parser - version 1.0
46  * --------------------------------------------------------
47  * Copyright © 2006-2012, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
48  * Report bugs and download new versions at http://pugixml.org/
49  *
50  * This library is distributed under the MIT License. See notice at the end
51  * of this file.
52  *
53  * This work is based on the pugxml parser, which is:
54  * Copyright © 2003, by Kristen Wegner (kristen@tima.net)
55  */
56 
57 #ifndef _xmlwriter_h
58 #define _xmlwriter_h
59 
60 /// @file
61 /// @brief The definitions for all of the XML::Writer inheritance hierarchy.
62 
63 #include "datatypes.h"
64 
65 #ifndef SWIG
66 #include "resource.h"
67 #endif
68 
69 namespace Mezzanine
70 {
71 
72  namespace XML
73  {
74 
75 #ifndef SWIG_SAFE
76 
77 
78  ///////////////////////////////////////////////////////////////////////////////
79  /// @brief Interface for node printing (see @ref Node::Print)
81  {
82  public:
83  /// @brief Safe to dervied doconstructor
84  virtual ~Writer() {}
85 
86  /// @brief Write memory chunk into stream/file/whatever
87  /// @param data A void pointer that could be anything, so that it does not interfere with inheritance
88  /// @param size How much to write in bytes.
89  virtual void Write(const void* data, size_t size) = 0;
90  };
91 
92 
93  ///////////////////////////////////////////////////////////////////////////////
94  /// @brief An implementation of @ref Writer intended for writing to FILEs as defined in stdio
95  class MEZZ_LIB WriterFile: public Writer
96  {
97  private:
98  /// @internal
99  /// @brief A pointer to a FILE as defined in stdio
100  void* TargetFile;
101 
102  public:
103  /// @brief Construct WriterInstance from a FILE* object; void* is used to avoid header dependencies on stdio
104  /// @param FilePtr the c style FILE* to contruct this from.
105  WriterFile(void* FilePtr);
106 
107  /// @brief Construct a Writer from a FILE* object.
108  /// @param data Data To be written to the FILE.
109  /// @param size How much data to write.
110  virtual void Write(const void* data, size_t size);
111  };
112 
113 
114  ///////////////////////////////////////////////////////////////////////////////
115  /// @class WriterStream
116  /// @brief An implementation of @ref Writer intended for writing std::ostreams
118  {
119  public:
120  /// @brief A constructor that accepts a stream of characters
121  /// @param stream A stream to send stuff to.
122  WriterStream(std::basic_ostream<char, std::char_traits<char> >& stream);
123 
124  /// @brief A constructor that accepts a stream of wide characters
125  /// @param stream A stream to send stuff to.
126  WriterStream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
127 
128  /// @brief Actually issues the write commands.
129  /// @param data A pointer to the data to write, this will assume the pointer is valid and cast it.
130  /// @param size How much to write from the pointer data, pointer.
131  virtual void Write(const void* data, size_t size);
132 
133  private:
134  /// @internal
135  std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
136  /// @internal
137  std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
138  };
139 
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  /// @class XMLStreamWrapper
143  /// @brief This represents a simple wrapper that makes data streams compatible with the XML API.
144  /// @details
145  /// @todo Ideally this class should not exist, and the XML system should be made to use the resource system instead of doing its own IO.
146  ///////////////////////////////////////
148  {
149  protected:
150  /// @brief This is the stream that will be used for output.
152  public:
153  /// @brief Class constructor.
154  /// @param Stream The stream to be wrapped.
155  XMLStreamWrapper(Resource::DataStream* Stream) : WrappedStream(Stream) {}
156 
157  /// @brief Class destructor.
158  virtual ~XMLStreamWrapper() {}
159 
160  /// @brief Writes data to the stream.
161  /// @param data The data to be written.
162  /// @param size The number of bytes to be written.
163  void Write(const void* data, size_t size) { WrappedStream->Write(data,size); }
164  };//XMLStreamWrapper
165 
166 
167  // placed here to avoid inclusion in safe swig library for scripting language.
168 
169 #endif //
170  }
171 }// /namespace Mezzanine
172 
173 #endif // Include guard
174 
175 /*
176  *
177  * Software, Files, Libraries and all other items referenced in this clause refers only
178  * to the contents of this file and associated documentation.
179  *
180  * Copyright © 2006-2012 Arseny Kapoulkine
181  *
182  * Permission is hereby granted, free of charge, to any person
183  * obtaining a copy of this software and associated documentation
184  * files (the "Software"), to deal in the Software without
185  * restriction, including without limitation the rights to use,
186  * copy, modify, merge, publish, distribute, sublicense, and/or sell
187  * copies of the Software, and to permit persons to whom the
188  * Software is furnished to do so, subject to the following
189  * conditions:
190  *
191  * The above copyright notice and this permission notice shall be
192  * included in all copies or substantial portions of the Software.
193  *
194  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
195  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
196  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
197  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
198  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
199  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
200  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
201  * OTHER DEALINGS IN THE SOFTWARE.
202  */