daeLIBXMLPlugin.h 2.9 KB

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