Click
Loading...
Searching...
No Matches
routervisitor.hh
Go to the documentation of this file.
1// -*- c-basic-offset: 4; related-file-name: "../../lib/routervisitor.cc" -*-
2#ifndef CLICK_ROUTERVISITOR_HH
3#define CLICK_ROUTERVISITOR_HH
4#include <click/element.hh>
5#include <click/bitvector.hh>
6#include <click/pair.hh>
7
8CLICK_DECLS
9
17class RouterVisitor { public:
18
21 }
22
24 virtual ~RouterVisitor() {
25 }
26
52 virtual bool visit(Element *e, bool isoutput, int port,
53 Element *from_e, int from_port, int distance);
54
69 virtual int distance(Element *e, Element *from_e);
70
71};
72
82class ElementTracker : public RouterVisitor { public:
83
86 ElementTracker(Router *router);
87
89 const Vector<Element *> &elements() const {
90 return _elements;
91 }
93 int size() const {
94 return _elements.size();
95 }
99 Element *operator[](int i) const {
100 return _elements[i];
101 }
102
107 return _elements.begin();
108 }
111 return _elements.end();
112 }
113
115 bool contains(const Element *e) const {
116 return _reached[e->eindex()];
117 }
118
120 void insert(Element *e) {
121 if (!_reached[e->eindex()]) {
122 _reached[e->eindex()] = true;
123 _elements.push_back(e);
124 }
125 }
126
128 void clear() {
129 _reached.clear();
130 _elements.clear();
131 }
132
133 private:
134
135 Bitvector _reached;
136 Vector<Element *> _elements;
137
138};
139
157class ElementCastTracker : public ElementTracker { public:
158
162 ElementCastTracker(Router *router, const String &name, bool stopAtFirst = true)
163 : ElementTracker(router), _name(name), _continue(!stopAtFirst) {
164 }
165
166 bool visit(Element *e, bool isoutput, int port,
167 Element *from_e, int from_port, int distance);
168
169 private:
170
171 String _name;
172 bool _continue;
173
174};
175
193
198 ElementNeighborhoodTracker(Router *router, int diameter = 1)
199 : ElementTracker(router), _diameter(diameter) {
200 }
201
202 bool visit(Element *e, bool isoutput, int port,
203 Element *from_e, int from_port, int distance);
204
205 private:
206
207 int _diameter;
208
209};
210
211CLICK_ENDDECLS
212#endif
Click's bitvector class.
Vector of bits.
Definition bitvector.hh:21
void clear()
Set all bits to false.
Definition bitvector.cc:59
Router configuration visitor that collects elements that match a certain cast.
Definition routervisitor.hh:157
ElementCastTracker(Router *router, const String &name, bool stopAtFirst=true)
Construct an ElementCastTracker.
Definition routervisitor.hh:162
bool visit(Element *e, bool isoutput, int port, Element *from_e, int from_port, int distance)
Visit an element.
Definition routervisitor.cc:45
Base class for Click elements.
Definition element.hh:42
int eindex() const
Return the element's index within its router.
Definition element.hh:524
Router configuration visitor that collects close-by elements.
Definition routervisitor.hh:192
bool visit(Element *e, bool isoutput, int port, Element *from_e, int from_port, int distance)
Visit an element.
Definition routervisitor.cc:55
ElementNeighborhoodTracker(Router *router, int diameter=1)
Construct an ElementNeighborhoodTracker.
Definition routervisitor.hh:198
Base class for router configuration visitors that collect elements.
Definition routervisitor.hh:82
Vector< Element * >::const_iterator const_iterator
Iterator type.
Definition routervisitor.hh:104
void insert(Element *e)
Add element e to the set of matching elements.
Definition routervisitor.hh:120
void clear()
Clear the set of matching elements.
Definition routervisitor.hh:128
const Vector< Element * > & elements() const
Return the elements that matched.
Definition routervisitor.hh:89
const_iterator begin() const
Return an iterator for the first matching element.
Definition routervisitor.hh:106
bool contains(const Element *e) const
Return true iff element e is a matching element.
Definition routervisitor.hh:115
const_iterator end() const
Return an iterator for the end of the container.
Definition routervisitor.hh:110
Element * operator[](int i) const
Return the i'th matching element.
Definition routervisitor.hh:99
int size() const
Return the number of matching elements.
Definition routervisitor.hh:93
A router configuration.
Definition router.hh:28
Base class for router configuration visitors.
Definition routervisitor.hh:17
virtual int distance(Element *e, Element *from_e)
return the distance between two neighbour elements
Definition routervisitor.cc:35
virtual ~RouterVisitor()
Destroy an RouterVisitor.
Definition routervisitor.hh:24
RouterVisitor()
Construct an RouterVisitor.
Definition routervisitor.hh:20
virtual bool visit(Element *e, bool isoutput, int port, Element *from_e, int from_port, int distance)
Visit an element.
Definition routervisitor.cc:29
A string of characters.
Definition string.hh:22
Vector template.
Definition vector.hh:111
void clear()
Remove all elements.
Definition vector.hh:476
iterator end()
Return an iterator for the end of the vector.
Definition vector.hh:266
iterator begin()
Return an iterator for the first element in the vector.
Definition vector.hh:253
size_type size() const
Return the number of elements.
Definition vector.hh:231
void push_back(value_argument_type v)
Append element v.
Definition vector.hh:399
Click's Element class.