4 #include <rikitiki/rikitiki>
5 #include <rikitiki/mongoose/mongoose>
6 #include <rikitiki/rest/rest>
7 #include <rikitiki/jsoncpp/jsoncpp>
8 #include <rikitiki/configuration/configuration>
11 #include <mxcomp/tuples.h>
13 using namespace rikitiki;
14 using namespace rikitiki::mongoose;
17 inline static std::string prettyName(
const std::type_info& ti){
21 char* res = abi::__cxa_demangle (ti.name(),
25 return std::string(res);
35 Book(
const std::string& _name,
const std::string& _author,
const std::string& _isbn) :
36 name(_name), author(_author), isbn(_isbn) {}
52 auto operator()(
const T& t)
const ->
typename std::enable_if<std::is_base_of<Field, T>::value, std::string>::type
53 {
return prettyName(
typeid(T)); }
56 auto operator()(
const T& t)
const ->
typename std::enable_if<std::is_base_of<Field, T>::value ==
false, std::string>::type
57 {
return prettyName(
typeid(T)) +
"!!!"; }
67 std::vector<Book> books;
73 books.push_back(newBook);
74 ctx << books.size() - 1;
83 if(id < 0 || id >= (
int)books.size())
84 ctx << HttpStatus::Bad_Request;
100 inline void operator()(
const Field_<Book, S>& field){
101 ctx << field.get(book);
105 void operator()(
ConnContext& ctx,
int id,
const std::string& prop){
106 if(id < 0 || id >= (
int)books.size())
107 ctx << HttpStatus::Bad_Request;
109 auto mt = mxcomp::tuples::make_mapped([](
const Member& m) {
return m.name; },
110 MetaClass_<Book>::fields());
111 mt.findAndRun(prop, PrintFunctor(ctx, books[
id]));
115 void Register(
Server& server){
116 typedef RestAdvModule T;
117 rikitiki::rest::Register(server,
"/book-adv",
this);