00001 00020 #ifndef ARXX_STRUCTURE_H 00021 #define ARXX_STRUCTURE_H 00022 00023 #include <map> 00024 #include <vector> 00025 00026 #include "Common.h" 00027 #include "Reference.h" 00028 00035 namespace Arxx 00036 { 00037 class Archive; 00038 00039 class Buffer; 00040 00041 class Item; 00042 00048 class Structure 00049 { 00050 friend class Arxx::Archive; 00051 public: 00057 class Relation 00058 { 00059 friend class Arxx::Structure; 00060 public: 00061 typedef std::multimap< Arxx::u4byte, Arxx::Reference >::size_type size_type; 00062 00063 class const_iterator; 00064 00070 class iterator 00071 { 00072 friend class Arxx::Structure::Relation::const_iterator; 00073 public: 00080 iterator(std::multimap< Arxx::u4byte, Arxx::Reference >::iterator iReference); 00081 00085 ~iterator(void); 00086 00092 iterator & operator++(void); 00093 00099 Arxx::Reference & operator*(void); 00100 00106 const Arxx::Reference & operator*(void) const; 00107 00111 Arxx::Reference * operator->(void); 00112 00117 bool operator==(const Arxx::Structure::Relation::iterator & iReference) const; 00118 00123 bool operator!=(const Arxx::Structure::Relation::iterator & iReference) const; 00124 00129 bool operator==(const Arxx::Structure::Relation::const_iterator & iReference) const; 00130 00135 bool operator!=(const Arxx::Structure::Relation::const_iterator & iReference) const; 00136 private: 00142 std::multimap< Arxx::u4byte, Arxx::Reference >::iterator m_iReference; 00143 }; 00144 00150 class const_iterator 00151 { 00152 friend class Arxx::Structure::Relation::iterator; 00153 public: 00160 const_iterator(std::multimap< Arxx::u4byte, Arxx::Reference >::const_iterator iReference); 00161 00168 const_iterator(Arxx::Structure::Relation::iterator iIterator); 00169 00173 ~const_iterator(void); 00174 00180 const_iterator & operator++(void); 00181 00187 const Arxx::Reference & operator*(void) const; 00188 00192 const Arxx::Reference * operator->(void); 00193 00198 bool operator==(const Arxx::Structure::Relation::const_iterator & iReference) const; 00199 00204 bool operator!=(const Arxx::Structure::Relation::const_iterator & iReference) const; 00205 private: 00211 std::multimap< Arxx::u4byte, Arxx::Reference >::const_iterator m_iReference; 00212 }; 00213 00220 void vAdd(Arxx::u4byte u4UniqueID); 00221 00228 bool bDelete(Arxx::u4byte u4UniqueID); 00229 00233 size_type size(void) const; 00234 00238 Arxx::Structure::Relation::iterator begin(void); 00239 00243 Arxx::Structure::Relation::iterator end(void); 00244 00248 Arxx::Structure::Relation::const_iterator begin(void) const; 00249 00253 Arxx::Structure::Relation::const_iterator end(void) const; 00254 00258 const std::string & sGetName(void) const; 00259 private: 00265 Relation(Arxx::Structure & Structure, const std::string & sName); 00266 00272 Arxx::Structure & m_Structure; 00273 00277 std::multimap< Arxx::u4byte, Arxx::Reference > m_References; 00278 00282 std::string m_sName; 00283 }; 00284 00285 friend class Arxx::Structure::Relation; 00286 00287 class const_iterator; 00288 00294 class iterator 00295 { 00296 friend class Arxx::Structure::const_iterator; 00297 public: 00304 iterator(std::map< std::string, Arxx::Structure::Relation >::iterator iRelation); 00305 00309 ~iterator(void); 00310 00316 iterator & operator++(void); 00317 00323 Arxx::Structure::Relation & operator*(void); 00324 00330 const Arxx::Structure::Relation & operator*(void) const; 00331 00335 Arxx::Structure::Relation * operator->(void); 00336 00341 bool operator==(const Arxx::Structure::iterator & iRelation) const; 00342 00347 bool operator!=(const Arxx::Structure::iterator & iRelation) const; 00348 00353 bool operator==(const Arxx::Structure::const_iterator & iRelation) const; 00354 00359 bool operator!=(const Arxx::Structure::const_iterator & iRelation) const; 00360 private: 00366 std::map< std::string, Arxx::Structure::Relation >::iterator m_iRelation; 00367 }; 00368 00374 class const_iterator 00375 { 00376 friend class Arxx::Structure::iterator; 00377 public: 00384 const_iterator(std::map< std::string, Arxx::Structure::Relation >::const_iterator iRelation); 00385 00392 const_iterator(Arxx::Structure::iterator iRelation); 00393 00397 ~const_iterator(void); 00398 00404 const_iterator & operator++(void); 00405 00411 const Arxx::Structure::Relation & operator*(void) const; 00412 00416 const Arxx::Structure::Relation * operator->(void); 00417 00422 bool operator==(const Arxx::Structure::const_iterator & iRelation) const; 00423 00428 bool operator!=(const Arxx::Structure::const_iterator & iRelation) const; 00429 private: 00435 std::map< std::string, Arxx::Structure::Relation >::const_iterator m_iRelation; 00436 }; 00437 00438 typedef std::map< std::string, Arxx::Structure::Relation >::size_type size_type; 00439 00444 Structure(Arxx::Item & Item); 00445 00462 bool bAdd(Arxx::u4byte u4UniqueID, const std::string & sRelation = "child"); 00463 00484 bool bDelete(Arxx::u4byte u4UniqueID, const std::string & sRelation = "child"); 00485 00493 const Arxx::Structure::Relation & GetRelation(const std::string & sRelation) const; 00494 00502 Arxx::Structure::Relation & GetRelation(const std::string & sRelation); 00503 00508 bool bHasRelation(const std::string & sRelation) const; 00509 00513 size_type size(void) const; 00514 00518 Arxx::Structure::iterator begin(void); 00519 00523 Arxx::Structure::iterator end(void); 00524 00528 Arxx::Structure::const_iterator begin(void) const; 00529 00533 Arxx::Structure::const_iterator end(void) const; 00534 private: 00535 friend Arxx::Buffer & Arxx::operator<<(Arxx::Buffer & Buffer, const Arxx::Structure & Structure); 00536 00543 void vWriteToBuffer(Arxx::Buffer & Buffer) const; 00544 00545 void vReadFromStream(Arxx::u4byte u4StructureDataLength, std::istream & IStream); 00546 00547 00548 void vRemoveRelation(Arxx::Structure::Relation * pRelation); 00549 Arxx::Item & m_Item; 00550 std::map< std::string, Arxx::Structure::Relation > m_Relations; 00551 }; 00552 00556 Arxx::Buffer & operator<<(Arxx::Buffer & Buffer, const Arxx::Structure & Structure); 00557 } 00558 00559 #endif