Boost logo

Boost Users :

Subject: Re: [Boost-users] boost.extensions and boost.reflection.
From: Germán Diago (germandiago_at_[hidden])
Date: 2008-09-13 04:08:14


> A factory of non-pointer types? I'm confused - the example you describe
> appears to create the objects on the heap, thus pointers are involved
> somewhere. As soon as you right myns::myclass&, you are basically using a
> pointer.
> Could you try and describe your use cases a little bit more clearly, and
> also take a look at the Extension documentation
> at http://boost-extension.redshoelace.com/docs/boost/extension/index.html?
> Let me apologize for the still incomplete reflection documentation.
> Jeremy Pack
> __________

There is a way to use value-based types (with non-pointers) even from
shared libraries.
I think you didn't read
the paper I linked.
It's ok to have factories with types which are pointers to base
classes. But I'd like
to be able to use a factories to register types with no pointer in its
creation so that I can use
non-pointer factories with my own non-intrusive interfaces. I know it
sounds weird.
If you want to understand why I want this, take a look at the paper I
linked and these ones:

run-time concepts:

http://www.emarcus.org/papers/oops2008-marcus.pdf

mixing objects and generic programming:

http://www.emarcus.org/papers/MPOOL2007-marcus.pdf

Pseudo-code.
With this technique your examples could become (but they don't need to):

//This is the object that takes the role of interface
class any_animal {
  void get_name(); ...
};

factory <any_animal, int> ... //This factory should be of non-pointers

//Note: no inheritance.
class dog
{
  void get_name();
};

class cat
{
  void get_name();
}

Now I could use it like this:

//Dog is contained inside this object
any_animal a = create("dog");
any_animal b = create("cat");

//Calls dog::get_name
a.get_name();

//Calls cat::get_name
b.get_name();

This way I can adapt external code to be used with my library (no need
an animal to inherit from anywhere, just implement the functions).
 I want to use boost.extensions
and boost.reflection, but I need a way to create value-based factories
so that I can enable non-intrusive
interface classes like the one above. It's the only thing I need. With
the example above the castings go
away. The class any_animal holds the real objects (dog, cat...) and is
used as an interface with value-based types.
And you can use naturally these types with stl algorithms. It's
similar to what boost.function does with any kind of callable type.

_____________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net