You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently using the suggested pattern in the lib documentation.
What I am trying to achieve is to construct C++ objects from JSON strings. The strategy that I'm deploying is very similar to what is suggested in the lib doc.
I pass a reader and an input stream object to a class constructor and I'm parsing the JSON by passing the constructed object reference as the handler.
One difficulty that I have is that my handler class is now littered with a bunch of data members that their only purpose is for providing a parsing context. Past the object construction, they aren't needed anymore...
I was thinking of 2 solutions:
Have rapidjson pass a parsing context to the various handler methods... (similar to what expat offers)
Have a friend builder class.
I think #2 has the most potential... Maybe add this idea to the doc to help others... Here is the concept:
class A { public: A(Reader r, InputStream is) { BuilderHandler handler(*this); r.parse(is, handler); } private: class BuilderHandler { BuilderHandler(A &a) : a_(a) {} private: // bunch of context parsing variables A &a_; }; friend class BuilderHandler; };
The text was updated successfully, but these errors were encountered:
I'm currently using the suggested pattern in the lib documentation.
What I am trying to achieve is to construct C++ objects from JSON strings. The strategy that I'm deploying is very similar to what is suggested in the lib doc.
I pass a reader and an input stream object to a class constructor and I'm parsing the JSON by passing the constructed object reference as the handler.
One difficulty that I have is that my handler class is now littered with a bunch of data members that their only purpose is for providing a parsing context. Past the object construction, they aren't needed anymore...
I was thinking of 2 solutions:
I think #2 has the most potential... Maybe add this idea to the doc to help others... Here is the concept:
class A { public: A(Reader r, InputStream is) { BuilderHandler handler(*this); r.parse(is, handler); } private: class BuilderHandler { BuilderHandler(A &a) : a_(a) {} private: // bunch of context parsing variables A &a_; }; friend class BuilderHandler; };
The text was updated successfully, but these errors were encountered: