/***************************************************************************
 Copyright (c) 2009 S Roderick <xxxstephen AT theptrgroupxxx DOT comxxx>
                               (remove the x's above)
 ***************************************************************************/
#include "BoostToolkit.hpp"
#include <rtt/Types.hpp>
#include <rtt/TypeStream-io.hpp>
#include <rtt/TemplateTypeInfo.hpp>

namespace Examples
{
    using namespace RTT;
    using namespace RTT::detail;
    using namespace std;

    /***************************************************************************
        STREAM OPERATORS
	***************************************************************************/
    std::ostream& operator<<(std::ostream& os, const boost::posix_time::ptime& t)
	{
		os << boost::posix_time::to_simple_string(t);
		return os;
	}

    std::ostream& operator<<(std::ostream& os, const boost::posix_time::time_duration& d)
	{
		os << boost::posix_time::to_simple_string(d);
		return os;
	}

    std::istream& operator>>(std::istream& is, boost::posix_time::ptime& t)
	{
        is >> t;
		return is;
	}

    std::istream& operator>>(std::istream& is, boost::posix_time::time_duration& d)
	{
        is >> d;
		return is;
	}


    /***************************************************************************
        PLUGIN
	***************************************************************************/

    BoostPlugin BoostToolkit;

    std::string BoostPlugin::getName()
    {
        return "Boost";
    }

    bool BoostPlugin::loadTypes()
    {
        TypeInfoRepository::shared_ptr ti = TypeInfoRepository::Instance();

		/* each quoted name here (eg "boost_ptime") must _EXACTLY_ match that
		   in the associated TypeInfo::composeTypeImpl() and
		   TypeInfo::decomposeTypeImpl() functions (in this file), as well as
		   the name registered in the associated Corba plugin's
		   registerTransport() function (see corba/BoostCorbaToolkit.cpp)
		*/
        ti->addType( new BoostPtimeTypeInfo("boost_ptime") );
        ti->addType( new BoostTimeDurationTypeInfo("boost_timeduration") );

        return true;
    }

    bool BoostPlugin::loadConstructors()
    {
		// no constructors for these particular types

        return true;
    }

    bool BoostPlugin::loadOperators()
    {
		// no operators for these particular types

        return true;
    }


    /***************************************************************************
        TYPE DE/COMPOSERS
	***************************************************************************/

    bool BoostPtimeTypeInfo::decomposeTypeImpl(const boost::posix_time::ptime& source, PropertyBag& targetbag)
    {
        targetbag.setType("boost_ptime");
		assert(0);
        return true;
    }

    bool BoostPtimeTypeInfo::composeTypeImpl(const PropertyBag& bag, boost::posix_time::ptime& result)
    {
        if ( "boost_ptime" == bag.getType() ) // ensure is correct type
        {
            // \todo
			assert(0);
        }
        return false;
    }

    bool BoostTimeDurationTypeInfo::decomposeTypeImpl(const boost::posix_time::time_duration& source, PropertyBag& targetbag)
    {
        targetbag.setType("boost_time_duration");
		assert(0);
        return true;
    }

    bool BoostTimeDurationTypeInfo::composeTypeImpl(const PropertyBag& bag, boost::posix_time::time_duration& result)
    {
        if ( "boost_time_duration" == bag.getType() ) // ensure is correct type
        {
            // \todo
			assert(0);
        }
        return false;
    }

}

// declare the plugin so that RTT can load it from the shared library later.
ORO_TOOLKIT_PLUGIN(Examples::BoostToolkit)
