Statistics
| Branch: | Revision:

root / src / scave / compoundfilter.h @ e1750c09

History | View | Annotate | Download (4.83 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  COMPOUNDFILTER.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//=========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17
18
#ifndef _COMPOUNDFILTER_H_
19
#define _COMPOUNDFILTER_H_
20
21
#include <string>
22
#include <vector>
23
24
#include "nodetype.h"
25
#include "commonnodes.h"
26
27
NAMESPACE_BEGIN
28
29
30
class CompoundFilterType;
31
32
33
/**
34
 * FilterNode nodes combined into a single filter by cascading them.
35
 */
36
class SCAVE_API CompoundFilter : public FilterNode
37
{
38
        friend class CompoundFilterType;
39
    protected:
40
        FilterNode *first;
41
        FilterNode *last;
42
        StringMap _attrvalues;  // _attrs[name] = value
43
    public:
44
        CompoundFilter() {}
45
        virtual ~CompoundFilter() {}
46
        FilterNode *getFirstNode() {return first;}
47
        FilterNode *getLastNode() {return last;}
48
49
        virtual bool isReady() const  {return false;}
50
        virtual void process()  {}
51
        virtual bool isFinished() const {return true;}
52
};
53
54
55
/**
56
 * FilterNode nodes combined into a single filter by cascading them.
57
 */
58
class SCAVE_API CompoundFilterType : public FilterNodeType
59
{
60
    public:
61
        /** Describes one of the cascaded filters */
62
        class Subfilter
63
        {
64
            private:
65
                std::string _nodetype;  // refers to NodeType name
66
                std::string _comment;   // comment
67
                StringMap _attrassignments;  // _attrs[name] = value
68
            public:
69
                const char *getNodeType() const  {return _nodetype.c_str();}
70
                const char *getComment() const  {return _comment.c_str();}
71
                void setNodeType(const char *s)  {_nodetype = s;}
72
                void setComment(const char *s)  {_comment = s;}
73
                /** Allows update, too */
74
                StringMap& attrAssignments() {return _attrassignments;}
75
                bool operator==(const Subfilter& other) const;
76
        };
77
78
    private:
79
        std::string _name;
80
        std::string _description;
81
        bool _hidden;
82
        StringMap _attrs;  // _attrs[name] = description
83
        StringMap _defaults;  // _defaults[name] = default value
84
85
        typedef std::vector<Subfilter> Subfilters;
86
        Subfilters _subfilters;  // filters are now connected in cascade
87
88
    public:
89
        CompoundFilterType() {_hidden=false;}
90
        virtual ~CompoundFilterType() {}
91
        CompoundFilterType& operator=(const CompoundFilterType& other);
92
        bool equals(const CompoundFilterType& other);
93
94
        /** @name Name, description etc. */
95
        //@{
96
        virtual const char *getName() const;
97
        virtual const char *getCategory() const  {return "custom filter";}
98
        virtual const char *getDescription() const;
99
        virtual bool isHidden() const {return _hidden;}
100
        virtual void setName(const char *);
101
        virtual void setDescription(const char *);
102
        virtual void setHidden(bool hidden) {_hidden=hidden;}
103
        //@}
104
105
        /** @name Creation */
106
        //@{
107
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
108
        virtual Port *getPort(Node *node, const char *portname) const;
109
        //@}
110
111
        /** @name Attributes, ports */
112
        //@{
113
        virtual void getAttributes(StringMap& attrs) const;
114
        virtual void getAttrDefaults(StringMap& attrs) const;
115
        virtual void setAttr(const char *name, const char *desc, const char *defaultvalue);
116
        virtual void removeAttr(const char *name);
117
        //@}
118
119
        /** @name Subfilters */
120
        //@{
121
        virtual int getNumSubfilters() const;
122
        /**
123
         * Allows update too, via object reference
124
         */
125
        virtual Subfilter& getSubfilter(int pos);
126
        /**
127
         * Access subfilter.
128
         */
129
        virtual const Subfilter& getSubfilter(int pos) const;
130
        /**
131
         * Insert subfilter at given position (old filter at pos and following ones
132
         * are shifted up).
133
         */
134
        virtual void insertSubfilter(int pos, const Subfilter& f);
135
        /**
136
         * Remove subfilter at given position (following ones are shifted down).
137
         */
138
        virtual void removeSubfilter(int pos);
139
        //@}
140
141
        /** @name Vector attribute mapping */
142
        //@{
143
        /**
144
         * Maps attributes of the input vector to attributes of the output vector.
145
         */
146
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
147
        //@}
148
};
149
150
151
NAMESPACE_END
152
153
154
#endif