view host/Rule.h @ 7:b30fcffc5000

* Better organisation of action classes; support for AND-type rules
author cannam
date Mon, 27 Nov 2006 11:03:52 +0000
parents f0e9092bd3e4
children 10715d2b3069
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

#ifndef _RULE_H_
#define _RULE_H_

#include <vector>

#include "Action.h"

class Condition
{
public:
    enum Type {
        EqualTo,
        GreaterThan,
        LessThan,
        NotEqualTo,
        Present,
        Changed,
        GapGreaterThan,
        GapLessThan
    };

    Condition(int pluginIndex, int outputNumber,
              Type type, float argument = 0.f) :
        m_pluginIndex(pluginIndex),
        m_outputNumber(outputNumber),
        m_type(type),
        m_argument(argument)
    { }

    int getPluginIndex() const { return m_pluginIndex; }
    int getOutputNumber() const { return m_outputNumber; }
    Type getType() const { return m_type; }
    float getArgument() const { return m_argument; }

/*
    bool operator<(const Condition &c) const {
        if (m_pluginIndex < c.m_pluginIndex) return true;
        else if (m_pluginIndex > c.m_pluginIndex) return false;
        if (m_outputNumber < c.m_outputNumber) return true;
        else if (m_outputNumber > c.m_outputNumber) return false;
        if (int(m_type) < int(c.m_type)) return true;
        else if (int(m_type) > int(c.m_type)) return true;
        return m_argument < c.m_argument;
    }
*/

protected:
    int m_pluginIndex;
    int m_outputNumber;
    Type m_type;
    float m_argument;
};

class Rule
{
public:
    Rule() : m_action(0) { }
    virtual ~Rule();

    void addCondition(Condition condition);
    void setAction(Action *action); // I take ownership of action

    typedef std::vector<Condition> ConditionList;
    const ConditionList &getConditions() const { return m_conditions; }

    Action *getAction() { return m_action; }

protected:
    std::vector<Condition> m_conditions;
    Action *m_action;
};

#endif