Re: [Cppcms-users] How to set default response().out() stream precision?
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-06-21 10:34:54
|
----- Original Message ----- > From: "ele...@ex..." <ele...@ex...> > To: Artyom Beilis <art...@ya...>; cpp...@li... > Cc: > Sent: Thursday, June 21, 2012 1:17 PM > Subject: Re: [Cppcms-users] How to set default response().out() stream precision? > >> <% gt "{1,precision =10}" using my_high_precision_value > %> > > That's just not feasible. If I had to do it for every number on the page, > id have to spend like a whole day changing it all. > >> If you need to change it globally create a small function in you topmost >> application >> class that all your classes are derived from: >> >> void render(std::string const &template_name,cppcms::basi_context > &c) >> { >> response().out() << std::setprecision(10); >> cppcms::application::render(template_name,c); >> } > > > Yes yes, I'm aware of this. However because the render functions are not > virtual, so they are not intended for overloading. At least that's the way > i've been taught so I did not want to do this either. > See, you can override non-virtual function as well but the parent classes you call the old one. In our case it is not used by parent (application) class, it rather provides convenience interface to base_content::app_guard g(content,my_app); service().views_pool().render(my_app.context().skin(),template_name,my_app.response().out(),content); So this is not a problem - may be not the most beautiful solution but it works and consistent with the standard. If you don't like this create some other "hp_render" function and refactor the code in much fewer places. > Anyway, is there are a reason they are not virtual? There's other > functions cppcms::application that are virtual. > > Petr > Generally the only functions that are virtual are thous that are expected to be overridden. I can suggest an another option, consider you have some global skin: <% template master uses master %> <html> <head> .... <% end template %> Just add a simple code like: <% template master uses master %> <% c++ out()<<std::setprecision(10) %> <html> <head> .... <% end template %> And every template that derives from the master page would include it... See, there are many things you can do to override the default of the standard C++ std::ostream. It is not a big problem. Also if you are looking for correct solution for global altering of response().out() settings at cppcms level you may want to add some callbacks to cppcms::http::response like void on_before_stream_output(booster::function<(cppcms::http::context &)> const &); void on_after_stream_output(booster::function<(cppcms::http::context &)> const &); Such a patch I can accept as it makes much more sense and may be actually useful for other things as well like altering a session or HTTP headers globally. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ |