#include <cppcms/serialization.h>
#include <cppcms/application.h>
#include <cppcms/cache_interface.h>
#include <cppcms/session_interface.h>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <sstream>
#include <iostream>
struct person {
std::string name;
std::string family;
template<typename Archive>
void serialize(Archive &a,unsigned )
{
a & name & family;
}
};
template<typename T>
void load_from_boost(std::string const &src,T &obj)
{
std::stringbuf ss(src);
{
boost::archive::binary_iarchive oa(ss);
oa >> obj;
}
}
template<typename T>
void save_with_boost(T const &obj,std::string &tgt)
{
std::stringbuf ss;
{
boost::archive::binary_oarchive oa(ss);
oa << obj;
}
tgt=ss.str();
}
void init_person(person &john)
{
john.name = "John";
john.family = "Jonson";
}
template<>
struct serialization_traits<person> {
static void save(person const &obj,std::string &tgt)
{
save_with_boost(obj,tgt);
}
static void load(std::string const &src,person &obj)
{
load_from_boost(src,obj);
}
};
}
public:
{
}
void main(std::string )
{
{
person john;
session().fetch_data("me",john);
}
{
person john;
if(!cache().fetch_data("john",john)) {
init_person(john);
cache().store_data("john",john);
}
}
}
};
int main()
{
{
{
person john;
init_person(john);
}
{
person john;
std::cout << john.name << std::endl;
}
}
return 0;
}