daeIOPlugin.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_IOPLUGIN__
  9. #define __DAE_IOPLUGIN__
  10. #include <string>
  11. #include <vector>
  12. #include <dae/daeTypes.h>
  13. class daeDatabase;
  14. class daeMetaElement;
  15. class daeURI;
  16. class daeDocument;
  17. /**
  18. * The @c daeIOPlugin class provides the input/output plugin interface, which is
  19. * the interface between the COLLADA runtime and the backend storage. A native
  20. * COLLADA XML plugin implementation is provided along with this interface.
  21. */
  22. class DLLSPEC daeIOPlugin
  23. {
  24. public:
  25. /**
  26. * Destructor
  27. */
  28. virtual ~daeIOPlugin() {}
  29. /**
  30. * Sets the top meta object.
  31. * Called by @c dae::setIOPlugin() when the IO plugin changes. It passes to this function the
  32. * top meta object, which is the root of a
  33. * hierarchy of @c daeMetaElement objects. This top meta object is capable of creating
  34. * any of the root objects in the DOM tree.
  35. * @param topMeta Top meta object to use to create objects to fill the database.
  36. * @return Returns DAE_OK if successful, otherwise returns a negative value defined in daeError.h.
  37. */
  38. virtual daeInt setMeta(daeMetaElement *topMeta) = 0;
  39. /** @name Database setup */
  40. //@{
  41. /**
  42. * Sets the database to use.
  43. * All @c daeIOPlugins use the same interface to the @c daeDatabase,
  44. * @c setDatabase() tells the @c daeIOPlugin which @c daeDatabase object it should use
  45. * for storage and queries.
  46. * @param database Database to set.
  47. */
  48. virtual void setDatabase(daeDatabase* database) = 0;
  49. //@}
  50. /** @name Operations */
  51. //@{
  52. /**
  53. * Imports content into the database from an input.
  54. * The input can be a file, a database or another runtime.
  55. * @param uri the URI of the COLLADA document to load, not all plugins accept all types of URIs,
  56. * check the documentation for the IO plugin you are using.
  57. * @param docBuffer A string containing the text of the document to load. This is an optional attribute
  58. * and should only be used if the document has already been loaded into memory.
  59. * @return Returns DAE_OK if successfully loaded, otherwise returns a negative value defined in daeError.h.
  60. * @see @c DAE::load().
  61. */
  62. virtual daeInt read(const daeURI& uri, daeString docBuffer) = 0;
  63. /** @name Operations */
  64. //@{
  65. /**
  66. * Writes a specific document to an output.
  67. * @param name URI to write the document to, not all IO plugins support all types of URIs
  68. * check the documentation for the IO plugin you are using.
  69. * @param document Pointer to the document that we're going to write out.
  70. * @param replace True if write should overwrite an existing file. False otherwise.
  71. * @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
  72. * @see @c DAE::saveAs()
  73. */
  74. virtual daeInt write(const daeURI& name, daeDocument *document, daeBool replace) = 0;
  75. //@}
  76. /**
  77. * Returns a list of the URI protocols that this plugin supports.
  78. * @return Returns a daeArray containing the supported protocols.
  79. */
  80. virtual const std::vector<std::string>& getSupportedProtocols() {
  81. return supportedProtocols;
  82. }
  83. /**
  84. * setOption allows you to set options for this IOPlugin. Which options a plugin supports is
  85. * dependent on the plugin itself. There is currently no list of options that plugins are
  86. * suggested to implement.
  87. * @param option The option to set.
  88. * @param value The value to set the option.
  89. * @return Returns DAE_OK upon success.
  90. */
  91. virtual daeInt setOption( daeString option, daeString value ) = 0;
  92. /**
  93. * getOption retrieves the value of an option from this IOPlugin. Which options a plugin supports is
  94. * dependent on the plugin itself.
  95. * @param option The option to get.
  96. * @return Returns the string value of the option or NULL if option is not valid.
  97. */
  98. virtual daeString getOption( daeString option ) = 0;
  99. protected:
  100. // This is an array of the URI protocols supported by this plugin, e.g. "http", "file",
  101. // etc. Each plugin should initialize this variable in the constructor.
  102. std::vector<std::string> supportedProtocols;
  103. };
  104. class DLLSPEC daeIOEmpty : public daeIOPlugin {
  105. public:
  106. virtual daeInt setMeta(daeMetaElement *topMeta) { return DAE_ERROR; }
  107. virtual void setDatabase(daeDatabase* database) { }
  108. virtual daeInt read(const daeURI& uri, daeString docBuffer) { return DAE_ERROR; }
  109. virtual daeInt write(const daeURI& name, daeDocument *document, daeBool replace) { return DAE_ERROR; }
  110. virtual daeInt setOption( daeString option, daeString value ) { return DAE_ERROR; }
  111. virtual daeString getOption( daeString option ) { return ""; }
  112. };
  113. #endif // __DAE_IOPLUGIN__