cppcms-users Mailing List for CppCMS C++ Web Framework (Page 113)
Brought to you by:
artyom-beilis
You can subscribe to this list here.
2009 |
Jan
|
Feb
(22) |
Mar
|
Apr
(3) |
May
|
Jun
(4) |
Jul
|
Aug
|
Sep
|
Oct
(15) |
Nov
(16) |
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(4) |
Feb
|
Mar
(8) |
Apr
(8) |
May
(8) |
Jun
(36) |
Jul
(63) |
Aug
(126) |
Sep
(47) |
Oct
(66) |
Nov
(46) |
Dec
(42) |
2011 |
Jan
(87) |
Feb
(24) |
Mar
(54) |
Apr
(21) |
May
(22) |
Jun
(18) |
Jul
(22) |
Aug
(101) |
Sep
(57) |
Oct
(33) |
Nov
(34) |
Dec
(66) |
2012 |
Jan
(64) |
Feb
(76) |
Mar
(73) |
Apr
(105) |
May
(93) |
Jun
(83) |
Jul
(84) |
Aug
(88) |
Sep
(57) |
Oct
(59) |
Nov
(35) |
Dec
(49) |
2013 |
Jan
(67) |
Feb
(17) |
Mar
(49) |
Apr
(64) |
May
(87) |
Jun
(64) |
Jul
(93) |
Aug
(23) |
Sep
(15) |
Oct
(16) |
Nov
(62) |
Dec
(73) |
2014 |
Jan
(5) |
Feb
(23) |
Mar
(21) |
Apr
(11) |
May
(1) |
Jun
(19) |
Jul
(27) |
Aug
(16) |
Sep
(5) |
Oct
(37) |
Nov
(12) |
Dec
(9) |
2015 |
Jan
(7) |
Feb
(7) |
Mar
(44) |
Apr
(28) |
May
(5) |
Jun
(12) |
Jul
(8) |
Aug
|
Sep
(39) |
Oct
(34) |
Nov
(30) |
Dec
(34) |
2016 |
Jan
(66) |
Feb
(23) |
Mar
(33) |
Apr
(15) |
May
(11) |
Jun
(15) |
Jul
(26) |
Aug
(4) |
Sep
(1) |
Oct
(30) |
Nov
(10) |
Dec
|
2017 |
Jan
(52) |
Feb
(9) |
Mar
(24) |
Apr
(16) |
May
(9) |
Jun
(12) |
Jul
(33) |
Aug
(8) |
Sep
|
Oct
(1) |
Nov
(2) |
Dec
(6) |
2018 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
(14) |
Jun
(1) |
Jul
(9) |
Aug
(1) |
Sep
(13) |
Oct
(8) |
Nov
(2) |
Dec
(2) |
2019 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2020 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(9) |
Jul
(6) |
Aug
(25) |
Sep
(10) |
Oct
(10) |
Nov
(6) |
Dec
|
2021 |
Jan
|
Feb
|
Mar
(7) |
Apr
(1) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(9) |
Oct
(1) |
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Artyom B. <art...@ya...> - 2011-06-13 06:53:03
|
Ignore Please |
From: augustin <aug...@ov...> - 2011-06-06 10:27:36
|
Alec, Good luck with your exams, and have fun with cppcms. Blessings, Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: Alec T. <ale...@gm...> - 2011-06-06 10:18:39
|
Okay, well I'm amidst exams ATM, I'll start coding (heavily) in 20 days. In the meantime, I'll play around with examples and see if I can get my template done =] On Mon, Jun 6, 2011 at 4:35 AM, Artyom Beilis <art...@ya...> wrote: >> From: Alec Taylor <ale...@gm...> > >> >> I'll Checkout from the SVN and start coding in >> ~week > > Actually it is better to use the latest stable version unless you > have some bugs fixed in svn. > > Currently it is quite close to svn-trunk. > > Because svn trunk still can become broken once in a while > during development. > > In any case svn version is quite stable. > >> >> Here are some names (off the top of my head), add your own below (or >> to the wiki :P): >> >> [list of names] >> > > Actually there was a good name once as potential replacement but it was decided > not to change cppcms as it is already well known name and > replacement of the name should also be followed by namespace > renaming (causing breaking existing software) > > So it was decided to keep not-so-good-but-well-known-name CppCMS > > Artyom > > ------------------------------------------------------------------------------ > Simplify data backup and recovery for your virtual environment with vRanger. > Installation's a snap, and flexible recovery options mean your data is safe, > secure and there when you need it. Discover what all the cheering's about. > Get your free trial download today. > http://p.sf.net/sfu/quest-dev2dev2 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Artyom B. <art...@ya...> - 2011-06-05 18:35:14
|
> From: Alec Taylor <ale...@gm...> > > I'll Checkout from the SVN and start coding in > ~week Actually it is better to use the latest stable version unless you have some bugs fixed in svn. Currently it is quite close to svn-trunk. Because svn trunk still can become broken once in a while during development. In any case svn version is quite stable. > > Here are some names (off the top of my head), add your own below (or > to the wiki :P): > > [list of names] > Actually there was a good name once as potential replacement but it was decided not to change cppcms as it is already well known name and replacement of the name should also be followed by namespace renaming (causing breaking existing software) So it was decided to keep not-so-good-but-well-known-name CppCMS Artyom |
From: Alec T. <ale...@gm...> - 2011-06-05 15:37:05
|
Thanks for the info, I'll Checkout from the SVN and start coding in ~week (I'm a student currently half-way through my IT Degree) Here are some names (off the top of my head), add your own below (or to the wiki :P): webC++ sharpC++ netC++ speedC++ NetScalC++ ScalC++ UncppNet accpt-Net (accpt means accompaniment, add an extra p in for fun) ScalNet NetScal On Sun, Jun 5, 2011 at 9:45 PM, augustin <aug...@ov...> wrote: > > Speaking of: > >> Keep in mind that the questions you may have, others may also have them in >> the future. Your help in ensuring that each question need only be asked >> once (by improving the wiki as we go along) will be very appreciated. > > >> > BTW: Are there any plans to disambiguate the name of this project, >> > since it isn't a CMS? > > http://art-blog.no-ip.info/wikipp/en/page/faq/diff/19vs20 > > > Augustin. > > > > -- > Friends: http://www.reuniting.info/ > My projects: > http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ > http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ > http://openteacher.info/ http://minguo.info/ > http://www.wechange.org/ http://searching911.info/ > > > > > > > > > > > > > . > > ------------------------------------------------------------------------------ > Simplify data backup and recovery for your virtual environment with vRanger. > Installation's a snap, and flexible recovery options mean your data is safe, > secure and there when you need it. Discover what all the cheering's about. > Get your free trial download today. > http://p.sf.net/sfu/quest-dev2dev2 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: augustin <aug...@ov...> - 2011-06-05 12:13:01
|
Speaking of: > Keep in mind that the questions you may have, others may also have them in > the future. Your help in ensuring that each question need only be asked > once (by improving the wiki as we go along) will be very appreciated. > > BTW: Are there any plans to disambiguate the name of this project, > > since it isn't a CMS? http://art-blog.no-ip.info/wikipp/en/page/faq/diff/19vs20 Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: augustin <aug...@ov...> - 2011-06-05 12:12:54
|
Alec, Welcome back on the list. First of all, when we reply to you, we assume you have at least a fair amount of experience with C++ (you were asking about PHP and C++ frameworks at the same time). If you don't, that's ok to (I am myself a newbie) but then be ready to spend a fair amount of time to learn the basics. On Sunday 05 June 2011 06:51:39 pm Alec Taylor wrote: > Augustin: Thanks for the suggestions, however I've found the examples > to be broken (not showing anything other than title), i.e.: > http://art-blog.no-ip.info/cppcms_ref_v0_99/hello_8cpp-example.html See: http://art-blog.no-ip.info/wikipp/en/page/cppcms_1x_tut_hello Download the source code of cppcms. See the sourceforge project for the exact download procedure. cppcms uses svn. In the source code, see within the example folder. Compile the examples and run them. Study their code. Copy them elsewhere and modify the code to start playing with the various features. > Please tell me where I can find CppCMS documentation. http://art-blog.no-ip.info/wikipp/en/page/main Registration to the wiki is easy. Keep in mind that the questions you may have, others may also have them in the future. Your help in ensuring that each question need only be asked once (by improving the wiki as we go along) will be very appreciated. > BTW: Are there any plans to disambiguate the name of this project, > since it isn't a CMS? The developer asked for suggestions for a better name 3 years ago, but received 0 replies: http://art-blog.no-ip.info/cppcms/blog/post/23 I am not sure Artyom would be open today to changing the name.... provided we have a nice alternative! See also the FAQ: "If CppCMS is not a CMS, where does this name come from?" http://art-blog.no-ip.info/wikipp/en/page/faq See the developer's blog for more info: http://art-blog.no-ip.info/cppcms/blog Have fun! Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: Alec T. <ale...@gm...> - 2011-06-05 10:51:46
|
Thanks for the replies (and sorry for this late one) Augustin: Thanks for the suggestions, however I've found the examples to be broken (not showing anything other than title), i.e.: http://art-blog.no-ip.info/cppcms_ref_v0_99/hello_8cpp-example.html Aris: Thanks, I'll take a look. My search results will be ranked by accuracy, you see the results will be very statistical (66% correct) &etc Please tell me where I can find CppCMS documentation. Thanks, Alec Taylor BTW: Are there any plans to disambiguate the name of this project, since it isn't a CMS? On Fri, Apr 29, 2011 at 11:06 AM, Aris Setyawan <ari...@gm...> wrote: > Hi Alec, > > For fulltext search, you must use fulltext index. If you are mysql > user, use spynx index (sphinxsearch.com), for postgresql user, use > tsearch2 index and for sqlite user use FTS3/4 index. > > I'm now also developing web search app. For maximizing performance, > I'm not using javascript at all. html + css is enough for me. > > Don't forget to use ranking in your search result. > > On Thu, Apr 28, 2011 at 8:34 PM, augustin <aug...@ov...> wrote: >> Good Evening Alec, >> >> On Thursday 28 April 2011 09:17:37 pm Alec Taylor wrote: >>> Please tell me if it's possible to do in CppCMS, and if so, how. >> >> Yes, it's possible. The cppcms library is well conceived, and I find the cppdb >> (DB layer) library especially easy to use. >> >> How? Well, check the wiki for simple tutorials and documentation , and check >> all the examples delivered with the source code. That will get you started in >> understanding how to use the libraries. >> >> The templating layer will allow you to achieve the look you are after, like in >> your mockup. Again, check the wiki for more information. >> >> Blessings, >> >> Augustin. >> >> >> >> >> -- >> Friends: http://www.reuniting.info/ >> My projects: >> http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ >> http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ >> http://openteacher.info/ http://minguo.info/ >> http://www.wechange.org/ http://searching911.info/ >> >> >> >> >> >> >> >> >> >> >> >> >> . >> >> ------------------------------------------------------------------------------ >> WhatsUp Gold - Download Free Network Management Software >> The most intuitive, comprehensive, and cost-effective network >> management toolset available today. Delivers lowest initial >> acquisition cost and overall TCO of any competing solution. >> http://p.sf.net/sfu/whatsupgold-sd >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > ------------------------------------------------------------------------------ > WhatsUp Gold - Download Free Network Management Software > The most intuitive, comprehensive, and cost-effective network > management toolset available today. Delivers lowest initial > acquisition cost and overall TCO of any competing solution. > http://p.sf.net/sfu/whatsupgold-sd > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Artyom B. <art...@ya...> - 2011-05-21 09:40:52
|
Small note, instead of: return_response("Not authorised"); return false; You can also return a error on HTTP level (not JSON-RPC): context().response().make_error_response(cppcms::http::response::forbidden); return false; But I think this is generally bad idea to make a error response on transport level rather then on JSON-RPC level. Artyom |
From: Artyom B. <art...@ya...> - 2011-05-21 09:31:04
|
> So if I do just that, the request parsing is made twice. One for obtain > method name for check_privileges and another into json_rpc_server::main() > function. I guess there are no other solution in actual design. Is it true? If the privilege control is made on the level of each specific method like get(id) // for all update(id,new_value) // for privilege user Then you should check it inside method and not outside, void update(std::string const &id,my_object const &vale) { if(!check_permissions()) { return; } objects_[id]=value; } void get(std::string const &id) { return_result(objects_[id]); } bool check_permissions() { if(session().get("role","nobody")!="admin") { return_response("Not authorised"); return false; } return true; } The point you should not decouple parts of code that are truly connected. This way you know from looking to the method its permissions. Consider you add in future new method add() that is for priviliged users thus you have to add permissions control in one place and method itself in other. It is dangerous practice. Artyom |
From: Daniel V. <chi...@gm...> - 2011-05-19 17:08:40
|
On Thu, 2011-05-19 at 00:07 -0700, Artyom Beilis wrote: > > This is why it is virtual. You want pre/post-actions? > > void main(std::string param) > { > // some pre-action > cppcms::rpc::json_rpc_server::main(param); > // some post-actions > } > > The privilege validations depends on session() object (user and his rights) and method name. Then: void main(std::string param) { if( check_privileges(context()) ) { cppcms::rpc::json_rpc_server::main(param); } else { // not authorized } } So if I do just that, the request parsing is made twice. One for obtain method name for check_privileges and another into json_rpc_server::main() function. I guess there are no other solution in actual design. Is it true? One solution is give to the user of json_rpc_server class the possibility to add pre action after parsing json request but before dispatching. Thanks. |
From: Artyom B. <art...@ya...> - 2011-05-19 07:18:01
|
----- Original Message ---- > From: Daniel Vallejos <chi...@gm...> > To: cpp...@li... > Sent: Thu, May 19, 2011 7:17:31 AM > Subject: [Cppcms-users] CPPDB and Oracle support > > Hello. > > Oracle Support is on cppdb roadmap? > cppdb supports ODBC. So given a good ODBC driver it should support Oracle or any other RDBMS. However: 1. I do not have an installation of Oracle database itself. 2. I have no experience with OCI API. So I'm not going to implement one myself. So if you need a native driver for Orcale you need to implement one - it should not be that hard if you know OCI. Or you need to find somebody who is willing to contribute one. In any case you can look on ODBC and if you can successfully use ODBC with Oracle please report me. There is also a Unit test (that may need some tweaks for Orcale) that can give you a way to know of ODBC/Oracle works well. I'd would be glad if you can test cppdb with Oracle and maybe tweak a Unit test a little if needed to make sure it passes. In any case if you need a good library for Oracle that supports other RDMBSs as well you can take a look on SOCI. >From my experience it does not support other DB too well and it does not have CppDB's features like caching of prepared statements. Best, Artyom |
From: Artyom B. <art...@ya...> - 2011-05-19 07:07:21
|
>Question 1. > >I am implementing a json rpc server (cppcms::rpc::json_rpc_server) with >privileges. > >One possible solution is for each rpc method do the following: > >void my_rpc_server::get_sensible_data() >{ >if ( check_privileges() ) { > >// method implementation >//... >} >else { >return_error("not authorized"); >} >}; It depends on the level you check the privileges and how do you want to handle an answer and protocol. If you use HTTP session to check the privileges then you can do different things: 1. Return 403 Forbidden status on HTTP level before you even access to RPC service. You can overload the main function and check permissions, but this is generally limited for entire service not specific methods. This is something like "prevent executable from running as you don't have permissions to run it at OS leve" 2. Return a error code for specific call on the protocol level. This is something like "tell the chroot() or unlink() system calls return error code EACCES" It is really a question of your design and the design of the protocol. If some methods are forbidden, return error code is best, if all the service is forbidden return 403 as above. > >The problem is that I think this solution is not good because I would like to >decouple the privilege system of the rpc methods definitions. > >Another theoretical solution would be extend virtual main method to add desired >pre actions: > >class my_rcp : public cppcms::rpc::json_rpc_server >{ >virtual void main(std::string); >}; > > >void main(std::string //unused) >{ >json_rpc_request req = parse_json_rpc_request(context()); // Ideally this method > >should be protected and implemented in json_rpc_server. > This is why it is virtual. You want pre/post-actions? void main(std::string param) { // some pre-action cppcms::rpc::json_rpc_server::main(param); // some post-actions } >// Added pre actions > >if ( check_privileges(req.method_name) ) >{ >dispatch_request(req); // Ideally this method should be protected and >implemented in json_rpc_server. >} >else { >return_error("not authorised"); >} >} > > >AFAIK that is not posible with current json_rpc_server implementation. > AFAIK it should work fine, just overload main. > >Question 2. > >I can't implement a json rpc method with a json::value argument, for example the > >following example not compile: > >void my_rpc_server::my_method(cppcms::json::value v) >{ >} > >One posible workaround is define a json::value to json::value trait: > >namespace cppcms { namespace json { > template<> > struct traits<value> { > static value get(value const &v) { > return v; > } > static void set(value &v,value const &in) { > v = in; > } > }; >}} // end cppcms::json > >But I guest it is not optimal because nedless copy overhead. > If you want "native" json parameter you should create method that receives an array as parameter my_method(cppcms::json::array const &v) { } And the use something like boost::bind to create a reference. bind("sum",boost::bind(&json_service::my_method,this,_1),method_role); Or if you wan't want to use boost struct binder { binder(my_service &s) : s_(&s) void operator()(cppcms::json::array const &v) const { s_->my_method(v); } my_service *s_; }; And then bind("sum",binder(this),method_role); Actually you bring a good point, I need to provide such binder my default something like: cppcms::rpc::json_native_method in addition to json_method Fill a feature request for the last one so I will not forget. Best. Artyom |
From: Daniel V. <chi...@gm...> - 2011-05-19 04:17:42
|
Hello. Oracle Support is on cppdb roadmap? Thank you. |
From: Daniel V. <chi...@gm...> - 2011-05-18 20:57:20
|
Hello, Question 1. I am implementing a json rpc server (cppcms::rpc::json_rpc_server) with privileges. One possible solution is for each rpc method do the following: void my_rpc_server::get_sensible_data() { if ( check_privileges() ) { // method implementation //... } else { return_error("not authorized"); } }; The problem is that I think this solution is not good because I would like to decouple the privilege system of the rpc methods definitions. Another theoretical solution would be extend virtual main method to add desired pre actions: class my_rcp : public cppcms::rpc::json_rpc_server { virtual void main(std::string); }; void main(std::string //unused) { json_rpc_request req = parse_json_rpc_request(context()); // Ideally this method should be protected and implemented in json_rpc_server. // Added pre actions if ( check_privileges(req.method_name) ) { dispatch_request(req); // Ideally this method should be protected and implemented in json_rpc_server. } else { return_error("not authorised"); } } AFAIK that is not posible with current json_rpc_server implementation. What is the best approach to add pre actions (ie: check privileges) to rpc method invocation?. Question 2. I can't implement a json rpc method with a json::value argument, for example the following example not compile: void my_rpc_server::my_method(cppcms::json::value v) { } One posible workaround is define a json::value to json::value trait: namespace cppcms { namespace json { template<> struct traits<value> { static value get(value const &v) { return v; } static void set(value &v,value const &in) { v = in; } }; }} // end cppcms::json But I guest it is not optimal because nedless copy overhead. Thank you. |
From: Artyom B. <art...@ya...> - 2011-05-16 18:19:47
|
> From: Daniel Vallejos <chi...@gm...> > > Hello. > > I need catch common sql errors in cppdb, such as duplicate key insert > error or other constraint errors. > > How to accomplish this in a portable way with cppdb? > Just catch cppdb_error exception. There is no portable way to get specific error. Also it is better to check the constraints before you execute something and not relay on them in normal flow. i.e.: cppdb::translation tr(sql); cppdb::result r; sql << "SELECT id FROM foo where id=?" << id >> cppdb::row >> r; if(r.empty()) { sql << "INSERT ... " ... ; tr.commit(); } else { tr.rollback(); // Handle error. } Artyom |
From: Daniel V. <chi...@gm...> - 2011-05-16 15:50:32
|
Hello. I need catch common sql errors in cppdb, such as duplicate key insert error or other constraint errors. How to accomplish this in a portable way with cppdb? Thanks. |
From: augustin <aug...@ov...> - 2011-05-05 13:31:47
|
On Thursday 05 May 2011 12:52:44 am Artyom wrote: > > getline(ss, r); > > return r; > > It is better to call > > return ss.str() Oops! This one is very embarrassing given the time I wasted trying to figure out a simple way to extract the string from the stream! Thank you very much for all your comments on my code. They're duly noted. I appreciate it. > http://cppcms.sourceforge.net/cppcms_ref_v0_99/namespacecppcms_1_1filters. > html > > So just write in the template > > > <% tt | datetime %> > > Or even with more fine grained control > > <% tt | strftime("%Y-%m-%d %H:%M:%S %Z") %> > > > where tt is just time_t in your context :-) Ah, yes! You just answered my earlier question about locales in a cppcms context. This is actually what I meant. I knew my approach didn't feel right. It works as it should, now. Thanks again, augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: Artyom <art...@ya...> - 2011-05-04 16:52:53
|
> > BTW, thanks to your help, I got the missing piece, so that I finally managed >to > > do what I wanted to do: > > #include <sstream> > #include <boost/locale.hpp> > > std::string timestamp_to_string(time_t const& tt) { > using namespace boost::locale; > generator gen; > std::locale::global(gen("en_US.UTF-8")); > std::stringstream ss; > ss.imbue(std::locale()); > ss << as::date << tt << " "; > ss << as::time << tt << std::endl; > std::string r = ""; > getline(ss, r); > return r; > } > Few points: > timestamp_to_string(time_t const& tt) It is better to write timestamp_to_string(time_t tt) As time_t is integral type and it is better to pass it by value. > using namespace boost::locale; > generator gen; > std::locale::global(gen("en_US.UTF-8")); > ss.imbue(std::locale()); Is very inefficient as locale generation is very heavy procedure. In CppCMS context you have this member function: http://cppcms.sourceforge.net/cppcms_ref_v0_99/classcppcms_1_1http_1_1context.html#39fde738210daf84deee691f45260e5b So basically inside cppcms::application based class just write std::locale loc = context().locale(); or std::locale loc = context().locale("en_US.UTF-8"); It returns the locale defined in configuration file for you and it would cache the locale automatically for future use. > std::locale::global(gen("en_US.UTF-8")); > ss.imbue(std::locale()); Even if you use it, it is better to write ss.imbue(gen("en_US.UTF-8")); And not set global locale and then create a locale instance from global one. > ss << as::date << tt << " "; > ss << as::time << tt << std::endl; It is better to write ss << as::datetime << tt; > std::string r = ""; r is empty by default, no need r=""; > getline(ss, r); > return r; It is better to call return ss.str() Of course without "<<std::endl" > It took me 10-20 hours to research, read and understand enough to come up with > > the seemingly simple piece of code above. :-/ > > I use it to format unix timestamps before pushing it to my > cppcms::base_content object. > > I don't know if it's the right approach, but it works... > It is much simpler, you have filers namespace http://cppcms.sourceforge.net/cppcms_ref_v0_99/namespacecppcms_1_1filters.html So just write in the template <% tt | datetime %> Or even with more fine grained control <% tt | strftime("%Y-%m-%d %H:%M:%S %Z") %> where tt is just time_t in your context :-) > > > Augustin. Best, Artyom |
From: augustin <aug...@ov...> - 2011-05-04 15:32:48
|
On Wednesday 04 May 2011 09:29:39 pm Artyom wrote: > http://www.boost.org/doc/libs/1_46_1/more/getting_started/unix- variants.html > http://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html Ha! Even by reading the official boost documentation page about linking, I wouldn't have guessed what linker option to chose. For Linux/g++, at least, it wouldn't hurt mentioning the -lboost_locale in the docs. > Was too damn busy, I'll try to get to it this week. > Drop me a mail if I forget once again. There's no actual hurry as far as I am concerned, but something just came up today and I may have to travel to Europe for two weeks later this month, so I won't be available then, if I do go. BTW, thanks to your help, I got the missing piece, so that I finally managed to do what I wanted to do: #include <sstream> #include <boost/locale.hpp> std::string timestamp_to_string(time_t const& tt) { using namespace boost::locale; generator gen; std::locale::global(gen("en_US.UTF-8")); std::stringstream ss; ss.imbue(std::locale()); ss << as::date << tt << " "; ss << as::time << tt << std::endl; std::string r = ""; getline(ss, r); return r; } It took me 10-20 hours to research, read and understand enough to come up with the seemingly simple piece of code above. :-/ I use it to format unix timestamps before pushing it to my cppcms::base_content object. I don't know if it's the right approach, but it works... Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: Artyom <art...@ya...> - 2011-05-04 13:29:47
|
> > > Is this platform/compiler dependent? Can't this kind of thing be > > > documented? Anyway, in this case, I found it was -lboost_locale. > > > > This is something Boost general not related > > to Boost.Locale specifically. > > Yes, but it affects every single boost library, including yours. Maybe you can > > add such necessary information to the boost.locale documentation. > It is not something trivial especially when you use MSVC with its endless incompatible build variants. See: http://www.boost.org/doc/libs/1_46_1/more/getting_started/unix-variants.html http://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html > ever considered using git? Subversion has a huge advantage of working over https behind firewalls and in various even untrusted networks. So if you work from University network or just some public network there is no replacement for https support. GIT does not allow to perform commits over https protocol like SVN. > (I am still waiting for your review of my form.h patch, > though...). I'm sorry, you are right. Was too damn busy, I'll try to get to it this week. Drop me a mail if I forget once again. Regards, Artyom |
From: augustin <aug...@ov...> - 2011-05-04 12:46:13
|
On Wednesday 04 May 2011 08:37:33 pm augustin wrote: > In the boost.locale documentation, as part of the introduction, you ought > to make a list of assumed knowledge, with some links like those I provided > above, to redirect people like me to background information. Oops. You actually already do: http://cppcms.sourceforge.net/boost_locale/html/std_locales.html I read it too quickly the first time and didn't understand what I was reading. It's slowly sinking in... Sorry for the noise. Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: augustin <aug...@ov...> - 2011-05-04 12:40:38
|
On Wednesday 04 May 2011 03:35:35 pm Artyom wrote: > See: http://thread.gmane.org/gmane.comp.lib.boost.devel/218008 > [...] > See section about locale generation. Thanks. The discussion thread you link to, and your mention prompted me to do some further research and I finally figured out that I was missing yet another whole chapter of this very complex, yet fascinating language (C++). I hadn't grasped how the concept of locale was deeply embedded within the language itself: http://www.cplusplus.com/reference/std/locale/ http://stdcxx.apache.org/doc/stdlibug/VII.html chapter 22 of c++0x, chapter 27 of c++03. With only 400+ hours of experience with C++, I still count as a very beginner. It's been 400 hours worth of shocks at discovering how many facets there are to the language, and how many ancillary skills (compiling, linking, gnu tools, Makefile, cmake, etc.) and libraries (std, STL, std::locale, boost, cppcms, cppdb and others I am using...) I have yet to master to become, hopefully one day, a decent C++ programmer. In the boost.locale documentation, as part of the introduction, you ought to make a list of assumed knowledge, with some links like those I provided above, to redirect people like me to background information. I'm going to be reading about all this now... > http://stackoverflow.com/questions/3467153/is-there-an-intelligent-way-to-k > now- > > > the-name-of-the-library-to-link-to-at-compile > > Is this platform/compiler dependent? Can't this kind of thing be > > documented? Anyway, in this case, I found it was -lboost_locale. > > This is something Boost general not related > to Boost.Locale specifically. Yes, but it affects every single boost library, including yours. Maybe you can add such necessary information to the boost.locale documentation. > Take a look on libs/locale/examples > with full code to see what you miss. Oh, yes, I did miss that! Very cool, thanks. Thanks again for your constant support. Your answers were very helpful in pointing me in the right direction. I have much study to do, now... ;) Btw, since I have a svn checkout (ever considered using git? Yet another thing I need to learn: how to link a local git working directory to a svn upstream source. I know there are tutorials about it, that I can find easily... there is so much to do and to learn!)... I was saying: since I checked out boost.locale from svn, let me know if you'd like me to prepare a patch for the documentation.... (I am still waiting for your review of my form.h patch, though...). Blessings, Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: Artyom <art...@ya...> - 2011-05-04 07:35:44
|
> From: augustin <aug...@ov...> > > (second try to send this to the list) > > Hello, > > Speaking of boost(er).locale, I am having problems formatting dates. > > I tried the simple example from here: > [...] See: http://thread.gmane.org/gmane.comp.lib.boost.devel/218008 > I'm sure I am missing something simple. > Probably, I need to set the locale first, but it's not clear to me how to do > it. See section about locale generation. > > Also, a grip I have with most/all boost libraries, is that one never knows > what option to pass to the linker: > http://stackoverflow.com/questions/3467153/is-there-an-intelligent-way-to-know- > the-name-of-the-library-to-link-to-at-compile > Is this platform/compiler dependent? Can't this kind of thing be documented? > Anyway, in this case, I found it was -lboost_locale. > This is something Boost general not related to Boost.Locale specifically. > For boost.locale, more, fully working, compilable examples would help. > Take a look on libs/locale/examples with full code to see what you miss. > - > > Most boost libraries documentation are written for very experienced C++ > developers. From a newbie perspective, I find most documentation very obtuse. >I > > checked boost.date_time for a long while, and still couldn't understand >enough > > to actually make use of it. I still have much to learn before I can understand > > a lot of the boost documentation. > > - This specific "problem" would be added to FAQ. > > Generally speaking, within the context of a cppcms application, what is the > best/recommended way to format dates, times and such? > Basically, I have a unix timestamp, and I want to output it in human readable > form, both in the UTC and locale timezone. > Read the tutorial there are an examples how to make UTC, local timezone (default) or custom time zone output (there is a manipulator for this purpose and formatting flags). Also the way you want to display dates is application specific and dependent on use case. Best, Artyom |
From: augustin <aug...@ov...> - 2011-05-04 00:27:04
|
(second try to send this to the list) Hello, Speaking of boost(er).locale, I am having problems formatting dates. I tried the simple example from here: http://cppcms.sourceforge.net/boost_locale/html/formatting_and_parsing.html #include <iostream> #include <sstream> #include <boost/locale.hpp> using std::cout; using std::endl; using namespace boost::locale; int main() { double now=time(0); cout << "Today is "<< as::date << now << " and tommorrow is " << now+24*3600 << endl; cout << "Current time is "<< as::time << now << endl; cout << "The current weekday is "<< as::ftime("%A") << now << endl; } g++ main.cpp -o run.main -lboost_locale and the output is: Today is 1.30439e+09 and tommorrow is 1.30448e+09 Current time is 1.30439e+09 The current weekday is 1.30439e+09 I tried with booster.locale that comes with cppcms, and I downloaded from svn and compiled the very latest boost.locale. I get the same result with both. I'm sure I am missing something simple. Probably, I need to set the locale first, but it's not clear to me how to do it. Also, a grip I have with most/all boost libraries, is that one never knows what option to pass to the linker: http://stackoverflow.com/questions/3467153/is-there-an-intelligent-way-to-know- the-name-of-the-library-to-link-to-at-compile Is this platform/compiler dependent? Can't this kind of thing be documented? Anyway, in this case, I found it was -lboost_locale. For boost.locale, more, fully working, compilable examples would help. - Most boost libraries documentation are written for very experienced C++ developers. From a newbie perspective, I find most documentation very obtuse. I checked boost.date_time for a long while, and still couldn't understand enough to actually make use of it. I still have much to learn before I can understand a lot of the boost documentation. - Generally speaking, within the context of a cppcms application, what is the best/recommended way to format dates, times and such? Basically, I have a unix timestamp, and I want to output it in human readable form, both in the UTC and locale timezone. Thanks, Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . ------------------------------------------------------- -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |