00001 /* 00002 * Copyright 2006 Sony Computer Entertainment Inc. 00003 * 00004 * Licensed under the MIT Open Source License, for details please see license.txt or the website 00005 * http://www.opensource.org/licenses/mit-license.php 00006 * 00007 */ 00008 00009 #ifndef __DAE_IDREF_H__ 00010 #define __DAE_IDREF_H__ 00011 00012 #include <string> 00013 #include <dae/daeTypes.h> 00014 #include <dae/daeElement.h> 00015 class DAE; 00016 00029 class DLLSPEC daeIDRef 00030 { 00031 public: 00035 enum ResolveState{ 00037 id_empty, 00039 id_loaded, 00041 id_pending, 00043 id_success, 00045 id_failed_id_not_found, 00047 id_failed_invalid_id, 00049 id_failed_invalid_reference, 00051 id_failed_externalization, 00054 id_failed_no_document 00055 }; 00056 00057 private: 00059 std::string id; 00060 00062 daeElement* container; 00063 00064 public: 00068 daeIDRef(); 00069 00074 daeIDRef(daeString id); 00075 00080 daeIDRef(const daeIDRef& constructFromIDRef); 00081 00086 daeIDRef(daeElement& container); 00087 00092 daeString getID() const; 00093 00099 void setID(daeString ID); 00100 00105 daeElement* getElement() const; 00106 00111 daeElement* getContainer() const; 00112 00117 void setContainer(daeElement* cont); 00118 00122 void print(); 00123 00128 void reset(); 00129 00133 void initialize(); 00134 00139 bool operator==(const daeIDRef& other) const; 00140 00145 daeIDRef &operator=( const daeIDRef& other); 00146 00147 // These methods are only provided for backwards compatibility. Use the listed alternatives. 00148 daeIDRef &get( daeUInt idx ); // Never should have existed. No alternative. 00149 size_t getCount() const; // Never should have existed. No alternative. 00150 daeIDRef& operator[](size_t index); // Never should have existed. No alternative. 00151 void resolveElement( daeString typeNameHint = NULL ); // Call getElement. No separate "resolve" step needed. 00152 void resolveID(); // Never should have existed. No alternative. 00153 void validate(); // Never should have existed. No alternative. 00154 void copyFrom(const daeIDRef& from); // Use the assignment operator instead. 00155 ResolveState getState() const; // Never should have existed. No alternative. 00156 }; 00157 00163 class DLLSPEC daeIDRefResolver 00164 { 00165 public: 00169 daeIDRefResolver(DAE& dae); 00170 00174 virtual ~daeIDRefResolver(); 00175 00182 virtual daeElement* resolveElement(const std::string& id, daeDocument* doc) = 0; 00183 00184 00189 virtual daeString getName() = 0; 00190 00191 protected: 00192 DAE* dae; 00193 }; 00194 00195 00200 class DLLSPEC daeDefaultIDRefResolver : public daeIDRefResolver 00201 { 00202 public: 00203 daeDefaultIDRefResolver(DAE& dae); 00204 ~daeDefaultIDRefResolver(); 00205 virtual daeElement* resolveElement(const std::string& id, daeDocument* doc); 00206 virtual daeString getName(); 00207 }; 00208 00209 00210 // This is a container class for storing a modifiable list of daeIDRefResolver objects. 00211 class DLLSPEC daeIDRefResolverList { 00212 public: 00213 daeIDRefResolverList(); 00214 ~daeIDRefResolverList(); 00215 00216 void addResolver(daeIDRefResolver* resolver); 00217 void removeResolver(daeIDRefResolver* resolver); 00218 00219 daeElement* resolveElement(const std::string& id, daeDocument* doc); 00220 00221 private: 00222 // Disabled copy constructor/assignment operator 00223 daeIDRefResolverList(const daeIDRefResolverList& resolverList) { }; 00224 daeIDRefResolverList& operator=(const daeIDRefResolverList& resolverList) { return *this; }; 00225 00226 daeTArray<daeIDRefResolver*> resolvers; 00227 }; 00228 00229 00230 #endif //__DAE_IDREF_H__