1 // -*- c-basic-offset: 4; related-file-name: "../../lib/elemfilter.cc" -*-
2 #ifndef CLICK_ELEMFILTER_HH
3 #define CLICK_ELEMFILTER_HH
4 #include <click/element.hh>
5 CLICK_DECLS
6 
7 class ElementFilter { public:
8 
9     /** @brief Construct an ElementFilter. */
ElementFilter()10     ElementFilter() {
11     }
12 
13     /** @brief Destroy an ElementFilter. */
~ElementFilter()14     virtual ~ElementFilter() {
15     }
16 
17     /** @brief Determine whether an element or port matches this filter.
18      * @param e element
19      * @param isoutput true for output ports, false for input ports
20      * @param port port number, or -1 to check the element as a whole
21      *
22      * This virtual function is the core of ElementFilter's functionality.
23      * The function should return true iff the specified element or port
24      * matches the filter.  @a isoutput and @a port define the interesting
25      * port; if @a port < 0, the element should be checked as a whole.
26      *
27      * The default implementation returns false for any element.
28      */
29     virtual bool check_match(Element *e, bool isoutput, int port);
30 
31     /** @brief Remove all non-matching elements from @a es.
32      * @param es array of elements
33      *
34      * Calls check_match(e, false, -1) for each element of @a es, removing
35      * those elements that do not match (i.e., check_match() returns false).
36      */
37     void filter(Vector<Element *> &es);
38 
39 };
40 
41 class CastElementFilter : public ElementFilter { public:
42 
43     /** @brief Construct a CastElementFilter.
44      * @param name cast name of matching elements
45      */
46     CastElementFilter(const String &name);
47 
48     /** @brief Determine whether an element matches this filter.
49      * @param e element
50      * @param isoutput ignored
51      * @param port ignored
52      * @return True iff @a e->cast(@a name) != NULL, where @a name is the
53      *   cast name passed to the constructor.
54      */
55     bool check_match(Element *e, bool isoutput, int port);
56 
57   private:
58 
59     String _name;
60 
61 };
62 
63 CLICK_ENDDECLS
64 #endif
65