Wiselib
wiselib.testing/internal_interface/connectivity/connectivity.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 ** This file is part of the generic algorithm library Wiselib.           **
00003 ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004 **                                                                       **
00005 ** The Wiselib is free software: you can redistribute it and/or modify   **
00006 ** it under the terms of the GNU Lesser General Public License as        **
00007 ** published by the Free Software Foundation, either version 3 of the    **
00008 ** License, or (at your option) any later version.                       **
00009 **                                                                       **
00010 ** The Wiselib is distributed in the hope that it will be useful,        **
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013 ** GNU Lesser General Public License for more details.                   **
00014 **                                                                       **
00015 ** You should have received a copy of the GNU Lesser General Public      **
00016 ** License along with the Wiselib.                                       **
00017 ** If not, see <http://www.gnu.org/licenses/>.                           **
00018 ***************************************************************************/
00019 #ifndef __CONECTIVITY_H__
00020 #define __CONECTIVITY_H__
00021 namespace wiselib
00022 {
00023    template<   typename Os_P,
00024             typename Radio_P,
00025             typename Node_P,
00026             typename NodeList_P,
00027             typename Debug_P>
00028    class ConnectivityType
00029    {
00030    public:
00031       typedef Os_P Os;
00032       typedef  Node_P Node;
00033       typedef Radio_P Radio;
00034       typedef NodeList_P NodeList;
00035       typedef Debug_P Debug;
00036       typedef typename Radio::block_data_t block_data_t;
00037       typedef typename Radio::node_id_t node_id_t;
00038       typedef typename NodeList::iterator NodeListIterator;
00039       ConnectivityType( void )
00040       {}
00041       ConnectivityType(block_data_t* buff, size_t offset = 0 )
00042       {
00043          get_from_buffer( buff, offset );
00044       }
00045       inline Node get_node()
00046       {
00047          return node;
00048       }
00049       inline void set_node(const Node& _n)
00050       {
00051          node = _n;
00052       }
00053       inline NodeList* get_node_list()
00054       {
00055          return &node_list;
00056       }
00057       inline void set_node_list( NodeList& _nl )
00058       {
00059          node_list = _nl;
00060       }
00061       block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 )
00062       {
00063          uint8_t LAZY_CONNECTIVITY_SIZE_POS  = 0;
00064          uint8_t NODE_POS = LAZY_CONNECTIVITY_SIZE_POS + sizeof( size_t );
00065          uint8_t NODE_LIST_POS = NODE_POS + node.get_buffer_size();
00066          size_t len = get_buffer_size();
00067          write<Os, block_data_t, size_t>( buff + LAZY_CONNECTIVITY_SIZE_POS + offset, len );
00068          node.set_buffer_from( buff, NODE_POS + offset );
00069          for ( uint16_t i = 0; i < node_list.size(); i++ )
00070          {
00071             node_list.at(i).set_buffer_from( buff, NODE_LIST_POS + i * node_list.at( i ).get_buffer_size() + offset );
00072          }
00073          return buff;
00074       }
00075       void get_from_buffer( block_data_t* buff, size_t offset = 0 )
00076       {
00077          uint8_t LAZY_CONNECTIVITY_SIZE_POS  = 0;
00078          uint8_t NODE_POS = LAZY_CONNECTIVITY_SIZE_POS + sizeof( size_t );
00079          uint8_t NODE_LIST_POS = NODE_POS + node.get_buffer_size();
00080          size_t len = read<Os, block_data_t, size_t>( buff + LAZY_CONNECTIVITY_SIZE_POS + offset);
00081          node.get_from_buffer( buff, NODE_POS + offset );
00082          Node n;
00083          for ( uint16_t i = 0; i < ( ( len - node.get_buffer_size() -1 ) / n.get_buffer_size() ); i++ )
00084          {
00085             n.get_from_buffer( buff, NODE_LIST_POS + ( i * n.get_buffer_size() ) + offset );
00086             node_list.push_back( n );
00087          }
00088       }
00089       size_t get_buffer_size()
00090       {
00091          Node n;
00092          uint8_t LAZY_CONNECTIVITY_SIZE_POS  = 0;
00093          uint8_t NODE_POS = LAZY_CONNECTIVITY_SIZE_POS + sizeof( size_t );
00094          uint8_t NODE_LIST_POS = NODE_POS + n.get_buffer_size();
00095          return NODE_LIST_POS + node_list.size() * n.get_buffer_size();
00096       }
00097       void print( Debug& debug )
00098       {
00099          debug.debug( "Connectivity : (size %i) : \n", get_buffer_size() );
00100          node.print( debug );
00101          debug.debug("\n");
00102          for (NodeListIterator i = node_list.begin(); i != node_list.end(); ++i )
00103          {
00104             i->print( debug );
00105             debug.debug("\n");
00106          }
00107       }
00108    private:
00109       Node node;
00110       NodeList node_list;
00111    };
00112 }
00113 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines