Updated PolyXML package

git-svn-id: svn://ultimatepp.org/upp/trunk@1887 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
micio 2010-01-13 21:18:22 +00:00
parent 8e94336a9f
commit af9723b24b
2 changed files with 12 additions and 4 deletions

View file

@ -28,7 +28,7 @@ template<class T> class WithFactory
static T *CreatePtr(String const &className) { return classMap().Get(className)().Detach(); }
static Vector<String> 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() {}
};

View file

@ -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<Base> polyArray;
@ -44,6 +46,12 @@ CONSOLE_APP_MAIN
d->DerivedData = "Another sample data in derived class";
polyArray.Add(d);
Another *a = dynamic_cast<Another *>(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++)
{