2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAStreamWriter.
6
Licensed under the MIT Open Source License,
7
for details please see LICENSE file or the website
8
http://www.opensource.org/licenses/mit-license.php
11
#ifndef __COLLADASTREAMWRITER_H__
12
#define __COLLADASTREAMWRITER_H__
14
#include <COLLADABUPlatform.h>
16
#include "COLLADASWPrerequisites.h"
17
#include "COLLADASWColor.h"
27
#define WHITESPACESTRINGLENGTH 1000
36
class FWriteBufferFlusher;
37
class CharacterBuffer;
45
typedef unsigned long ElementIndexType;
48
/** Class that simplifies closes open elements*/
55
/** We use the default copy ctor.*/
58
/** Closes all elements that have been open and not closed, since this object has been instantiated*/
61
TagCloser & operator= ( const TagCloser & other );
64
friend class StreamWriter;
65
TagCloser ( StreamWriter * streamWriter, ElementIndexType elementIndex );
67
StreamWriter * mStreamWriter;
68
ElementIndexType mElementIndex; //!< the index of the open tag
72
/** A class to write a COLLADASW document directly to a file, without storing the data in an internal data model*/
83
/** Contains information about an open tag*/
86
OpenTag ( const String* name, ElementIndexType elementIndex )
88
, mElementIndex( elementIndex )
89
, mHasContents( false )
93
const String* mName; //!< The name of the tag
94
ElementIndexType mElementIndex; //!< the index of the open tag
95
bool mHasContents; //!< true, if contents, i.e. elements or text has been added to the element
96
bool mHasText; //!< true, if text has been added to the element
99
typedef std::deque<OpenTag> OpenTagStack;
102
Common::FWriteBufferFlusher* mBufferFlusher;
104
Common::CharacterBuffer* mCharacterBuffer;
106
/** If true, the double values will be exported with a maximum precision of 20 digits. */
107
bool mDoublePrecision;
109
OpenTagStack mOpenTags; //!< A stack that holds all the open tags.
115
static const int FWRITEBUFFERSIZE;
117
static const int CHARACTERBUFFERSIZE;
119
static const String mWhiteSpaceString;
121
friend class TagCloser;
123
/** Each element gets a continuous index. This is the index the next opened element gets.*/
124
ElementIndexType mNextElementIndex;
126
/** The version of the COLLADA file.*/
127
COLLADAVersion mCOLLADAVersion;
130
/** Creates a stream writer that writes to file @a fileName*/
131
StreamWriter ( const NativeString& fileName, bool doublePrecision = false, COLLADAVersion cOLLADAVersion = COLLADA_1_4_1);
133
/** Closes all open tags and closes the stream*/
136
/** Writes the document start, including the opening @a \<COLLADASW\> element.
137
This member must be called, before any other member function can be called.*/
138
void startDocument();
140
/** Closes all open tags*/
143
/** Adds the attribute @a name with value "#" plus @a value to the last opened element.
144
This function can only be called after openElement() before any content is written.*/
145
void appendURIAttribute ( const String& name, const URI& value );
147
/** Adds the attribute @a name with value @a value to the last opened element.
148
This function can only be called after openElement() before any content is written.*/
149
void appendAttribute ( const String& name, const String& value );
151
/** Adds the attribute @a name with value @a value to the last opened element.
152
This function can only be called after openElement() before any content is written.*/
153
void appendAttribute ( const String& name, const double value );
155
/** Adds the attribute @a name with value @a value to the last opened element.
156
This function can only be called after openElement() before any content is written.*/
157
void appendAttribute ( const String& name, const unsigned long value );
159
/** Adds the attribute @a name with value @a value to the last opened element.
160
This function can only be called after openElement() before any content is written.*/
161
void appendAttribute ( const String& name, const unsigned int value );
163
/** Adds the attribute @a name with value @a value to the last opened element.
164
This function can only be called after openElement() before any content is written.*/
165
void appendAttribute ( const String& name, const int value );
167
/** Adds @a text to the COLLADASW file.
168
No checks are performed, if @a text contains forbidden characters. */
169
void appendText ( const String& text );
171
/** Adds @a text to the COLLADASW file in a new line.
172
No checks are performed, if @a text contains forbidden characters. */
173
void appendTextBlock ( const String& text );
175
/** Adds @a number to the COLLADASW file.*/
176
void appendValues ( const double number );
178
/** Adds @a number1 and @a number2 to the COLLADASW file.*/
179
void appendValues ( const double number1, const double number2 );
181
/** Adds @a number1, @a number2 and @a number3 to the COLLADASW file.*/
182
void appendValues ( const double number1, const double number2, const double number3 );
184
/** Adds @a number1, @a number2, @a number3 and @a number4 to the COLLADASW file.*/
185
void appendValues ( const double number1, const double number2, const double number3, const double number4 );
187
/** Adds @a number to the COLLADASW file.*/
188
void appendValues ( const float number );
190
/** Adds @a number1 and @a number2 to the COLLADASW file.*/
191
void appendValues ( const float number1, const float number2 );
193
/** Adds @a number1, @a number2 and @a number3 to the COLLADASW file.*/
194
void appendValues ( const float number1, const float number2, const float number3 );
196
/** Adds @a number1, @a number2, @a number3 and @a number4 to the COLLADASW file.*/
197
void appendValues ( const float number1, const float number2, const float number3, const float number4 );
199
/** Adds all values in the array to the COLLADASW file.*/
200
void appendValues ( const float values[], const size_t length );
202
/** Adds all values in the array to the COLLADASW file.*/
203
void appendValues ( const int values[], const size_t length );
205
/** Adds all values in the array to the COLLADASW file.*/
206
void appendValues ( const double values[], const size_t length );
208
/** Adds all values in the array to the COLLADASW file.*/
209
void appendValues ( const float matrix[4][4] );
211
/** Adds all values in the array to the COLLADASW file.*/
212
void appendValues ( const double matrix[4][4] );
214
/** Adds all values in the array to the COLLADASW file.*/
215
void appendValues ( const std::vector<float>& values );
217
/** Adds all values in the array to the COLLADASW file.*/
218
void appendValues ( const std::vector<double>& values );
220
/** Adds all values in the array to the COLLADASW file.*/
221
void appendValues ( const std::vector<String>& values );
223
/** Adds all values in the array to the COLLADASW file.*/
224
void appendValues ( const std::vector<unsigned long>& values );
226
/** Adds @a number to the COLLADASW file.*/
227
void appendValues ( int number );
229
/** Adds @a number to the COLLADASW file.*/
230
void appendValues ( int number, int number2 );
232
/** Adds @a number to the COLLADASW file.*/
233
void appendValues ( unsigned int number );
235
/** Adds @a number to the COLLADASW file.*/
236
void appendValues ( unsigned int number, unsigned int number2 );
238
/** Adds @a number to the COLLADASW file.*/
239
void appendValues ( long number );
241
/** Adds @a number1 and @a number2 to the COLLADASW file.*/
242
void appendValues ( long number1, long number2 );
244
/** Adds @a number1, @a number2 and @a number3 to the COLLADASW file.*/
245
void appendValues ( long number1, long number2, long number3 );
247
/** Adds @a number1, @a number2, @a number3 and @a number4 to the COLLADASW file.*/
248
void appendValues ( long number1, long number2, long number3, long number4 );
250
/** Adds @a number to the COLLADASW file.*/
251
void appendValues ( unsigned long number );
253
/** Adds @a number1 and @a number2 to the COLLADASW file.*/
254
void appendValues ( unsigned long number1, unsigned long number2 );
256
/** Adds @a number1, @a number2 and @a number3 to the COLLADASW file.*/
257
void appendValues ( unsigned long number1, unsigned long number2, unsigned long number3 );
259
/** Adds @a number1, @a number2, @a number3 and @a number4 to the COLLADASW file.*/
260
void appendValues ( unsigned long number1, unsigned long number2, unsigned long number3, unsigned long number4 );
262
/** Adds @a number to the COLLADASW file.*/
263
void appendValues ( long long number );
265
/** Adds @a number1 and @a number2 to the COLLADASW file.*/
266
void appendValues ( long long number1, long long number2 );
268
/** Adds @a number1, @a number2 and @a number3 to the COLLADASW file.*/
269
void appendValues ( long long number1, long long number2, long long number3 );
271
/** Adds @a number1, @a number2, @a number3 and @a number4 to the COLLADASW file.*/
272
void appendValues ( long long number1, long long number2, long long number3, long long number4 );
274
/** Adds @a number to the COLLADASW file.*/
275
void appendValues ( unsigned long long number );
277
/** Adds @a number1 and @a number2 to the COLLADASW file.*/
278
void appendValues ( unsigned long long number1, unsigned long long number2 );
280
/** Adds @a number1, @a number2 and @a number3 to the COLLADASW file.*/
281
void appendValues ( unsigned long long number1, unsigned long long number2, unsigned long long number3 );
283
/** Adds @a number1, @a number2, @a number3 and @a number4 to the COLLADASW file.*/
284
void appendValues ( unsigned long long number1, unsigned long long number2, unsigned long long number3, unsigned long long number4 );
286
/** Adds the float @a number to the COLLADASW file.*/
287
void appendValues ( bool value );
289
/** Adds the float @a number to the COLLADASW file.*/
290
void appendValues ( const Color& value );
292
/** Adds @a text to the COLLADASW file.
293
No checks are performed, if @a text contains forbidden characters. */
294
void appendValues ( const String& text );
296
/** Adds @a text to the COLLADASW file.
297
No checks are performed, if @a text contains forbidden characters. */
298
void appendValues ( const char* text );
300
/** Adds @a text to the COLLADASW file.
301
No checks are performed, if @a text contains forbidden characters. */
302
void appendValues ( const char* text, size_t length );
304
/** Opens a new element with the name @a name.
305
The string must persist at least until the corresponding closeElement() member is called.*/
306
TagCloser openElement ( const String& name );
308
/** Closes the previously opened element. */
311
/** Adds an element with name @a elementName that contains only @a text.*/
312
void appendTextElement ( const String& elementName, const String& text );
314
/** Adds an element with name @a elementName that contains only @a text.*/
315
void appendURIElement ( const String& elementName, const URI& text );
317
/** Returns the version of the COLLADA file that ias written by the StreamWriter.*/
318
COLLADAVersion getCOLLADAVersion() const { return mCOLLADAVersion; }
322
/** Closes all elements opened since the element with index @a elementIndex has been open,
323
including the element itself. */
324
void closeElements( ElementIndexType elementIndex );
326
/** Adds the string @a str to the stream.*/
327
inline void appendString ( const String & str )
329
appendNCNameString(str);
332
/** Adds the string @a str to the stream.*/
333
inline void appendString ( const char* text )
335
appendString(text, strlen(text));
338
/** Adds the string @a str to the stream.*/
339
void appendString ( const char* text, size_t length );
341
/** Adds the string @a str to the stream.
342
The string have to be a valid ncname. */
343
void appendNCNameString ( const String & str );
345
/** Adds the first @n characters of string @a str to the stream.
346
@a n must not be larger than the length of @a str.*/
347
void appendNCNameString ( const String & str, size_t n );
350
/** Adds the char @a c to the stream*/
351
void appendChar ( char c );
353
/** Adds the double @a number to the stream*/
354
void appendNumber ( double number );
356
/** Adds the float @a number to the stream*/
357
void appendNumber ( float number );
359
/** Adds the long @a number to the stream*/
360
void appendNumber ( int number );
362
/** Adds the long @a number to the stream*/
363
void appendNumber ( unsigned int number );
365
/** Adds the long @a number to the stream*/
366
void appendNumber ( long number );
368
/** Adds the long @a number to the stream*/
369
void appendNumber ( unsigned long number );
371
/** Adds the long long @a number to the stream*/
372
void appendNumber ( long long number );
374
/** Adds the long long @a number to the stream*/
375
void appendNumber ( unsigned long long number );
377
/** Adds the bool @a value to the stream*/
378
void appendBoolean ( bool value );
380
/** Adds a new line to the stream*/
381
inline void appendNewLine()
386
/** Adds @a number white spaces to the stream*/
387
void addWhiteSpace ( size_t number );
391
/** This function prepares the last opened tag to add contents to it.
392
This function must be called before any contents is added to an element. After this function
393
has been calls, contents should be added, but if not, the xml file will still be valid*/
394
void prepareToAddContents();
399
} //namespace COLLADASW
402
#endif //__COLLADASTREAMWRITER_H__