Comments (6)
Hi there.
There is a way to conditionally serialize members.
struct TEST_OBJECT
{
std::map<std::string, bool> filter; // filter object
std::string _children;
std::string _name;
};
ThorsAnvil_MakeFilter(TEST_OBJECT, filter); // define a filter object
ThorsAnvil_MakeTrait(TEST_OBJECT, _children, _name); // define a filter.
If the name of the field is in the filter AND has a value false then it will not be serialized on ouptut.
Otherwise the value is serialized.
Note: This only affects output and the filter is not used on input.
from thorsserializer.
hmm, interesting! I didn't see this in the docs, so I assume it is a new capability?
I see the test case for it, which is a good example: https://github.com/Loki-Astari/ThorsSerializer/blob/dac66aa1feefd3559032d9df3178ec19c318caf4/src/Serialize/test/FilterValuesTest.cpp
I have a fairly large tree of objects, which would require updating thousands of instances to remove/add a member to the filter, and it would increase the memory footprint to store the filter map.
Since I need a global Trait filter (not per object instance), I may need to figure out a different method.
from thorsserializer.
Yes. I am working on DB driver with optional field requirements.
This has made me add this feature.
Once I have stabalized the DB driver I will add the appropriate documentation to the Serializer product.
from thorsserializer.
Sounds good. I am using your library to serialize data from a microcontroller's SDRAM to an SD card, so memory is a scarce resource.
from thorsserializer.
Note: The filter does not have to be std::map<std::string, bool>
object.
It can be an object that supports bool operator[](std::string)
.
It should be relatively simple to add an object that accesses a global structure.
std::map<std::string, bool> globalFilter;
class GlobalFilter
{
std::string prefix;
public:
GlobalFilter(std::string const& prefix): prefix(prefix) {}
bool operator[](std::string const& name) const
{
return globalFilter[prefix + ":" + name];
}
};
Then it each object just add a member to the type.
GlobalFilter filter("ObjectName"); // You could potentially make this static to save space
// Though this adds some of its own complexities.
from thorsserializer.
I was able to try this today and it worked perfectly. I used a static member of my objects as a "global" filter
from thorsserializer.
Related Issues (20)
- 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
- 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
- read problem with map of pointers HOT 1
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.