tyt2y3 / tinybind

the neat and sexy XML and JSON binding and serialization scheme for C++
18 stars 11 forks source link

polymorphism #4

Open DerSemjon opened 8 years ago

DerSemjon commented 8 years ago

Hello, i'd like to use tinybind for polymorphistic classes. I dont get how the INHERIT(X) or the STRUCT_INHERIT(X) works. Is there any example ?

tyt2y3 commented 8 years ago

Hi, try example 2 https://github.com/tyt2y3/tinybind/blob/master/examples/2_svg.h though polymorphism is about functionality, not about data. so it should work. Edit, the definition of STRUCT_INHERIT(TYPE, ...) has a va_args, so the following trick should work too:

STRUCT_INHERIT(C, public A, B)
{
    INHERIT(A);
    INHERIT(B);
};
DerSemjon commented 8 years ago

Hello Chris, thanks for your reply. Is there a way to utilize vectors of pointers as CHILD elements ? Gretes, Semjon

Am 21.03.2016 um 17:10 schrieb Chris Tsang notifications@github.com:

Hi, try example 2 https://github.com/tyt2y3/tinybind/blob/master/examples/2_svg.h https://github.com/tyt2y3/tinybind/blob/master/examples/2_svg.h though polymorphism is about functionality, not about data. so it should work

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/tyt2y3/tinybind/issues/4#issuecomment-199360128


Automedia Marketing und Medienservice für den Kfz-Handel GmbH Drususgasse 7-11, 50667 Köln T +49 221 285 839 0 F +49 221 285 839 29 Amtsgericht Köln HRB 29570 Geschäftsführer: Wilhelm Ruppert

www.automedia.de www.automedia360.com

http://www.facebook.com/Automedia.GmbH [image: Google+] http://plus.google.com/b/110802155187587697673/dashboard/overview

tyt2y3 commented 8 years ago

I am not sure what do you mean by that. Why would you use a pointer in an object for serialization. You can theoretically write a custom binding function for that, e.g.

template <class P>
void TXB_attr_bind( TiXmlElement* xmle, bool from, P* attr_content, const char* attr_name)

where P is you pointer.

But you will need to think about circular reference or objects with too deep nesting