/*
   HARK Library
   Copyright (C) 2021 Honda Research Institute Japan Inc.
 */

#include "hark-lib/datastream.h"
#include "hark-lib/error.h"

namespace hark
{
    template<>
    size_t
    DataProxyMapImplWrapper<DataSource, DataSourceMap>::count_ready() const
    {
        return this->_proxy_impl->count_ready_source();
    }

    template<>
    size_t
    DataProxyMapImplWrapper<DataSink, DataSinkMap>::count_ready() const
    {
        return this->_proxy_impl->count_ready_sink();
    }

    size_t
    DataProxyMapImpl::count_ready_source() const
    {
        return std::count_if(this->_values.begin(), this->_values.end(),
                             [this](std::pair<std::string, DataProxy *> &&it){
//             {
//                 std::stringstream ss;
//                 ss << this->_parent->name() << ": in: " << it.first << ": " << it.second->is_source_ready() << std::endl;
//                 std::cout << ss.str();
//             }
            return it.second->is_source_ready();
        });
    }

    size_t
    DataProxyMapImpl::count_ready_sink() const
    {
        return std::count_if(this->_values.begin(), this->_values.end(),
                             [this](std::pair<std::string, DataProxy *> &&it){
//             {
//                 std::stringstream ss;
//                 ss << this->_parent->name() << ": out: " << it.first << ": " << it.second->is_sink_ready() << std::endl;
//                 std::cout << ss.str();
//             }
            return it.second->is_sink_ready();
        });
    }

    template<>
    DataSink &
    DataProxyMapImplWrapper<DataSink, DataSinkMap>::query(const std::string &name)
    {
        return this->operator [] (name);
    }

    DataProxyMap *
    DataProxyMap::create(DataProxyFactory &factory, BaseNode *parent)
    {
        return new DataProxyMapImpl(factory, parent);
    }
}

/* end of file */
