daeLIBXMLPlugin.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2006 Sony Computer Entertainment Inc.
  3. *
  4. * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
  5. * file except in compliance with the License. You may obtain a copy of the License at:
  6. * http://research.scea.com/scea_shared_source_license.html
  7. *
  8. * Unless required by applicable law or agreed to in writing, software distributed under the License
  9. * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied. See the License for the specific language governing permissions and limitations under the
  11. * License.
  12. */
  13. #ifndef __DAE_LIBXMLPLUGIN__
  14. #define __DAE_LIBXMLPLUGIN__
  15. #include <vector>
  16. #include <dae/daeElement.h>
  17. #include <dae/daeURI.h>
  18. #include <dae/daeIOPluginCommon.h>
  19. struct _xmlTextReader;
  20. struct _xmlTextWriter;
  21. class DAE;
  22. /**
  23. * The @c daeLIBXMLPlugin class derives from @c daeIOPluginCommon and implements an XML
  24. * input/output backend using libxml2 as a parser. When using this plugin, DAE::load() expects
  25. * an rfc 2396 compliant URI, any URI supported by libxml2 should be properly
  26. * handled including ones with network schemes and authority. If the URI contains a fragment it will be ignored
  27. * and the entire referenced document will be loaded. DAE::saveAs will only
  28. * handle a filename path at present (ie: no scheme or authority).
  29. */
  30. class DLLSPEC daeLIBXMLPlugin : public daeIOPluginCommon
  31. {
  32. public:
  33. // Constructor / destructor
  34. /**
  35. * Constructor.
  36. */
  37. daeLIBXMLPlugin(DAE& dae);
  38. /**
  39. * Destructor.
  40. */
  41. virtual ~daeLIBXMLPlugin();
  42. // Operations
  43. virtual daeInt write(const daeURI& name, daeDocument *document, daeBool replace);
  44. /**
  45. * setOption allows you to set options for this IOPlugin. Which options a plugin supports is
  46. * dependent on the plugin itself. There is currently no list of options that plugins are
  47. * suggested to implement. daeLibXML2Plugin supports only one option, "saveRawBinary". Set to
  48. * "true" to save float_array data as a .raw binary file. The daeRawResolver will convert the
  49. * data back into COLLADA domFloat_array elements upon load.
  50. * @param option The option to set.
  51. * @param value The value to set the option.
  52. * @return Returns DAE_OK upon success.
  53. */
  54. virtual daeInt setOption( daeString option, daeString value );
  55. /**
  56. * getOption retrieves the value of an option from this IOPlugin. Which options a plugin supports is
  57. * dependent on the plugin itself.
  58. * @param option The option to get.
  59. * @return Returns the string value of the option or NULL if option is not valid.
  60. */
  61. virtual daeString getOption( daeString option );
  62. private:
  63. DAE& dae;
  64. _xmlTextWriter *writer;
  65. FILE *rawFile;
  66. unsigned long rawByteCount;
  67. daeURI rawRelPath;
  68. bool saveRawFile;
  69. virtual daeElementRef readFromFile(const daeURI& uri);
  70. virtual daeElementRef readFromMemory(daeString buffer, const daeURI& baseUri);
  71. daeElementRef read(_xmlTextReader* reader);
  72. daeElementRef readElement(_xmlTextReader* reader, daeElement* parentElement);
  73. void writeElement( daeElement* element );
  74. void writeAttribute( daeMetaAttribute* attr, daeElement* element);
  75. void writeValue(daeElement* element);
  76. void writeRawSource( daeElement* src );
  77. };
  78. #endif //__DAE_LIBXMLPLUGIN__