
#include <cmath>
#include <complex>
#include <algorithm>
#include <iostream>

#include "hark-lib/node/IterCount.h"

namespace hark
{
namespace node
{
    IterCount::IterCount():
        NodeDef("IterCount")
    {
        *this
            << Terminal::in("INPUT")
            << Terminal::in("SYNCHRONOUS").def(false)
            >> Terminal::out("OUTPUT");
    }

    void
    IterCount::reset()
    {
    }

    void
    IterCount::initialize(InputDataBundle &input)
    {
        this->sync = input["SYNCHRONOUS"].last().as<bool>();
    }

    bool
    IterCount::operator () (size_t count, InputDataBundle &input, OutputDataBundle &output)
    {
#ifdef DEBUG
        ptime start_time;
        ptime end_time;
        start_time = microsec_clock::local_time();
#endif

        if(count == 0){ this->initialize(input); }

        auto out = data::create<size_t>();
        auto output_count = out.cast<size_t>();

        if(this->sync){
            const auto &input_dummy = input["INPUT"].at(count); // input is ready
        }
        output_count = count;

        output["OUTPUT"].push(out);

#ifdef DEBUG
        end_time = microsec_clock::local_time();
        std::cout << end_time - start_time << std::endl;
#endif

        return true;
    }
}
}

/* end of file */
