Boost logo

Boost :

Subject: [boost] [Boost-interest] C++ library for runtime-concepts (type-erasure)
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2011-02-13 22:26:09


I have posted Boost.IDL to github complete with documentation here: http://bytemaster.github.com/boost_idl/index.html

https://github.com/bytemaster/boost_idl

The library is header only. It is included as part of the Boost.Defrag "incubating" projects.

The documentation includes several examples of how it is used to provide a simple 'command line interface' to a struct as well as a fully 'generic' RPC example that will expose any interface over the network using Boost.Serialization. Full RPC implementation 245 SLOC. The RPC example is very 'bare bones' because I think that a Boost.RPC library should be a separate project.

I welcome any feedback.

The code is still very 'new' and has not been tested on any platforms other than OS X, but it should all be very portable as I write Mac/Linux/Windows portable software every day.
Server:

    struct Echo
    {
        std::string echo(const std::string &s) { return s; }
    };
    BOOST_IDL_INTERFACE( Echo, BOOST_IDL_BASE, (echo) )
        
    int main()
    {
        boost::idl::rpc_server<Echo> server( Echo() );
        server.listen( 50001 );
        return 0;
    }
Client:

    struct Echo
    {
        std::string echo(const std::string &s); // implementation not needed
    };
    BOOST_IDL_INTERFACE( Echo, BOOST_IDL_BASE, (echo) )
        
    int main()
    {
        boost::idl::rpc_client<Echo> client;
        client.connect_to( "localhost", 50001 );
        std::string s = client.echo( "what's up" );
        return 0;
    }

Type Erasure Applied to rpc_client:
    // erase the details of the rpc_client, by storing
    // it in a generic Echo interface.
    boost::idl::any<Echo> any_echo = client;

Command Line Interface:
    template<typename InterfaceType,typename InterfaceDelegate>
    void start_cli( boost::idl::any<InterfaceType,InterfaceDelegate>& a )
    {
        cli m_cli;
        m_cli.start_visit(a);

        std::string line;
        std::string cmd;
        std::string args;

        while( true )
        {
            std::cerr << "Enter Method: ";
            std::getline( std::cin, line );
            cmd = line.substr( 0, line.find('(') );
            args = line.substr( cmd.size(), line.size() );
            std::cerr << m_cli[cmd](args) << std::endl;
        }
    }


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