Wiselib
wiselib.testing/internal_interface/node/node_new.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 __NODE_H__
00020 #define __NODE_H__
00021 
00022 namespace wiselib
00023 {
00024    template<   typename Os_P,
00025             typename Radio_P,
00026             typename NodeID_P,
00027             typename Position_P,
00028             typename Debug_P>
00029    class NodeType
00030    {
00031    public:
00032       typedef Os_P Os;
00033       typedef Radio_P Radio;
00034       typedef NodeID_P NodeID;
00035       typedef Position_P Position;
00036       typedef Debug_P Debug;
00037       typedef typename Radio::block_data_t block_data_t;
00038       typedef typename Radio::size_t size_t;
00039       typedef NodeType<Os, Radio, NodeID, Position, Debug> self_type;
00040       NodeType():
00041          id ( 0 )
00042       {}
00043       NodeType( block_data_t* buff, size_t offset = 0 )
00044       {
00045          get_from_buffer(buff, offset);
00046       }
00047       NodeType( const self_type& _n )
00048       {
00049          *this = _n;
00050       }
00051       NodeType( const NodeID& _id, const Position& _p )
00052       {
00053          set_all( _id, _p );
00054       }
00055       inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 )
00056       {
00057          uint8_t ID_POS = 0;
00058          uint8_t POSITION_POS = ID_POS + sizeof( NodeID );
00059          write<Os, block_data_t, NodeID>( buff + ID_POS + offset, id );
00060          position.set_buffer_from( buff, POSITION_POS + offset );
00061          return buff;
00062       }
00063       inline void get_from_buffer(block_data_t* buff, size_t offset = 0)
00064       {
00065          uint8_t ID_POS = 0;
00066          uint8_t POSITION_POS = ID_POS + sizeof( NodeID );
00067          id = read<Os, block_data_t, NodeID>( buff + ID_POS + offset );
00068          position.get_from_buffer( buff, POSITION_POS + offset );
00069       }
00070       inline size_t get_buffer_size()
00071       {
00072          uint8_t ID_POS = 0;
00073          uint8_t POSITION_POS = ID_POS + sizeof( NodeID );
00074          return POSITION_POS + position.get_buffer_size();
00075       }
00076       inline self_type& operator=( const self_type& _n )
00077       {
00078          position = _n.position;
00079          id  = _n.id;
00080          return *this;
00081       }
00082       inline NodeID get_id()
00083       {
00084          return id;
00085       }
00086       inline Position get_position()
00087       {
00088          return position;
00089       }
00090       void set_id( const NodeID& _id )
00091       {
00092          id = _id;
00093       }
00094       void set_position( const Position& _p )
00095       {
00096          position = _p;
00097       }
00098       void set_all( const NodeID& _id, const Position& _p )
00099       {
00100          position = _p;
00101          id = _id;
00102       }
00103       inline void print( Debug& debug )
00104       {
00105          debug.debug( "Node (size %i) :", get_buffer_size() );
00106          debug.debug( "id (size %i) : %x", sizeof( NodeID ), id );
00107          position.print( debug );
00108       }
00109    private:
00110       NodeID id;
00111       Position position;
00112    };
00113 }
00114 
00115 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines