Node.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __Node__
00042 #define __Node__
00043
00044 #include "boost/shared_ptr.hpp"
00045 #include <boost/shared_array.hpp>
00046 #include "debug.h"
00047 #include "mw/nl/awds/MAC.h"
00048 #include "mw/nl/awds/ComparableAttributeSet.h"
00049
00050 namespace famouso {
00051 namespace mw {
00052 namespace nl {
00053 namespace awds {
00054
00055 namespace detail {
00060 template< class AttrSet >
00061 class Node: boost::noncopyable {
00062 private:
00063
00068 Node(MAC mac) :
00069 _mac(mac) {
00070 }
00071
00072 public:
00073
00076 typedef boost::shared_ptr<Node> type;
00077
00079 typedef typename ComparableAttributeSet<AttrSet>::type NodeAttributes;
00080
00083 struct comp {
00093 bool operator()(const type &lhs, const type &rhs) const {
00094 return lhs->mac() < rhs->mac();
00095 }
00096 };
00097
00102 const MAC &mac() const {
00103 return _mac;
00104 }
00105
00110 NodeAttributes &attr() {
00111 return _attr;
00112 }
00113
00120 void attr(NodeAttributes &attribs) {
00121 _attr = attribs->clone();
00122 }
00123
00129 template< class Attrib >
00130 Attrib *find() {
00131 return attr()->find<Attrib> ();
00132 }
00133
00140 template< class Attrib >
00141 typename Attrib::value_type get() {
00142 Attrib *res = find<Attrib> ();
00143 if (!res)
00144 throw "Missing Attribute";
00145 return res->get();
00146 }
00147
00153 bool operator==(const Node& o) const {
00154 return _mac == o._mac;
00155 }
00156
00161 void print(::logging::loggingReturnType &out) const {
00162 out << _mac;
00163 }
00164
00169 static type create(MAC mac) {
00170 type res = type(new Node(mac));
00171 return res;
00172 }
00173
00174 private:
00175 MAC _mac;
00176 NodeAttributes _attr;
00177 };
00178 }
00179 }
00180 }
00181 }
00182 }
00183
00184 namespace logging {
00192 template< class AttrSet >
00193 inline ::logging::loggingReturnType &operator <<(::logging::loggingReturnType &out, const boost::shared_ptr<
00194 famouso::mw::nl::awds::detail::Node<AttrSet> > &c) {
00195 c->print(out);
00196 return out;
00197 }
00198
00206 template< class AttrSet >
00207 inline ::logging::loggingReturnType &operator <<(::logging::loggingReturnType &out,
00208 const famouso::mw::nl::awds::detail::Node<AttrSet> &c) {
00209 c.print(out);
00210 return out;
00211 }
00212 }
00213
00214 #endif