forked from enlightenment/efl
allow C++ user create new classes inheriting from Eolian generated Classes
This commit is contained in:
parent
0685885c2a
commit
2b12114777
|
@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in
|
|||
CLEANFILES =
|
||||
BUILT_SOURCES =
|
||||
|
||||
EOLIAN_FLAGS = \
|
||||
EOLIAN_FLAGS = -I$(srcdir)\
|
||||
-I$(srcdir)/lib/eo \
|
||||
-I$(srcdir)/lib/evas/canvas \
|
||||
-I$(srcdir)/lib/edje \
|
||||
|
|
|
@ -72,6 +72,8 @@ tests/eolian_cxx/d.c \
|
|||
tests/eolian_cxx/eolian_cxx_test_callback.cc \
|
||||
tests/eolian_cxx/eolian_cxx_test_address_of.cc \
|
||||
tests/eolian_cxx/eolian_cxx_test_wrapper.cc \
|
||||
tests/eolian_cxx/simple.c \
|
||||
tests/eolian_cxx/eolian_cxx_test_inheritance.cc \
|
||||
tests/eolian_cxx/eolian_cxx_test_generate.cc
|
||||
|
||||
tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh
|
||||
|
@ -83,7 +85,15 @@ tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-b.$(OBJEXT): tests/eolian_cxx
|
|||
tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-c.$(OBJEXT): tests/eolian_cxx/c.eo.c tests/eolian_cxx/c.eo.h
|
||||
tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-d.$(OBJEXT): tests/eolian_cxx/d.eo.c tests/eolian_cxx/d.eo.h
|
||||
|
||||
CLEANFILES += tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.c tests/eolian_cxx/callback.eo.h \
|
||||
tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_inheritance.$(OBJEXT): tests/eolian_cxx/simple.eo.hh
|
||||
|
||||
tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-simple.$(OBJEXT): tests/eolian_cxx/simple.eo.c tests/eolian_cxx/simple.eo.h
|
||||
|
||||
CLEANFILES += tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.c \
|
||||
tests/eolian_cxx/callback.eo.h \
|
||||
tests/eolian_cxx/simple.eo.c \
|
||||
tests/eolian_cxx/simple.eo.h \
|
||||
tests/eolian_cxx/simple.eo.hh \
|
||||
tests/eolian_cxx/a.eo.hh tests/eolian_cxx/a.eo.c tests/eolian_cxx/a.eo.h \
|
||||
tests/eolian_cxx/b.eo.hh tests/eolian_cxx/b.eo.c tests/eolian_cxx/b.eo.h \
|
||||
tests/eolian_cxx/c.eo.hh tests/eolian_cxx/c.eo.c tests/eolian_cxx/c.eo.h \
|
||||
|
@ -111,6 +121,7 @@ tests_eolian_cxx_eolian_cxx_suite_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@
|
|||
endif
|
||||
|
||||
EXTRA_DIST += tests/eolian_cxx/callback.eo \
|
||||
tests/eolian_cxx/simple.eo \
|
||||
tests/eolian_cxx/a.eo \
|
||||
tests/eolian_cxx/b.eo \
|
||||
tests/eolian_cxx/c.eo \
|
||||
|
|
|
@ -86,6 +86,9 @@ Eo_Class const* do_eo_class_new(Eo_Class_Description& class_desc)
|
|||
|
||||
template <typename T> struct operation_description_class_size;
|
||||
|
||||
template<>
|
||||
struct operation_description_class_size<efl::eo::base> { static const int value = 0; };
|
||||
|
||||
/// @internal
|
||||
///
|
||||
/// @brief Provides the operator to convert @p T to @p D.
|
||||
|
@ -130,6 +133,9 @@ namespace detail {
|
|||
///
|
||||
template <typename T> struct operations;
|
||||
|
||||
template <>
|
||||
struct operations<efl::eo::base> { template <typename T> struct type {}; };
|
||||
|
||||
/// @internal
|
||||
///
|
||||
/// @brief Provides the operations of an extension as well as its
|
||||
|
@ -153,6 +159,17 @@ struct Inherit_Private_Data
|
|||
void* this_;
|
||||
};
|
||||
|
||||
} } } // namespace efl { namespace eo { namespace detail {
|
||||
|
||||
namespace efl { namespace eo { namespace detail {
|
||||
template <typename T>
|
||||
int initialize_operation_description(efl::eo::detail::tag<efl::eo::base>
|
||||
, Eo_Op_Description* ops)
|
||||
{
|
||||
(void)ops;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
} } } // namespace efl { namespace eo { namespace detail {
|
||||
|
|
|
@ -30,7 +30,7 @@ struct ColourableCircle
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
struct ColourableFoo
|
||||
: efl::eo::inherit<ColourableFoo,
|
||||
::colourable,
|
||||
|
@ -40,6 +40,24 @@ struct ColourableFoo
|
|||
: inherit_base(efl::eo::args<::colourable>(size)
|
||||
, efl::eo::args<::colourablesquare>(rgb))
|
||||
{}
|
||||
};*/
|
||||
|
||||
struct ColourableBar
|
||||
: efl::eo::inherit<ColourableBar, ::colourablesquare>
|
||||
{
|
||||
ColourableBar()
|
||||
: inherit_base(efl::eo::args<::colourablesquare>(0))
|
||||
{}
|
||||
|
||||
int colour_get()
|
||||
{
|
||||
int rgb = 0;
|
||||
eo_do_super(_eo_ptr(), _eo_class(), rgb = ::colourable_colour_get());
|
||||
std::cout << "ColourableBar::colour_get(" << this << ") ==> "
|
||||
<< std::hex << rgb << std::endl;
|
||||
return rgb;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int
|
||||
|
@ -55,6 +73,10 @@ main()
|
|||
int r, g, b;
|
||||
obj2.composite_colour_get(&r, &g, &b);
|
||||
|
||||
|
||||
ColourableBar obj3;
|
||||
obj3.composite_colour_get(&r, &g, &b);
|
||||
|
||||
assert(r == 0xc0);
|
||||
assert(g == 0xff);
|
||||
assert(b == 0xee);
|
||||
|
|
|
@ -65,6 +65,12 @@ struct inheritance_operations_description
|
|||
inline std::ostream&
|
||||
operator<<(std::ostream& out, inheritance_operations_description const& x)
|
||||
{
|
||||
extensions_container_type::const_iterator it, first, last;
|
||||
std::string s;
|
||||
|
||||
first = x._cls.extensions.begin();
|
||||
last = x._cls.extensions.end();
|
||||
|
||||
out << "template <typename T>"
|
||||
<< endl << "int initialize_operation_description(::efl::eo::detail::tag<"
|
||||
<< full_name(x._cls) << ">" << endl
|
||||
|
@ -77,6 +83,24 @@ operator<<(std::ostream& out, inheritance_operations_description const& x)
|
|||
{
|
||||
out << inheritance_operation(x._cls, i);
|
||||
}
|
||||
|
||||
out << tab(1)
|
||||
<< "initialize_operation_description<T>(efl::eo::detail::tag<"
|
||||
<< x._cls.parent
|
||||
<< ">(), &ops["
|
||||
<< x._cls.functions.size() << "]);" << endl;
|
||||
|
||||
s += " + operation_description_class_size<" + x._cls.parent + ">::value";
|
||||
|
||||
for (it = first; it != last; ++it)
|
||||
{
|
||||
out << tab(1)
|
||||
<< "initialize_operation_description<T>(efl::eo::detail::tag<"
|
||||
<< *it << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl;
|
||||
|
||||
s += " + operation_description_class_size< " + *it + ">::value";
|
||||
}
|
||||
|
||||
out << tab(1) << "return 0;" << endl
|
||||
<< "}" << endl;
|
||||
|
||||
|
@ -144,18 +168,57 @@ struct inheritance_base_operations_size
|
|||
inline std::ostream&
|
||||
operator<<(std::ostream& out, inheritance_base_operations_size const& x)
|
||||
{
|
||||
extensions_container_type::const_iterator it, first = x._cls.extensions.begin();
|
||||
extensions_container_type::const_iterator last = x._cls.extensions.end();
|
||||
first = x._cls.extensions.begin();
|
||||
|
||||
out << "template<>"
|
||||
<< endl << "struct operation_description_class_size< "
|
||||
<< full_name(x._cls) << " >" << endl
|
||||
<< "{" << endl
|
||||
<< tab(1) << "static const int value = "
|
||||
<< x._cls.functions.size()
|
||||
<< ";" << endl
|
||||
<< " + operation_description_class_size<" << class_name(x._cls.parent) << ">::value";
|
||||
|
||||
for (it = first; it != last; ++it)
|
||||
{
|
||||
out << " + operation_description_class_size< " << *it << " >::value";
|
||||
}
|
||||
|
||||
out << ";" << endl
|
||||
<< "};" << endl
|
||||
<< endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
struct inheritance_base_operations_extensions
|
||||
{
|
||||
eo_class const& _cls;
|
||||
inheritance_base_operations_extensions(eo_class const& cls)
|
||||
: _cls(cls)
|
||||
{}
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, inheritance_base_operations_extensions const& x)
|
||||
{
|
||||
eo_class const& cls = x._cls;
|
||||
extensions_container_type::const_iterator it, first = cls.extensions.begin();
|
||||
extensions_container_type::const_iterator last = cls.extensions.end();
|
||||
|
||||
out << endl << tab(3) << ": operations< " << class_name(cls.parent) << " >::template type<T>";
|
||||
for (it = first; it != last; ++it)
|
||||
{
|
||||
out << "," << endl << tab(3)
|
||||
<< "operations< " << *it
|
||||
<< " >::template type<T>";
|
||||
}
|
||||
|
||||
return out << endl;
|
||||
}
|
||||
|
||||
struct inheritance_base_operations_function
|
||||
{
|
||||
eo_class const& _cls;
|
||||
|
@ -212,7 +275,7 @@ operator<<(std::ostream& out, inheritance_base_operations const& x)
|
|||
<< full_name(x._cls) << " >" << endl
|
||||
<< "{" << endl
|
||||
<< tab(1) << "template <typename T>" << endl
|
||||
<< tab(1) << "struct type" << endl
|
||||
<< tab(1) << "struct type" << inheritance_base_operations_extensions(x._cls)
|
||||
<< tab(1) << "{" << endl;
|
||||
functions_container_type::const_iterator it,
|
||||
first = x._cls.functions.begin(),
|
||||
|
|
|
@ -8,6 +8,7 @@ void eolian_cxx_test_wrapper(TCase* tc);
|
|||
void eolian_cxx_test_generate(TCase* tc);
|
||||
void eolian_cxx_test_callback(TCase* tc);
|
||||
void eolian_cxx_test_address_of(TCase* tc);
|
||||
void eolian_cxx_test_inheritance(TCase* tc);
|
||||
|
||||
typedef struct _Eolian_Cxx_Test_Case Eolian_Cxx_Test_Case;
|
||||
struct _Eolian_Cxx_Test_Case
|
||||
|
@ -22,6 +23,7 @@ static const Eolian_Cxx_Test_Case etc[] = {
|
|||
{ "Eolian-Cxx Generation", eolian_cxx_test_generate },
|
||||
{ "Eolian-Cxx Callback", eolian_cxx_test_callback },
|
||||
{ "Eolian-Cxx Address_of", eolian_cxx_test_address_of },
|
||||
{ "Eolian-Cxx Inheritance", eolian_cxx_test_inheritance },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
#include <simple.eo.hh>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
struct bar
|
||||
: efl::eo::inherit<bar, simple>
|
||||
{
|
||||
bar()
|
||||
: inherit_base()
|
||||
{}
|
||||
|
||||
bool simple_get()
|
||||
{
|
||||
printf("calling bar::%s\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void foo(simple is)
|
||||
{
|
||||
fail_if(is.simple_get());
|
||||
}
|
||||
|
||||
START_TEST(eolian_cxx_test_inheritance_simple)
|
||||
{
|
||||
efl::eo::eo_init i;
|
||||
bar b;
|
||||
foo(b);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eolian_cxx_test_inheritance(TCase* tc)
|
||||
{
|
||||
tcase_add_test(tc, eolian_cxx_test_inheritance_simple);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "simple.eo.h"
|
||||
|
||||
#define MY_CLASS SIMPLE_CLASS
|
||||
|
||||
static void _simple_eo_base_constructor(Eo *obj, void *pd EINA_UNUSED)
|
||||
{
|
||||
eo_do_super(obj, MY_CLASS, eo_constructor());
|
||||
}
|
||||
|
||||
static Eina_Bool _simple_simple_get(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
|
||||
{
|
||||
printf("calling %s\n", __FUNCTION__);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool _simple_name_get(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, const char** name)
|
||||
{
|
||||
static const char* _name= "simple_class";
|
||||
|
||||
printf("calling %s= simples class\n", __FUNCTION__);
|
||||
*name = _name;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
#include "simple.eo.c"
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
class Simple (Eo.Base)
|
||||
{
|
||||
legacy_prefix: null;
|
||||
data: null;
|
||||
methods {
|
||||
simple_get {
|
||||
return bool;
|
||||
}
|
||||
name_get {
|
||||
params {
|
||||
@out const(char)* name;
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
}
|
||||
implements {
|
||||
Eo.Base.constructor;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue