Menu

Node.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2008-2009 Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de>
00004  *               2009-2010 Michael Kriese <kriese@cs.uni-magdeburg.de>
00005  * All rights reserved.
00006  *
00007  *    Redistribution and use in source and binary forms, with or without
00008  *    modification, are permitted provided that the following conditions
00009  *    are met:
00010  *
00011  *    * Redistributions of source code must retain the above copyright
00012  *      notice, this list of conditions and the following disclaimer.
00013  *
00014  *    * Redistributions in binary form must reproduce the above copyright
00015  *      notice, this list of conditions and the following disclaimer in
00016  *      the documentation and/or other materials provided with the
00017  *      distribution.
00018  *
00019  *    * Neither the name of the copyright holders nor the names of
00020  *      contributors may be used to endorse or promote products derived
00021  *      from this software without specific prior written permission.
00022  *
00023  *
00024  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00025  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *
00037  * $Id$
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                 } /* namespace detail */
00179             } /* awds*/
00180         } /* nl */
00181     } /* mw */
00182 } /* famouso */
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 } /* logging */
00213 
00214 #endif /* __Node__ */