Re: [Cppcms-users] Getting to feature freeze for CppCMS 1.0.0
Brought to you by:
artyom-beilis
|
From: Daniel V. <chi...@gm...> - 2011-09-05 18:06:54
|
Hello.
Apologies for my english.
Features required:
json RPC
1) The RPC method could receive parameters that are json values without
copy operation cost. For example:
using namespace cppcms;
void my_json_rpc_method( json::object& o, json::array& a,
std::string& s);
2) And could response json values without copy operation cost. That is
cppcms::rpc::json_rpc_server could have the following methods:
void return_result( json::object const & o);
void return_result( json::array const & a);
void return_result( std::string const & s);
Json Values
3) Add the possibility to a json::value object to point to an exists
json::object, json::array or json::string. That is required for access
the facilities that have json::value methods without copy operation.
For example, currently, if I want to print a json::array I have to do:
json::array a;
//...
json::value v = a;
std::cout << v;
This leads to an unnecessarily copy operation. I suggest adding the
following methods to json::value class
void wrap(json::object& o);
void wrap(json::array& a);
void wrap(string& s);
void wrap(json::object const& o) const;
void wrap(json::array const& a) const;
void wrap(string const& s) const;
Cppdb
4 ) Boost fusion integration. Posibility to fetch fusion sequences from
cppdb::result, for example:
typedef boost::fusion::vector< int, string, string> row_t;
cppdb::result r = sql << "SELECT id, user, location FROM
my_table";
row_t row;
fetch_sequence(r, row);
My implementation:
#include <cppdb/frontend.h>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/include/is_sequence.hpp>
template <typename T>
inline bool fetch(cppdb::result& r, T& x)
{
return r.fetch(x);
}
class fetch_functor
{
public:
fetch_functor(cppdb::result& r);
template <typename T>
void operator()(T& x) const {
fetch(result_, x);
}
private:
cppdb::result& result_;
};
template <typename T>
void fetch_sequence(cppdb::result& r, T& t )
{
BOOST_MPL_ASSERT(( boost::fusion::traits::is_sequence<T> ));
boost::fusion::for_each(t, fetch_functor(r) );
}http://
5) Add the posibility to the library client to extend fetch and bind to
custom types. For example add the following interface for fetch custom
types:
class CPPDB_API result {
public:
//...
template <typename T>
bool fetch(T& t) {
return fetch(*this, t);
}
//...
};
Library user code for boost::optional fetch:
namespace cppdb {
template<typename T>
bool fetch( result& r, boost::optional<T>& opt)
{
opt = T(); // WARNING: only for types with constructor
without arguments.
if ( ! r.fetch(opt.get()) ) {
opt =
boost::none;
}
return true; // Always true
}
}
And finally the same kind of interface for bind.
Thanks you.
|