Re: [Cppcms-users] Plugins and templates
Brought to you by:
artyom-beilis
From: Julian P. <ju...@wh...> - 2010-08-19 01:23:25
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just another question: The plugins currently return their own content class derived from a master class containing common properties such as a page title. Because C++ doesn't allow to redefine return types when overloading virtual methods, I use a booster::shared_ptr<content::master> for passing the content class. The problem that occurs is the following: Example: Plugin HelloWorld has a content class content::hello_world derived from content::master which is returned on calling handleRequest() wrapped in a booster::shared_ptr<content::master>. This content class now has to be rendered by the main application which does not now which content subclass is wrapped in the pointer / knows it at runtime only, so that a hard-compiled conversion via booster::dynamic_pointer_cast<content::hello_world,content::master> is not possible, because there could be other plugins returning different subclasses of the master than hello_world. The plugin tells the main application to use the view 'hello_world' for rendering. This view uses content::hello_world, because it needs access to some fields defined only in the subclass. Now, if I call render("hello_world", *c.get()); where c is the returned shared_ptr, cppcms catches a std::bad_cast exception occuring in http_context.c, line 132. If I use booster::dynamic_pointer_cast beforehand and pass the casted shared_ptr, everything works. So what I need is basically the following: 1. A way to use something like dynamic_pointer_cast with a type that is known only at runtime (could be queried from the plugin) 2. Or: The template compiler should not write a constructor expecting content::hello_world but instead from a booster::shared_ptr<content::master> which is then dynamic_pointer_cast'ed to the required pointer to a content::hello_world. Assumption for the compiler would be, that the base class is always content::master, so that the information from <% view uses content::hello_world %> would be used to construct this: content::hello_world &content; hello_world(booster::shared_ptr<content::master> ptr) { booster::shared_ptr<content::hello_world> hptr = booster::dynamic_pointer_cast<content::hello_world,content::master> (ptr); content = *hptr.get(); } Any ideas on that matter? Thank you, Julian -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJMbIeDAAoJENidYKvYQHlQqLMQAMXLquJctetMqg47huo+4D8l Z1a70oCfCwtQjL0DYdV7o8zMBZL4CKjC3H7i0XsCVcR3TokFl+EjBCQtJEQK+JQE ZWQ2SwhY3HwKELaNSF2wXt0H+iZgwjLDc2UUvx9t0hEpdesoL0LG2Nl0FgBUvGX7 BxUDmspjiWBsFTfSBHB9sVy4Iq7RXD5HLvnIJEaYN8KnZ8NmllLIl+VX/N3ECrgW GNxD057MRih2eMn999GWEoRJPOytMWwgq0F2IQRdzRPKIi+BQbFWXwQRQ7i0mbUX Lmm6WRbqGjt+eeEZWz6QkAsvX52xgJWGLPJw+PQmXADpd2O0PV2WS9uqtVxdeSrP fatJwAl/2+9uj5uIXKhkiHhkqW9AmmNIXGDgeo9F17RsryCgsWqlVlpSQoZBXSA0 g6PpIm2iDGBVue1+5X9LMxUbVLv7m1rJNaXJIsHg9yN/ebBK9li23zXFffQ2I1uj z2o4O+WoyOD6vCUbYa38M2kJU+Iuwwt4fjvZVmbr0wezeLUPtsXp2Zw5DLZNWUC1 gEhmCrDFvgQXcUvlQwYzmDYLPrNq7y5ovkgRccNt/kY0kxLJouahNtFfv7GLnVIl BWjef8qQ4vS+l9h6e5g5R+Et50DSSDKqpdoWGSr4YvaG5cCjEpfI9doISC05QTSv o84I1M1kAcEpUQGu9Q23 =hpb4 -----END PGP SIGNATURE----- |