Wiselib
wiselib.testing/internal_interface/node/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 __NODE_H__
00020 #define __NODE_H__
00021 
00022 namespace wiselib
00023 {
00024    template<typename NodeID_P,
00025            typename NodePosition_P,
00026            typename block_data_P,
00027            typename Debug_P,
00028            typename OsModel_P>
00029    class NodeType
00030    {
00031    public:
00032       typedef NodeID_P NodeID;
00033       typedef NodePosition_P NodePosition;
00034       typedef block_data_P block_data;
00035       typedef OsModel_P OsModel;
00036       typedef Debug_P Debug;
00037       typedef typename NodePosition::Float Float;
00038       NodeType():
00039          id ( 0 )
00040       {}
00041       NodeType( block_data* buff, size_t offset = 0 )
00042       {
00043          get_Node_from_buffer2D(buff, offset);
00044       }
00045       enum Node_Positions
00046       {
00047          NODE_ID_POS = 0,
00048          POSITION_POS = NODE_ID_POS + sizeof(NodeID)
00049       };
00050       inline block_data* set_buffer_from_Node2D(block_data* buff, size_t offset = 0)
00051       {
00052          write<OsModel, block_data, NodeID>( buff + NODE_ID_POS + offset, id);
00053          position.set_buffer_from_Position2D( buff, POSITION_POS + offset);
00054          return buff;
00055       }
00056       inline void get_Node_from_buffer2D(block_data* buff, size_t offset = 0)
00057       {
00058          id = read<OsModel, block_data, NodeID>( buff + NODE_ID_POS + offset);
00059          position.get_Position2D_from_buffer(buff, POSITION_POS + offset);
00060       }
00061       inline block_data* set_buffer_from_Node3D(block_data* buff, size_t offset = 0)
00062       {
00063          write<OsModel, block_data, NodeID>( buff + NODE_ID_POS + offset, id);
00064          position.set_buffer_from_Position3D( buff, POSITION_POS + offset);
00065          return buff;
00066       }
00067       inline void get_Node_from_buffer3D(block_data* buff, size_t offset = 0)
00068       {
00069          id = read<OsModel, block_data, NodeID>( buff + NODE_ID_POS + offset);
00070          position.get_Position3D_from_buffer(buff, POSITION_POS + offset);
00071       }
00072       inline size_t get_buffer_len()
00073       {
00074          return sizeof(NodeID) + position.get_buffer_size_2D();
00075       }
00076       inline NodeID get_node_id()
00077       {
00078          return id;
00079       }
00080       inline NodePosition get_position()
00081       {
00082          return position;
00083       }
00084       void set_node_id(NodeID n_id)
00085       {
00086          id = n_id;
00087       }
00088       void set_position(Float x, Float y, Float z)
00089       {
00090          position.x = x;
00091          position.y = y;
00092          position.z = z;
00093       }
00094       inline void print_node( Debug& debug)
00095       {
00096          debug.debug("node id = %x, node coords = ( %i, %i, %i )\n", id, position.x, position.y, position.z );
00097       }
00098    private:
00099       NodeID id;
00100       NodePosition position;
00101    };
00102 }
00103 
00104 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines