daeIOPlugin.h 5.0 KB

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