-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Question on the lifetime managment of objects at the lower levels #449
Comments
You could use an iterator to your object element: #include <json.hpp>
using nlohmann::json;
int main()
{
json j = {{"a", 1}, {"level1", "some_value"}};
json::iterator my_lev1 = j.find("level1");
std::cout << j << std::endl;
// {"a":1,"level1":"some_value"}
*my_lev1 = "another value";
std::cout << j << std::endl;
// {"a":1,"level1":"another value"}
} Internally, objects are stored as |
Hi Niels, well this is a good information, however i would say it does not solve my problem, since the object "Parameters" has to hold the json inside. (I am trying to modularize the library so that it only knowns Parameters and not the underlying implementation i could do something like the following, however i agree beforehand that it is not really clean
an alternative could be to derive Parameters from the json class... if you have any better idea let me know cheers |
Hi Riccardo, unfortunately, I do not understand what you are trying to do and where the library falls short. 😞 |
Hi Niels, to clarify it is NOT your library to fall short. It is the requirement i have on my side that obliges me to a hack. i am almost through anyway...so thanks a lot for your time, the confirmations that iterators are stable was fundamental cheers |
Thanks for checking back! |
Dear Niels,
first of all let me say that your library is very cool.
I am writing here since i am considering the possibility of switching our current implementation from using rapidjson to nlohmann.
Within our code (KratosMultiphysics) we made the choice of isolating ourselves from the json lib of choice by defining an object "Parameters" that essentially hides the details of the underlying implementation.
the point is that if i have something like
i need the capability of creating a pointer to the level1, something like
so that if i change my_lev1, the general1 is also changed.
the problem here is of course how to manage the lifetime of the different objects.
before going for ugly solutions (for example for rapidjson in each "Parameters" i was storing a shared_ptr to the root object, i could do something of the sort, or some even uglier trick)
i was wondering if you were using internally some sort of shared_ptr to manage the lifetyme of your descendants, which would allow me a much cleaner solution.
thank you in advance for any hint
Riccardo
The text was updated successfully, but these errors were encountered: