Wiselib
wiselib.testing/algorithms/tracking/PLTT_node.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 __PLTT_NODE_H__
00020 #define __PLTT_NODE_H__
00021 namespace wiselib
00022 {
00023    template<   typename Os_P,
00024             typename Radio_P,
00025             typename Node_P,
00026             typename PLTT_NodeTarget_P,
00027             typename PLTT_NodeTargetList_P,
00028             typename PLTT_TraceList_P,
00029             typename Debug_P>
00030    class PLTT_NodeType
00031    {
00032    public:
00033       typedef Os_P Os;
00034       typedef Radio_P Radio;
00035       typedef  Node_P Node;
00036       typedef PLTT_NodeTarget_P PLTT_NodeTarget;
00037       typedef PLTT_NodeTargetList_P PLTT_NodeTargetList;
00038       typedef PLTT_TraceList_P PLTT_TraceList;
00039       typedef Debug_P Debug;
00040       typedef typename PLTT_TraceList::iterator PLTT_TraceListIterator;
00041       typedef typename PLTT_NodeTargetList::iterator PLTT_NodeTargetListIterator;
00042       typedef typename PLTT_NodeTarget::IntensityNumber IntensityNumber;
00043       typedef typename Radio::block_data_t block_data_t;
00044       typedef typename Radio::size_t size_t;
00045       typedef typename Radio::node_id_t node_id_t;
00046       typedef PLTT_NodeType<Os, Radio, Node, PLTT_NodeTarget, PLTT_NodeTargetList, PLTT_TraceList, Debug> self_type;
00047       inline PLTT_NodeType()
00048       {}
00049       inline PLTT_NodeType( block_data_t* buff, size_t offset = 0 )
00050       {
00051          get_from_buffer( buff, offset );
00052       }
00053       inline PLTT_NodeType( Node _n )
00054       {
00055          node = _n;
00056       }
00057       inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 )
00058       {
00059          uint8_t PLTT_NODE_SIZE_POS = 0;
00060          uint8_t  NODE_POS = PLTT_NODE_SIZE_POS + sizeof( size_t );
00061          uint8_t TARGET_LIST_POS = NODE_POS + node.get_buffer_size();
00062          size_t len = get_buffer_size();
00063          write<Os, block_data_t, size_t>( buff + PLTT_NODE_SIZE_POS + offset, len );
00064          node.set_buffer_from( buff, NODE_POS + offset );
00065          for ( uint16_t i = 0; i < target_list.size(); i++ )
00066          {
00067             target_list.at( i ).set_buffer_from( buff, TARGET_LIST_POS + i * target_list.at( i ).get_buffer_size() + offset );
00068          }
00069          return buff;
00070       }
00071       inline void get_from_buffer( block_data_t* buff, size_t offset = 0 )
00072       {
00073          uint8_t PLTT_NODE_SIZE_POS = 0;
00074          uint8_t NODE_POS = PLTT_NODE_SIZE_POS + sizeof( size_t );
00075          uint8_t TARGET_LIST_POS = NODE_POS + node.get_buffer_size();
00076          size_t len = read<Os, block_data_t, size_t>( buff + PLTT_NODE_SIZE_POS + offset );
00077          node.get_from_buffer( buff, NODE_POS + offset );
00078          PLTT_NodeTarget nt;
00079          for ( uint16_t i = 0; i < ( ( len - node.get_buffer_size() - 1 ) / nt.get_buffer_size() ); i++ )
00080          {
00081             nt.get_from_buffer( buff, TARGET_LIST_POS + nt.get_buffer_size() * i + offset );
00082             target_list.push_back( nt );
00083          }
00084       }
00085       inline size_t get_buffer_size()
00086       {
00087          uint8_t PLTT_NODE_SIZE_POS = 0;
00088          uint8_t NODE_POS = PLTT_NODE_SIZE_POS + sizeof( size_t );
00089          uint8_t TARGET_LIST_POS = NODE_POS + node.get_buffer_size();
00090          PLTT_NodeTarget nt;
00091          return TARGET_LIST_POS + target_list.size() * nt.get_buffer_size();
00092       }
00093       inline self_type& operator=( const self_type& _p )
00094       {
00095          node = _p.node;
00096          target_list = _p.target_list;
00097          return *this;
00098       }
00099       inline Node get_node()
00100       {
00101          return node;
00102       }
00103       inline PLTT_NodeTargetList* get_node_target_list()
00104       {
00105          return &target_list;
00106       }
00107       inline void set_node( Node _n )
00108       {
00109          node = _n;
00110       }
00111       inline void set_node_target_list( PLTT_NodeTargetList& _ntl )
00112       {
00113          target_list = _ntl;
00114       }
00115       inline void set_node_target_list( PLTT_TraceList& _tl )
00116       {
00117          target_list.clear();
00118          for ( PLTT_TraceListIterator i = _tl.begin(); i != _tl.end(); ++i )
00119          {
00120             if ( ( i->get_intensity() > 0 ) || ( i->get_inhibited() == 0 ) )
00121             {
00122                PLTT_NodeTarget nt;
00123                nt.set_intensity( i->get_intensity() );
00124                nt.set_target_id( i->get_target_id() );
00125                target_list.push_back( nt );
00126             }
00127          }
00128       }
00129       inline void set_node_target( PLTT_TraceList& _tl, node_id_t _nid )
00130       {
00131          target_list.clear();
00132          for ( PLTT_TraceListIterator i = _tl.begin(); i != _tl.end(); ++i )
00133          {
00134             if ( ( ( i->get_intensity() > 0 ) || ( i->get_inhibited() == 0 ) ) && ( _nid == i->get_target_id() ) )
00135             {
00136                PLTT_NodeTarget nt;
00137                nt.set_intensity( i->get_intensity() );
00138                nt.set_target_id( i->get_target_id() );
00139                target_list.push_back( nt );
00140             }
00141          }
00142       }
00143       inline void set_all( Node& _n, PLTT_TraceList& _tl )
00144       {
00145          set_node( _n );
00146          set_node_target_list( _tl );
00147       }
00148       inline void print( Debug& debug )
00149       {
00150          debug.debug( " PLTT_Node (size %i) :", get_buffer_size() );
00151          node.print( debug );
00152          debug.debug( " PLTT_TargetList (size %i) :", target_list.size()*sizeof( PLTT_NodeTarget ) );
00153          for ( PLTT_NodeTargetListIterator i = target_list.begin(); i != target_list.end(); ++i )
00154          {
00155             i->print( debug );
00156          }
00157       }
00158    private:
00159       Node node;
00160       PLTT_NodeTargetList target_list;
00161    };
00162 }
00163 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines