diff --git a/bazaar/PolyXML/ClassFactory.h b/bazaar/PolyXML/ClassFactory.h index 8a825c9b4..83e9a29aa 100644 --- a/bazaar/PolyXML/ClassFactory.h +++ b/bazaar/PolyXML/ClassFactory.h @@ -28,7 +28,7 @@ template class WithFactory static T *CreatePtr(String const &className) { return classMap().Get(className)().Detach(); } static Vector const &Classes(void) { return classMap().GetKeys(); } static String const &GetClassDescription(const String &className) { return descMap().Get(className); } - static String const &GetClassIndex(const String &className) { return indexMap().Get(className); } + static int const &GetClassIndex(const String &className) { return indexMap().Get(className); } String const &IsA(void) { return typeMap().Get(typeid(*this).name()); } virtual ~WithFactory() {} }; diff --git a/bazaar/PolyXMLTest/Main.cpp b/bazaar/PolyXMLTest/Main.cpp index 8d28ed6e7..58f2e4c38 100644 --- a/bazaar/PolyXMLTest/Main.cpp +++ b/bazaar/PolyXMLTest/Main.cpp @@ -19,7 +19,7 @@ class Derived : public Base class Another : public Derived { public: - String AnotherData; + int AnotherData; void Xmlize(XmlIO xml) { Derived::Xmlize(xml); xml("AnotherData", AnotherData); } }; @@ -29,9 +29,11 @@ REGISTERCLASS(Another, "you can add a description and also an index", 10); CONSOLE_APP_MAIN { - Cerr() << "You have registered " << Base::Classes().GetCount() << ":\n"; + Cerr() << "You have registered " << Base::Classes().GetCount() << " classes:\n"; for(int i = 0; i < Base::Classes().GetCount(); i++) - Cerr() << " Class#" << i << " is a '" << Base::Classes()[i] << "' Description '" << Base::GetClassDescription(Base::Classes()[i]) << "'\n"; + Cerr() << " Class#" << i << " is a '" << Base::Classes()[i] + << "' Description '" << Base::GetClassDescription(Base::Classes()[i]) + << "' Index '" << Base::GetClassIndex(Base::Classes()[i]) << "'\n"; PolyXMLArray polyArray; @@ -44,6 +46,12 @@ CONSOLE_APP_MAIN d->DerivedData = "Another sample data in derived class"; polyArray.Add(d); + Another *a = dynamic_cast(Base::CreatePtr("Another")); + a->BaseData = "Sample data in derived class"; + a->DerivedData = "Another sample data in derived class"; + a->AnotherData = 12345; + polyArray.Add(a); + Cerr() << "\nArray content before streaming out: " << polyArray.GetCount() << " classes:\n"; for(int i = 0; i < polyArray.GetCount(); i++) {