• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2006 Sony Computer Entertainment Inc.
3 *
4 * Licensed under the MIT Open Source License, for details please see license.txt or the website
5 * http://www.opensource.org/licenses/mit-license.php
6 *
7 */
8 
9 #ifndef __DAE_LIBXMLPLUGIN__
10 #define __DAE_LIBXMLPLUGIN__
11 
12 #include <vector>
13 #include <dae/daeElement.h>
14 #include <dae/daeURI.h>
15 #include <dae/daeIOPluginCommon.h>
16 
17 struct _xmlTextReader;
18 struct _xmlTextWriter;
19 class DAE;
20 
21 /**
22  * The @c daeLIBXMLPlugin class derives from @c daeIOPluginCommon and implements an XML
23  * input/output backend using libxml2 as a parser. When using this plugin, DAE::load() expects
24  * an rfc 2396 compliant URI,  any URI supported by libxml2 should be properly
25  * handled including ones with network schemes and authority.  If the URI contains a fragment it will be ignored
26  * and the entire referenced document will be loaded.  DAE::saveAs will only
27  * handle a filename path at present (ie: no scheme or authority).
28  */
29 class DLLSPEC daeLIBXMLPlugin : public daeIOPluginCommon
30 {
31 public:
32 	// Constructor / destructor
33 	/**
34 	 * Constructor.
35 	 */
36 	daeLIBXMLPlugin(DAE& dae);
37 	/**
38 	 * Destructor.
39 	 */
40 	virtual ~daeLIBXMLPlugin();
41 
42 	// Operations
43 	virtual daeInt write(const daeURI& name, daeDocument *document, daeBool replace);
44 
45 	/**
46 	 * setOption allows you to set options for this IOPlugin. Which options a plugin supports is
47 	 * dependent on the plugin itself. There is currently no list of options that plugins are
48 	 * suggested to implement. daeLibXML2Plugin supports only one option, "saveRawBinary". Set to
49 	 * "true" to save float_array data as a .raw binary file. The daeRawResolver will convert the
50 	 * data back into COLLADA domFloat_array elements upon load.
51 	 * @param option The option to set.
52 	 * @param value The value to set the option.
53 	 * @return Returns DAE_OK upon success.
54 	 */
55 	virtual daeInt setOption( daeString option, daeString value );
56 
57 	/**
58 	 * getOption retrieves the value of an option from this IOPlugin. Which options a plugin supports is
59 	 * dependent on the plugin itself.
60 	 * @param option The option to get.
61 	 * @return Returns the string value of the option or NULL if option is not valid.
62 	 */
63 	virtual daeString getOption( daeString option );
64 
65 private:
66 	DAE& dae;
67 
68 	_xmlTextWriter *writer;
69 
70 	FILE *rawFile;
71 	unsigned long rawByteCount;
72 	daeURI rawRelPath;
73 	bool saveRawFile;
74 
75 	virtual daeElementRef readFromFile(const daeURI& uri);
76 	virtual daeElementRef readFromMemory(daeString buffer, const daeURI& baseUri);
77 	daeElementRef read(_xmlTextReader* reader);
78 	daeElementRef readElement(_xmlTextReader* reader,
79 	                          daeElement* parentElement,
80 	                          /* out */ int& readRetVal);
81 
82 	void writeElement( daeElement* element );
83 	void writeAttribute( daeMetaAttribute* attr, daeElement* element);
84 	void writeValue(daeElement* element);
85 
86 	void writeRawSource( daeElement* src );
87 };
88 
89 #endif //__DAE_LIBXMLPLUGIN__
90