Replies: 2 comments 4 replies
-
No sure if I understood all of the above. May brain is a bit slow today. I'd prefer to use Qt JSON for the implementation. Using third party libraries is ok if they can be copied to atools (if license allows). Maintaining and compiling third party libraries like Marble for three platforms is not really funny. Especially macOS is a pain. Deriving for POD objects/structs like Classes which might contain relevant information: https://github.com/albar965/littlenavmap/blob/master/src/route/route.h All flight plan related stuff including all legs as well as next active legs information. https://github.com/albar965/littlenavmap/blob/master/src/route/routealtitude.h TOC and TOD calculation, vertical profile as well as everything needed for fuel report. Contains partially redundant information for https://github.com/albar965/littlenavmap/tree/master/src/query Database access wrappers. Mostly deliver POD structs and sometimes SQL Records from the map namespace. https://github.com/albar965/littlenavmap/blob/master/src/common/maptypes.h Above mentioned POD objects. Most are serializable and passed around throughout the whole program. Inherit from base but don't have virtual destructors which needs a bit caution when dealing with these things. Edit: Not at C++17 yet. Will try this after the release. |
Beta Was this translation helpful? Give feedback.
-
the idea behind the op is, on an existing class hiearchy, to add support to collect values from classes of this existing hiearchy to somewhere (eg. to output it as JSON from there) while not touching the existing classes at all, in particular not write "custom" transfer code or extend individual value creation methods. Unfortunately this appears not possible by passing method pointers around: i forgot: to call a method of an object, the compilers type-safeyt I guess, must know the method exists on this object. This means,as long as the getters are defined first in the class to add value collection from, a pointer to any such getter must include the class name for the compiler to know this pointer can call the getter. Touching existing classes not at all isn't achieved by the op anway but at least not every getter has to extended with "custom code". The goal to have minimal intervention on the existing class hierarchy can still be achieved though I think ( I apologize for making you spend time in vain so far and causing disappointment to expectations I let rise): the constructor of any existing class to collect data from must stil be extended to call JSONProvider's super constructor with the information about the available "properties" (as to be collected) by passing their names as spec'd in the op. But nothing else has to be passed. Instead: add 1 or 3 pure virtual functions to JSONProvider taking a string. This string is to get passed the representative property name you came up with, name the pure virtual function getXProperty where X can be QVariant, Bool, Number or String.
This way, maintainance of your code per getter/property is boiled down to 1 line of additional effort. The elephant which was running at us is the creation of a special JSONProvider per existing class or changing every getter of every class with -- granted 1 line only too -- but several identifying identificators like JSONStorage::storeBool("propertyname", "classname", value, instanceidentificator) but which would run actively on each get rather than waiting passively or creating Templates out of your existing classes or .... . I hope this works. you = dear reader. CC @albar965 , i havent written C++ the last 18 or so years (glanced at C++ 11 for a time some 8 years ago). -- oh wait, i coded a Symbian Belle Nokia OVI store app with Qt around 9 years ago :) Other than Qt JSON or i think i understood your approval of the nlohmann header, do you have any other recommendations? looking forward to read from you, enjoy |
Beta Was this translation helpful? Give feedback.
-
JSON as output from the webserver appears to be a common fundamental requirement for catalysing future web-based community add-ons (for private or public use)
// I just noticed std::function requires the name of the class of which a method is being wanted to get assigned as a pointer ;( I hoped i could get around this - ah: perhaps you can add a protected list of pointers to member functions to JSONProvider. Your class inheriting from JSONProvider might make adding your getters to that list possible due to polymorphism. Then register the map with the index of the pointer to a member function as the value of string. "getValueByMethod" would then be "getValueByIndex" and would use the list to call the member function ! :)
proposal:
Now:
Then:
Implement overloading of operator >> in JSONStorage to output (to) the JSON class from https://github.com/nlohmann/json on request from the webserver. Using overloaded operators requires an instance. Call getValueByMethod on every JSONProvider stored for every method pointer stored passing that one, storing the result as/for a https://github.com/nlohmann/json JSON object.
For now, output all data. In future perhaps output only values of properties requested.
The JSON can look like the following considering you have 1 instance of your class X running and 3 instances of your class Y running:
Practical occurrence:
Y could be a waypoint class whose "doubleProperty2" is its position.
Note: I forgot getting Arrays and having objects of a Class which might itself inherit JSONProvider be a member of a class inheriting JSONProvider needs to be thought about.
The tedious part is assigning all property names. But you could start with exposing only 1 or 2 classes values. Anything else as time comes by.
delta data and rate data would be provided by web client code based on what its authors could achieve with the static and dynamic data.
Remaining: documentation of properties for VFO authors #661 to make use of them.
Beta Was this translation helpful? Give feedback.
All reactions