On Fri, Jun 14, 2013 at 12:52 PM, Carsten Haitzler <[email protected]> wrote:
>

Hello Carsten,

> On Fri, 14 Jun 2013 11:02:36 -0300 Felipe Magno de Almeida
> <[email protected]> said:

[snip]

> > I'm using metaprogramming in C++ for binding to Eo, but it is proving very
> > difficult for lack of void* data parameters for class functions, e.g.,
> > class_constructor,
> > class_destructor, constructor. Also, see below.
>
> more details?

[snip]

The syntax isn't yet fixed of course and it is still very
experimental. But, what
I have almost working right now is something like this:

PS: 27 and 28 are the numbers for the op call, I haven't yet abstracted calling,
so I have to do this manually right now, since I'm not using the same syntax
as C.

struct simple
{
  void get(int* i) const
  {
    std::cout << "get " << a << std::endl;
    *i = a;
  }
  void set(int i)
  {
    std::cout << "Setting " << i << std::endl;
    a = i;
  }
};

  eflcxx::eo_class_const_view simple_class
    = eflcxx::eo_register_class< ::simple>
    ("Simple"
     , boost::fusion::make_vector(&simple::set, &simple::get)
     , EO_BASE_CLASS, INTERFACE_CLASS, MIXIN_CLASS);

  Eo *obj = eo_add(simple_class.raw(), NULL);

  // eo_do(obj, simple_a_set(4));
  eo_do(obj, 27, 4);

  int a = 0, a2 = 0, a3 = 0;

  // eo_do(obj, simple_a_get(&a));
  eo_do(obj, 28, &a);

  printf("Got %d %d %d\n", a, a2, a3);

<output>
Setting 4
get 4
Got 4 0 0
</output>

I'm not yet handling overrides et al, but they don't seem very hard to extend.
The problem I'm facing though is, when I register the class (eo_class_new),
I have all pointers-to-members (and their signatures). So, I create a vtable
(indexed by number -> pointer-to-member) and then I have the functions
that will interface with Eo be instantiated by this index, function signature
and class type (struct simple in the example above). It has this signature:

template <int I, int N, typename T, typename F>
EAPI void eo_member_function(Eo* obj, void* class_data, va_list* list);

I = index in the vtable, N is the size of the vtable (so I can avoid dynamic
allocating the vtable), T is the class and F is the function-member signature,
e.g., void(T::*)(int*) const.

The problem is, I can't pass the vtable directly to the constructor, or save
it anywhere in the Eo_Class. So I needed to improvise and use local
static to allocate them like this:

template <int N, typename T>
vtable<N, T>* get_vtable()
{
  static vtable<N, T> v;
  return &v;
}

Which works, but has a few limitations, for example thread-safety on
pre-C+11, also I can't use the same T and N, e.g. struct simple, for different
Eo classes because the local static would be the same, and consequently the
same vtable.

Another problem is that I can't fill this vtable in the class_constructor,
because I couldn't find a way to pass any information to class_constructor
because it only receives a just constructed Eo_Class*.

If, on the other hand, oe_class_new had a void*data parameter, I could do
more in the class_constructor, and, to make it even better, Eo_Class_Description
had a size parameter for additional data in Eo_Class that I could modify freely
(think of it as a static variable members, shared for all Eo* instances from the
same Eo_Class*), then I could use this space for the vtable and avoid the
local static workaround completely, and still avoid more dynamic allocations.


> ------------- Codito, ergo sum - "I code, therefore I am" --------------
> The Rasterman (Carsten Haitzler)    [email protected]

[]'s,
--
Felipe Magno de Almeida

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to