urnathan / libcody

Compiler/BuildSystem Interface Library
Apache License 2.0
24 stars 6 forks source link

Expose MessageBuffers to dervied server class #14

Closed jjravi closed 4 years ago

jjravi commented 4 years ago

I added a state to client_state object, see https://github.com/urnathan/libcody/pull/11#discussion_r481191661.

I needed to pass the derived Server class, called client_state in make@lto-hack, object to InvokeSubProcessRequest() in derived Resolver class, called module_resolver in make@lto-hack. The virtual function InvokeSubProcessRequest() of Cody::Resolver takes the Cody::Server base class as the input. This virtual function gets called in ProcessRequest() in Cody::Server.

virtual int InvokeSubProcessRequest (Server *s, std::vector<std::string> &args);

I could not override this virtual function InvokeSubProcessRequest() because the input parameter is a derived Cody::Server, client_state. So, I declared InvokeSubProcessRequest() with client_state as an input. I need to re-implemented ProcessRequests() in client_state which requires the MessgeBuffers to be protected instead of private, so the derived Cody::Server class will have access to them, see https://github.com/jjravi/make/commit/08e132d780cd7451af186f1ce2d64a1989f43400

urnathan commented 4 years ago

sorry, this smells wrong. Why do you need direct access to these members? you should not need to reimplement base-class functionality. The usual way to deal with the overriding thing you mention is to override the function (using a Server * parm) and then static cast (or dyn_cast if you want to have checking) that to your client_state type in the overriding fn.

jjravi commented 4 years ago

Ah yes, static_cast solved that issue. Never mind about this PR, thanks!