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 9 #ifndef __DAE_STLDATABASE__ 10 #define __DAE_STLDATABASE__ 11 12 #include <stdio.h> 13 14 #include <vector> 15 #include <map> 16 #include <string> 17 #include <algorithm> 18 #include <functional> 19 20 #include <dae/daeElement.h> 21 #include <dae/daeDatabase.h> 22 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 39 public: 40 // Element Types of all Elements 41 virtual daeUInt getTypeCount(); 42 virtual daeString getTypeName(daeUInt index); 43 virtual daeInt setMeta(daeMetaElement *_topMeta); 44 45 // Documents 46 virtual daeInt insertDocument(daeString name, daeElement* dom, daeDocument** document = NULL, bool zaeRootDocument = false, const std::string& extractedFileURI = ""); 47 virtual daeInt insertDocument(daeString name, daeDocument** document = NULL); 48 virtual daeInt createDocument(daeString name, daeElement* dom, daeDocument** document = NULL, bool zaeRootDocument = false, const std::string& extractedFileURI = ""); 49 virtual daeInt createDocument(daeString name, daeDocument** document = NULL); 50 virtual daeInt insertDocument( daeDocument *c ); 51 52 virtual daeInt removeDocument(daeDocument* document); 53 virtual daeUInt getDocumentCount(); 54 virtual daeDocument* getDocument(daeUInt index); 55 virtual daeDocument* getDocument(daeString name, bool skipUriNormalization = false); 56 virtual daeString getDocumentName(daeUInt index); 57 virtual daeBool isDocumentLoaded(daeString name); 58 59 // Elements 60 virtual daeInt insertElement(daeDocument* document, daeElement* element); 61 virtual daeInt removeElement(daeDocument* document, daeElement* element); 62 virtual daeInt changeElementID(daeElement* element, daeString newID); 63 virtual daeInt changeElementSID(daeElement* element, daeString newSID); // Not implemented 64 virtual daeInt clear(); 65 66 virtual std::vector<daeElement*> idLookup(const std::string& id); 67 68 virtual void typeLookup(daeInt typeID, 69 std::vector<daeElement*>& matchingElements, 70 daeDocument* doc = NULL); 71 72 // Currently not implemented, but you can uncomment some code in daeSTLDatabase.cpp to get 73 // it working. 74 virtual void sidLookup(const std::string& sid, 75 std::vector<daeElement*>& matchingElements, 76 daeDocument* doc = NULL); 77 78 // Deprecated. Don't use these. Use idLookup or typeLookup instead. 79 virtual daeUInt getElementCount(daeString name = NULL, 80 daeString type = NULL, 81 daeString file = NULL); 82 virtual daeInt getElement(daeElement** pElement, 83 daeInt index, 84 daeString name = NULL, 85 daeString type = NULL, 86 daeString file = NULL); 87 88 private: 89 90 std::map< std::string, std::vector< daeElement* > > elements; // type name --> element lookup table (deprecated) 91 92 std::multimap<daeInt, daeElement*> typeMap; // type ID --> element lookup table 93 typedef std::multimap<daeInt, daeElement*>::iterator typeMapIter; 94 typedef std::pair<daeInt, daeElement*> typeMapPair; 95 typedef std::pair<typeMapIter, typeMapIter> typeMapRange; 96 97 std::multimap< std::string, daeElement* > elementsIDMap; //map for elements keyed on ID 98 typedef std::multimap<std::string, daeElement*>::iterator idMapIter; 99 typedef std::pair<std::string, daeElement*> idMapPair; 100 typedef std::pair<idMapIter, idMapIter> idMapRange; 101 102 std::multimap< std::string, daeElement* > sidMap; // sid --> element lookup table 103 typedef std::multimap<std::string, daeElement*>::iterator sidMapIter; 104 typedef std::pair<std::string, daeElement*> sidMapPair; 105 typedef std::pair<sidMapIter, sidMapIter> sidMapRange; 106 107 std::vector<daeDocument*> documents; 108 daeMetaElement* topMeta; 109 110 daeInt insertChildren( daeDocument *c, daeElement *element ); 111 daeInt removeChildren( daeDocument *c, daeElement *element ); 112 }; 113 114 #endif // __DAE_STLDATABASE__ 115