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 21:06:10
|
On Mon, 2011-09-05 at 12:38 -0700, Artyom Beilis wrote:
> You already can bind any callback of type
>
> typedef booster::function<void(json::array const &)> method_type
>
> It allows you to do 0 copy
Great.
>
> > 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);
>
> Why not to create json::value that can be json object in first
> place?
Yes, that's what I do:
json::value result = json::array();
json::array& result_arr = result.array();
result_arr.push_back("123");
return_result(result);
For me it's more clear the following theoretical code:
json::array& result;
result.push_back("123");
return_result(result);
But it's not big deal.
>
>
> > 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.
>
> This would require entirely different and not always
> clear semantics.
>
> Currently json::* is value type and I'm not sure that
> adding non-value semantics would not make it dangerous.
>
> What happens on copy? Shallow or deep?
>
Yes, it's not clear. But for me, copy is a copy.
> On the other hand you can do
>
> json::value my_huge_value;
> foo["bar"]["bee"].swap(my_huge_value)
>
Yes, I use swap.
But if the values are const, we can't use swap.
> Which provides move semantics and reduce the
> need of copy.
>
> > 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;
>
> Why not:
>
>
> json::value v = json::array();
> v.array().swap(a);
> std::cout << v;
>
Yes, my example is not good. What about this example?
void print(json::array const& a) {
json::value v = a;
std::cout << v;
}
My ugly solution is:
void print(json::array const& a)
{
json::value v = json::array();
json::array* array_ptr = const_cast<json::array*>(&a);
v.array().swap(*array_ptr);
std::cout << v;
v.array().swap(*array_ptr);
}
>
> > This leads to an unnecessarily copy operation. I suggest adding the
> > following methods to json::value class
>
> You can use move semantics with swap member functions.
>
> The semantics change you suggest is too radical.
>
> Same can be done for example with reimplementing
> json using tree of shared_ptr's but it would lead to different
> semantics.
>
> I don't think I want to touch this.
Ok.
Thank you for you great work.
Good bye.
|