From db8227a34ad616db95d319430d270c6372485e86 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Fri, 10 Nov 2017 18:04:53 +0900 Subject: [PATCH] cxx: Add alternative form to instantiate object This still uses the instantiate object but provides a more convenient syntax for objects declared before their creation (eg. a global win). Note: I wonder if we shouldn't rename instantiate to add. It would be closer to EFL API's while being much much easier to type. --- src/bindings/cxx/eo_cxx/eo_concrete.hh | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/bindings/cxx/eo_cxx/eo_concrete.hh b/src/bindings/cxx/eo_cxx/eo_concrete.hh index 9227445de9..adc33985b7 100644 --- a/src/bindings/cxx/eo_cxx/eo_concrete.hh +++ b/src/bindings/cxx/eo_cxx/eo_concrete.hh @@ -31,7 +31,32 @@ namespace efl { namespace eo { /// @addtogroup Efl_Cxx_API /// @{ -struct instantiate_t {} const instantiate = {}; +struct instantiate_t { + /// @brief A helper to create objects with a different syntax + /// + /// @param obj The object to instantiate + /// @return obj The newly created object + /// + /// Consider an object declared by its type T on the stack, like T obj. + /// Initially it will be empty (_eo_ptr() is nullptr). It can be created + /// in two ways: + /// obj = T(instantiate, obj); + /// or: + /// instantiate(obj); + /// + /// Note that if @c obj is already a valid object, it will be unreferenced. + template T& operator()(T& obj) const { + obj = T(*this); + return obj; + } +}; + +/// @brief The handle to use to create real EFL objects +/// +/// Use @c instantiate as first argument of any object constructor in order +/// to trigger a real EFL object creation. The following syntax is preferred: +/// T obj(instantiate, ...); +instantiate_t const instantiate = {}; /// @brief Creates concrete versions for Eo wrappers. ///