Re: [Cppcms-users] What is the best practice to serialize vector of struct?
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-10-24 13:38:33
|
You can provide a specialization for serialization traits like namespace cppcms { serialization_traits<std::vector<page> > { load(...) save(...) } }; It is generally designed to be used with custom (not-cppcms based) serialization methods. I woudn't say it is best practice, but it would allow you not to use the "wrapper" class. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: sergey lavrov <ccp...@gm...> >To: cpp...@li... >Sent: Wednesday, October 24, 2012 11:02 AM >Subject: [Cppcms-users] What is the best practice to serialize vector of struct? > > >Hi All! > > >What is the best practice to serialize vector of struct (std::vector<struct_name>)? > > >Now I use ugly method to wrap main struct into struct container with std:vector member: > > >struct page_container : public cppcms::serializable { >struct page : public cppcms::serializable { >std::string uuid; >time_t insert_date; >time_t update_date; >void serialize(cppcms::archive &a) { >a & uuid & insert_date & update_date; >} >}; >std::vector<page> pages; > > >void serialize(cppcms::archive &a) { >a & pages; >} >}; > > >page_container pages; >if(!cache().fetch_data("pages", pages)) { >get_pages(pages); >cache().store_data("pages", pages); >} > > >Thanks in advance! >------------------------------------------------------------------------------ >Everyone hates slow websites. So do we. >Make your web apps faster with AppDynamics >Download AppDynamics Lite for free today: >http://p.sf.net/sfu/appdyn_sfd2d_oct >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |