Comments (7)
Sorry.
That is an over-site in the documentation. I will take a look and add some examples.
To declare a derived class you use ThorsAnvil_ExpandTrait
rather than ThorsAnvil_MakeTrait
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
It would look like this:
MyDerived item(12, 23.8, "Look");
std::cout << jsonExport(item);
Should result in:
{
"data1": 12,
"data2": 23.8,
"data3": "Look",
"data4": 9
}
I will have some time to write this up and compile (and thus test) this weekend.
from thorsserializer.
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?
from thorsserializer.
You use pointers excessively (I understanding for the polymorphic Component
) but do you need it for the GameObject
? You should check out https://codereview.stackexchange.com and see if a code review would help.
To Answer your question:
Not Directly. (Missing a polymorphic feature).
Just two minor tweaks.
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.
from thorsserializer.
We need GameObject
to be a pointer because when referencing GameObject
we don't want to create a copy of it all the time but want to change it directly. Also there is a large amount of data saved into GameObject
when running the game which should be stored on the heap and not on the stack.
Thank you for your responses, I look forward to hearing from your updates of the library when you find the time!
from thorsserializer.
We need GameObject to be a pointer because when referencing GameObject we don't want to create a copy of it all the time but want to change it directly.
That does not preclude it being an object of a vector.
std::vector<GameObject> objects;
// STUFF
objects[1].doStuff(); // Does not create a copy.
// Operator [] returns a reference.
Also storing pointers is very error prone.
Basically in modern C++ you never use pointers (you should be using unique_ptr<>
). I would encourage you to get a code review of your design at https://codereview.stackexchange.com
Also with the addition of move semantics in C++11 must objects are moved (not copied). This should be relatively cheap operations.
Also there is a large amount of data saved into GameObject when running the game which should be stored on the heap and not on the stack.
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 Automatic/Static/Thread/Dynamic
storage duration objects. These are how you think of memory in C++ (not heap/stack). And you should never be interacting directly with dynamically allocated objects they should be controlled via automatic objects (i.e. smart pointers or containers).
from thorsserializer.
GameObject
is barely ever referenced directly through the scene unless it is scene management so it won't be called through the list variable that it is stored in. It is mainly referenced through Component
which looks like this: https://puu.sh/xEDvo/f145e4c4bb.png and components reference the GameObject
that they're attached to. This is the GameObject
class: https://puu.sh/xEEb6/60031484d2.png
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 GameObject
and Component
to be std::shared_ptr
s is because we want multiple pointers to the same resource.
P.S. I made screenshots of the code as it seemed to be too long to put it inside of the comment
from thorsserializer.
This is now supported.
See: https://github.com/Loki-Astari/ThorsSerializer/blob/master/doc/example3.md
from thorsserializer.
Related Issues (20)
- How to combine templates and polymorphism? HOT 7
- Maximum number of levels/depth? HOT 5
- No compile enum with 8 and more element HOT 6
- Deserializing to existing object with vectors/pointers? HOT 8
- Std:array not working on header only version HOT 6
- Make under Homebrew results in template error HOT 1
- Make Trait does not work for types with static members with non-standard types HOT 1
- Compilation issue with VisualStudio 2019 on Windows HOT 4
- my compile problem of example1 HOT 1
- Redefine traits at runtime HOT 6
- MakeTrait: error: unable to deduce 'std::initializer_list<auto>' HOT 9
- [Linuxbrew] Trying to prepare v2.2.0 bottle but hitting compilation issues (tried GCC-11 and LLVM) HOT 10
- Tags with header only HOT 7
- Linker error on basic example, I am missing something? HOT 4
- Linker Error? HOT 5
- Invalid enum values causes undefined behavior HOT 1
- missing include file magic_enum.hpp HOT 3
- Linker fails with header-only build HOT 11
- Why there is no CMAKE support? HOT 5
- error compiling with std::shared_ptr<const Type> HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thorsserializer.