daeSTLDatabase.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_STLDATABASE__
  14. #define __DAE_STLDATABASE__
  15. #include <stdio.h>
  16. #include <vector>
  17. #include <map>
  18. #include <string>
  19. #include <algorithm>
  20. #include <functional>
  21. #include <dae/daeElement.h>
  22. #include <dae/daeDatabase.h>
  23. /**
  24. * The @c daeSTLDatabase class derives from @c daeDatabase and implements
  25. * the default database.
  26. */
  27. class DLLSPEC daeSTLDatabase : public daeDatabase
  28. {
  29. public:
  30. /**
  31. * Constructor
  32. */
  33. daeSTLDatabase(DAE& dae);
  34. /**
  35. * Destructor
  36. */
  37. virtual ~daeSTLDatabase();
  38. public:
  39. // Element Types of all Elements
  40. virtual daeUInt getTypeCount();
  41. virtual daeString getTypeName(daeUInt index);
  42. virtual daeInt setMeta(daeMetaElement *_topMeta);
  43. // Documents
  44. virtual daeInt insertDocument(daeString name, daeElement* dom, daeDocument** document = NULL);
  45. virtual daeInt insertDocument(daeString name, daeDocument** document = NULL);
  46. virtual daeInt createDocument(daeString name, daeElement* dom, daeDocument** document = NULL);
  47. virtual daeInt createDocument(daeString name, daeDocument** document = NULL);
  48. virtual daeInt insertDocument( daeDocument *c );
  49. virtual daeInt removeDocument(daeDocument* document);
  50. virtual daeUInt getDocumentCount();
  51. virtual daeDocument* getDocument(daeUInt index);
  52. virtual daeDocument* getDocument(daeString name, bool skipUriNormalization = false);
  53. virtual daeString getDocumentName(daeUInt index);
  54. virtual daeBool isDocumentLoaded(daeString name);
  55. // Elements
  56. virtual daeInt insertElement(daeDocument* document, daeElement* element);
  57. virtual daeInt removeElement(daeDocument* document, daeElement* element);
  58. virtual daeInt changeElementID(daeElement* element, daeString newID);
  59. virtual daeInt changeElementSID(daeElement* element, daeString newSID); // Not implemented
  60. virtual daeInt clear();
  61. virtual std::vector<daeElement*> idLookup(const std::string& id);
  62. virtual void typeLookup(daeInt typeID,
  63. std::vector<daeElement*>& matchingElements,
  64. daeDocument* doc = NULL);
  65. // Currently not implemented, but you can uncomment some code in daeSTLDatabase.cpp to get
  66. // it working.
  67. virtual void sidLookup(const std::string& sid,
  68. std::vector<daeElement*>& matchingElements,
  69. daeDocument* doc = NULL);
  70. // Deprecated. Don't use these. Use idLookup or typeLookup instead.
  71. virtual daeUInt getElementCount(daeString name = NULL,
  72. daeString type = NULL,
  73. daeString file = NULL);
  74. virtual daeInt getElement(daeElement** pElement,
  75. daeInt index,
  76. daeString name = NULL,
  77. daeString type = NULL,
  78. daeString file = NULL);
  79. private:
  80. std::map< std::string, std::vector< daeElement* > > elements; // type name --> element lookup table (deprecated)
  81. std::multimap<daeInt, daeElement*> typeMap; // type ID --> element lookup table
  82. typedef std::multimap<daeInt, daeElement*>::iterator typeMapIter;
  83. typedef std::pair<daeInt, daeElement*> typeMapPair;
  84. typedef std::pair<typeMapIter, typeMapIter> typeMapRange;
  85. std::multimap< std::string, daeElement* > elementsIDMap; //map for elements keyed on ID
  86. typedef std::multimap<std::string, daeElement*>::iterator idMapIter;
  87. typedef std::pair<std::string, daeElement*> idMapPair;
  88. typedef std::pair<idMapIter, idMapIter> idMapRange;
  89. std::multimap< std::string, daeElement* > sidMap; // sid --> element lookup table
  90. typedef std::multimap<std::string, daeElement*>::iterator sidMapIter;
  91. typedef std::pair<std::string, daeElement*> sidMapPair;
  92. typedef std::pair<sidMapIter, sidMapIter> sidMapRange;
  93. std::vector<daeDocument*> documents;
  94. daeMetaElement* topMeta;
  95. daeInt insertChildren( daeDocument *c, daeElement *element );
  96. daeInt removeChildren( daeDocument *c, daeElement *element );
  97. };
  98. #endif // __DAE_STLDATABASE__