-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polymorphism support #35
Comments
Sorry. To declare a derived class you use Expanding on the Bigger Example class MyDerived: public MyClass
{
int data4 = 9;
friend struct ThorsAnvil::Serialize::Traits<MyDerived>;
public:
using MyClass::MyClass;
};
ThorsAnvil_ExpandTrait(MyClass, MyDerived, data4); If I serialized an object of MyDerived item(12, 23.8, "Look");
std::cout << jsonExport(item); Should result in:
I will have some time to write this up and compile (and thus test) this weekend. |
I'm developing a game engine with a friend in C++ and as I'm working on the editor I need to be able to flexibly serialize all kinds of classes and preferably in the most automatic and least intrusive way as possible to save time and enforce OOP (a class that manages serialization should manage all the serialization itself thus serialization code should not be found in classes that need to be serialized, obviously that's quite difficult in C++ without reflection or introspection). So for example we would have a scene that contains a map of pointer gameobjects which contains a vector of pointer components and those components could be any possible class that has derived from it. Would you think your library would be a good fit for something that flexible? |
You use pointers excessively (I understanding for the polymorphic To Answer your question: Not Directly. (Missing a polymorphic feature). So for pointers these don't work without a helper function. You need to write a function to convert them to references. Another un-document feature (I will have to look up how I did that). Its been a while since I used it but I am sure it is there. Also it does not handle polymorphic types out of the box. But I think I can add a feature to deal with that. I'll look into it this weekend if I get a chance. |
We need Thank you for your responses, I look forward to hearing from your updates of the library when you find the time! |
That does not preclude it being an object of a vector.
Also storing pointers is very error prone. Also with the addition of move semantics in C++11 must objects are moved (not copied). This should be relatively cheap operations.
Referring to the stack and heap is an incorrect way of looking at C++ (unlike Java, C++ does not have a concept of heap and stack (yes they are used underneath but they are not part of the language construct)) and trying to think about heap and stack will lead you to do things inefficiently. PS. You should be thinking in terms of |
We are already using smart pointers to store them, I simply didn't write smart pointer as I wanted to write it shortly as I believed specifying it to be of little significance (I'm aware that serialization of objects should be done through smart pointers). The reason for P.S. I made screenshots of the code as it seemed to be too long to put it inside of the comment |
This is now supported. |
Nowhere in the documentation is there any indication of inheritance so I wondered if there is any support for that?
The text was updated successfully, but these errors were encountered: