Source

quechua / modules / processor / IpProcessor / attributes.h

Full commit
/* 
 * Quechua - the lightweight data mining framework
 *
 * Copyright (C) 2012 Marek Denis <quechua@octogan.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef ATTRIBUTES_H
#define ATTRIBUTES_H

#include "../../../include/types.h"
#include "../../../include/log.h"
#include "../../data/types.h"
class Attribute;
typedef std::list<Attribute*> attributes_list;

enum ATTR_TYPE {SINGLE_ATTRIBUTE = 0, RANGE_ATTRIBUTE = 1};

struct attribute_cfg {
    ATTR_TYPE type;
    u_int16_t range;
    index_t index;
    const char* desc;
};

struct attribute_val {
    const char* desc;
    index_t value;
//    attribute_val(string_t& d, index_t& v): desc(d), value(v) {};
};

class Attribute {
 public:
    Attribute(const attribute_cfg& cfg);

    const char* get_desc();
    index_t& get_index();
    ATTR_TYPE get_type();
    u_int16_t get_range();

 protected:
    const char* desc;
    u_int16_t range;
    ATTR_TYPE type;
    index_t index;
};

class Attributes {
 public:
    Attributes();
    virtual ~Attributes();
    //setters
    void set_attribute(ATTR_TYPE type,const char* desc, const u_int16_t range);
    index_t get_attribute_index(const char* desc, const u_int16_t);
    attribute_val*  get_attribute_value(const index_t& idx, attribute_val* value);
 protected:
    index_t index;
    attributes_list attributes;

    static const char* default_desc;

    void set_single_attribute(const char* desc);
    void set_range_attribute(const char*, const u_int16_t range);

    const char* get_desc_by_val(const index_t& value);

    index_t allocate_index();
    inline void extract_index(const index_t& range);

    bool check_attribute(Attribute* attribute,const index_t& val);
};
#endif /* ATTRIBUTES_H */