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.
This commit is contained in:
Jean-Philippe Andre 2017-11-10 18:04:53 +09:00
parent 66eb8ddfeb
commit db8227a34a
1 changed files with 26 additions and 1 deletions

View File

@ -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<typename T> 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 <em>Eo</em> wrappers.
///