Boost logo

Boost :

Subject: Re: [boost] Interest in runtime concepts library.
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2011-02-06 20:39:20


On Feb 6, 2011, at 12:15 PM, Germán Diago wrote:

> Hi all. I'm implementing a framework to use runtime concepts for a
> project of myself.
> I would like to know the interest in that library. For now, I have a
> proof of concept working.
>
> The goal of the library, for now, is to be able to use objects of
> differente types without
> having any inheritance requirements and being nonintrusive.

It appears that your example is "intrusive" by requiring a typedef ModelOfType in the classes implementing your concept in order to perform the proper 'cast' whereas my implementation is 100% non-intrusive.

> The code
> has my own standards
> for naming conventions, but that can be changed later when I have
> something ready for
> consumption.

It appears that you and I are working on the same problem from two different angles. I apologize for not reading your post before posting my own regarding [boost][interfaces].

It appears that your implementation requires more boilerplate code and provides no ability to define dynamic interfaces such as exposing any object that defines a "concept'" as a json-rpc server or create a json-rpc client based upon a "concept" definition.

So my question to you, Germán Diago, in what ways is my solution undesirable for your application?

To implement your example using "boost idl" you would do something like:

namespace idl_definition {
        struct DeviceC
        {
                 std::size_t getCapacityInMB() const;
        };
        struct IPlugableDeviceC : DeviceC
        {
                void onOpen();
                void onRemove();
        };
}

BOOST_IDL_INTERFACE( DeviceC, (), (getCapacityInMB) )
BOOST_IDL_INTERFACE( IPlugableDeviceC, (IPlugableDeviceC),
         (onOpen)
         (onRemove) )

int main( int argc, char** argv )
{
        IpodDevice ipod;
        LegacyDevice legacy_device;
        std::vector<DeviceC> devices;
        devices.push_back( move(ipod) );
        devices.push_back( move(legacy_device) );
        
        IPlugableDeviceC plugable_device = ??? I guess I need a way to 'down cast'
        devices[0].getCapacityInMB();
}

After attempting to implement your example using my API I realized that my solution currently does not provide a down-casting option while maintaining your syntax. However down casting is possible like so:

int main( int argc, char** argv )
{
        IpodDevice ipod;
        LegacyDevice legacy_device;
        std::vector<DeviceC*> devices;
        devices.push_back( new IPluggableDeviceC(move(ipod)) );
        devices.push_back( new IPluggableDeviceC(move(legacy_device)) );

        devices[0].getCapacityInMB();
        IPlugableDeviceC* plugable_device = dynamic_cast<IPluggalbeDeviceC*>(devices[1]);
        pluggable_device->onOpen();
}

Additionally, my implementation supports public members as part of the 'Concept' which, as far as I can tell, is impossible with your design.

Dan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk