vle-forge / irritator

Other
5 stars 4 forks source link

refactor is-compatible ports with constexpr #93

Open quesnel opened 2 years ago

quesnel commented 2 years ago

We known the type of output/input for each ports. So we can provide a constant expression is-compatible port for each model.

enum class value_port_type : i8 {
    continuous,
    discrete,
    both
};

class counter {
    input_port x[1];

    constexpr value_port_type x_type(int i) noexcept
    {
        return value_port_type::both;
    }

};

class abstract_cross{
    input_port x[4];
    output_port y[3];

    constexpr value_port_type x_type(int i) noexcept
    {
        return value_port_type::both;
    }

    constexpr value_port_type y_type(int i) noexcept
    {
        if (i == 0 || i == 1)
            return value_port_type::continuous;
        else
            return value_port_type::discrete;
    }
};