Discussion:
[Cppcms-users] Read-only context
Nazım Can Bedir
2017-01-17 16:42:23 UTC
Permalink
Hi Artyom,

First of all, thank you (and all other contributors) for developing such
good C++ web development library.

Now, in one of application I am developing; I need to pass HTTP context
in read-only manner. What I am trying to achieve is; writing predicate
functions taking const reference to context, and checking some
conditions related with the request. With current version of
http::context and application classes, this is not possible out-of-box.

That's why I attached a patch to add "const-correct" member functions;
which works well for my case. If it's possible, could you apply patch to
trunk? I prefer to not fork a project just for small changes.

Regards,
Nazim.
Artyom Beilis
2017-01-17 21:00:36 UTC
Permalink
Hello Nazim,

Ohhh, I wish you were talking about it before you started to do all
the hard work.

The const correctness was discussed several times in the list and I
explained why central classes do not provide const interface.

Many of the interfaces that are used relay on lazy
initialization/evaluation - as you noticed for example for

- cache() object - it is created on demand.
- map<string,string> http::request::getenv() does similar stuff - it
converts the efficient internal representation to external only on
demand.

Even if some of the interfaces can be converted to "const" ones I
still prefer to keep an option to use lazy initialization if I will
need
in future to without breaking API or const correctness and without
creating unexpected side effects.

It is very critical as CppCMS is strongly performance oriented and I
need to keep the option for lazy evaluation performance improvements
under the hood.

So thank you for the effort but I can't accept this patch as it is today.

Thanks Again,
Artyom Beilis


On Tue, Jan 17, 2017 at 6:42 PM, Nazım Can Bedir
Post by Nazım Can Bedir
Hi Artyom,
First of all, thank you (and all other contributors) for developing such
good C++ web development library.
Now, in one of application I am developing; I need to pass HTTP context in
read-only manner. What I am trying to achieve is; writing predicate
functions taking const reference to context, and checking some conditions
related with the request. With current version of http::context and
application classes, this is not possible out-of-box.
That's why I attached a patch to add "const-correct" member functions; which
works well for my case. If it's possible, could you apply patch to trunk? I
prefer to not fork a project just for small changes.
Regards,
Nazim.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
Joerg Sonnenberger
2017-01-17 21:17:27 UTC
Permalink
Post by Artyom Beilis
Many of the interfaces that are used relay on lazy
initialization/evaluation - as you noticed for example for
- cache() object - it is created on demand.
- map<string,string> http::request::getenv() does similar stuff - it
converts the efficient internal representation to external only on
demand.
That doesn't necessarily stop const accessors from working, it just
means that the internal fields have to be marked explicitly as mutable.

Joerg
Nazım Can Bedir
2017-01-17 23:25:47 UTC
Permalink
Joerg,

I am not expert, but while preparing patch; especially in 'session()'
and 'cache()' functions; it's not so easy to mark some fields as mutable
as we could do it in daily C++. Since CppCMS is trying to keep ABI
stability; it uses pimpl idiom nearly everywhere. And it needs good
amount of work for refactoring to support mutable in proper way.

(I guess, sort of)

Regards,
Nazim.
Post by Joerg Sonnenberger
Post by Artyom Beilis
Many of the interfaces that are used relay on lazy
initialization/evaluation - as you noticed for example for
- cache() object - it is created on demand.
- map<string,string> http::request::getenv() does similar stuff - it
converts the efficient internal representation to external only on
demand.
That doesn't necessarily stop const accessors from working, it just
means that the internal fields have to be marked explicitly as mutable.
Joerg
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
Joerg Sonnenberger
2017-01-18 17:51:04 UTC
Permalink
Post by Nazım Can Bedir
Joerg,
I am not expert, but while preparing patch; especially in 'session()'
and 'cache()' functions; it's not so easy to mark some fields as mutable
as we could do it in daily C++. Since CppCMS is trying to keep ABI
stability; it uses pimpl idiom nearly everywhere. And it needs good
amount of work for refactoring to support mutable in proper way.
On the contrary, that actually tends to make it easier.

Joerg

Nazım Can Bedir
2017-01-17 23:26:13 UTC
Permalink
Hello Artyom,

No problem at all.

Thanks,
Nazim.
Post by Artyom Beilis
Hello Nazim,
Ohhh, I wish you were talking about it before you started to do all
the hard work.
The const correctness was discussed several times in the list and I
explained why central classes do not provide const interface.
Many of the interfaces that are used relay on lazy
initialization/evaluation - as you noticed for example for
- cache() object - it is created on demand.
- map<string,string> http::request::getenv() does similar stuff - it
converts the efficient internal representation to external only on
demand.
Even if some of the interfaces can be converted to "const" ones I
still prefer to keep an option to use lazy initialization if I will
need
in future to without breaking API or const correctness and without
creating unexpected side effects.
It is very critical as CppCMS is strongly performance oriented and I
need to keep the option for lazy evaluation performance improvements
under the hood.
So thank you for the effort but I can't accept this patch as it is today.
Thanks Again,
Artyom Beilis
On Tue, Jan 17, 2017 at 6:42 PM, Nazım Can Bedir
Post by Nazım Can Bedir
Hi Artyom,
First of all, thank you (and all other contributors) for developing such
good C++ web development library.
Now, in one of application I am developing; I need to pass HTTP context in
read-only manner. What I am trying to achieve is; writing predicate
functions taking const reference to context, and checking some conditions
related with the request. With current version of http::context and
application classes, this is not possible out-of-box.
That's why I attached a patch to add "const-correct" member functions; which
works well for my case. If it's possible, could you apply patch to trunk? I
prefer to not fork a project just for small changes.
Regards,
Nazim.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
Loading...