Wiselib
|
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 namespace wiselib 00020 { 00021 template< typename Os_P, 00022 typename Radio_P, 00023 typename DataType_P 00024 typename Debug_P> 00025 class SerializableType 00026 { 00027 public: 00028 typedef Os_P Os; 00029 typedef Radio_P Radio; 00030 typedef DataType_P DataType; 00031 typedef Debug_P Debug; 00032 typedef typename Radio::block_data_t block_data_t; 00033 typedef typename Radio::size_t size_t; 00034 SerializableType( const DataType& _d ) 00035 { 00036 data = _d; 00037 } 00038 SerializableType( block_data_t* buff, size_t offset = 0 ) 00039 { 00040 get_from_buffer( buff, offset ); 00041 } 00042 void set_buffer_from( block_data_t* buff, size_t offset = 0 ) 00043 { 00044 write<Os, block_data_t, DataType>( buff + offset, data ); 00045 } 00046 PLTT_TrackReportType get_from_buffer( block_data_t* buff, size_t offset = 0 ) 00047 { 00048 data = read<Os, block_data_t, DataType>( buff + offset ); 00049 return *this; 00050 } 00051 size_t get_buffer_size() 00052 { 00053 return sizeof(DataType); 00054 } 00055 inline void set_data( const DataType _d ) 00056 { 00057 target = _d; 00058 } 00059 inline Node get_data() 00060 { 00061 return data; 00062 } 00063 void print( Debug& debug ) 00064 { 00065 debug.debug( " %x ", data ); 00066 } 00067 private: 00068 DataType data; 00069 }; 00070 00071 template< typename Os_P, 00072 typename Radio_P, 00073 typename SerializableType1_P, 00074 typename SerializableType2_P, 00075 typename Debug_p > 00076 class SerializableSet2_Type 00077 { 00078 public: 00079 typedef Os_P Os; 00080 typedef Radio_P Radio; 00081 typedef SerializableType1_P SerializableType1; 00082 typedef SerializableType2_P SerializableType2; 00083 typedef Debug_P Debug; 00084 typedef typename Radio::block_data_t block_data_t; 00085 typedef typename Radio::size_t size_t; 00086 typedef SerializableSet2_Type<Os, Radio, SerializableType1, SerializableType2, Debug> self_type; 00087 SerializableSet2_Type() 00088 {} 00089 SerializableSet2_Type( const self_type& _d ) 00090 { 00091 *this = _d; 00092 } 00093 SerializableSet2_Type( block_data_t* buff, size_t offset = 0 ) 00094 { 00095 get_from_buffer( buff, offset ); 00096 } 00097 inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 ) 00098 { 00099 uint8_t DATA1_POS = 0; 00100 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00101 data1.set_buffer_from( buff, DATA1_POS + offset ); 00102 data2.set_buffer_from( buff, DATA2_POS + offset ); 00103 return buff; 00104 } 00105 inline void get_from_buffer(block_data_t* buff, size_t offset = 0 ) 00106 { 00107 uint8_t DATA1_POS = 0; 00108 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00109 data1.get_from_buffer( buff, DATA1_POS + offset ); 00110 data2.get_from_buffer( buff, DATA2_POS + offset ); 00111 } 00112 inline size_t get_buffer_size() 00113 { 00114 uint8_t DATA1_POS = 0; 00115 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00116 return DATA2_POS + data2.get_buffer_size(); 00117 } 00118 inline self_type& operator=( const self_type& _t ) 00119 { 00120 data1 = _t.data1; 00121 data2 = _t.data2; 00122 return *this; 00123 } 00124 inline void set_data1( const SerializableType1& _d ) 00125 { 00126 data1 = _d; 00127 } 00128 inline void set_data2( const SerializableType2& _d ) 00129 { 00130 data2 = _d; 00131 } 00132 inline SerializableType1 get_data1() 00133 { 00134 return data1; 00135 } 00136 inline SerializableType2 get_data2() 00137 { 00138 return data2; 00139 } 00140 inline void print( Debug& debug ) 00141 { 00142 data1.print( debug ); 00143 data2.print( debug ); 00144 } 00145 private: 00146 SerializableType1 data1; 00147 SerializableType2 data2; 00148 }; 00149 00150 template< typename Os_P, 00151 typename Radio_P, 00152 typename SerializableType1_P, 00153 typename SerializableType2_P, 00154 typename SerializableType3_P, 00155 typename Debug_p > 00156 class SerializableSet3_Type 00157 { 00158 public: 00159 typedef Os_P Os; 00160 typedef Radio_P Radio; 00161 typedef SerializableType1_P SerializableType1; 00162 typedef SerializableType2_P SerializableType2; 00163 typedef SerializableType3_P SerializableType3; 00164 typedef Debug_P Debug; 00165 typedef typename Radio::block_data_t block_data_t; 00166 typedef typename Radio::size_t size_t; 00167 typedef SerializableSet_Type<Os, Radio, SerializableType1, SerializableType2, SerializableType3, Debug> self_type; 00168 SerializableSet3_Type() 00169 {} 00170 SerializableSet3_Type( const self_type& _d ) 00171 { 00172 *this = _d; 00173 } 00174 SerializableSet3_Type( block_data_t* buff, size_t offset = 0 ) 00175 { 00176 get_from_buffer( buff, offset ); 00177 } 00178 inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 ) 00179 { 00180 uint8_t DATA1_POS = 0; 00181 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00182 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00183 data1.set_buffer_from( buff, DATA1_POS + offset ); 00184 data2.set_buffer_from( buff, DATA2_POS + offset ); 00185 data3.set_buffer_from( buff, DATA3_POS + offset ); 00186 return buff; 00187 } 00188 inline void get_from_buffer(block_data_t* buff, size_t offset = 0 ) 00189 { 00190 uint8_t DATA1_POS = 0; 00191 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00192 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00193 data1.get_from_buffer( buff, DATA1_POS + offset ); 00194 data2.get_from_buffer( buff, DATA2_POS + offset ); 00195 data3.get_from_buffer( buff, DATA3_POS + offset ); 00196 } 00197 inline size_t get_buffer_size() 00198 { 00199 uint8_t DATA1_POS = 0; 00200 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00201 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00202 return DATA3_POS + data3.get_buffer_size(); 00203 } 00204 inline self_type& operator=( const self_type& _t ) 00205 { 00206 data1 = _t.data1; 00207 data2 = _t.data2; 00208 data3 = _t.data3; 00209 return *this; 00210 } 00211 inline void set_data1( const SerializableType1& _d ) 00212 { 00213 data1 = _d; 00214 } 00215 inline void set_data2( const SerializableType2& _d ) 00216 { 00217 data2 = _d; 00218 } 00219 inline void set_data3( const SerializableType3& _d ) 00220 { 00221 data3 = _d; 00222 } 00223 inline SerializableType1 get_data1() 00224 { 00225 return data1; 00226 } 00227 inline SerializableType2 get_data2() 00228 { 00229 return data2; 00230 } 00231 inline SerializableType3 get_data3() 00232 { 00233 return data3; 00234 } 00235 inline void print( Debug& debug ) 00236 { 00237 data1.print( debug ); 00238 data2.print( debug ); 00239 data3.print( debug ); 00240 } 00241 private: 00242 SerializableType1 data1; 00243 SerializableType2 data2; 00244 SerializableType3 data3; 00245 }; 00246 00247 template< typename Os_P, 00248 typename Radio_P, 00249 typename SerializableType1_P, 00250 typename SerializableType2_P, 00251 typename SerializableType3_P, 00252 typename SerializableType4_P, 00253 typename Debug_p > 00254 class SerializableSet4_Type 00255 { 00256 public: 00257 typedef Os_P Os; 00258 typedef Radio_P Radio; 00259 typedef SerializableType1_P SerializableType1; 00260 typedef SerializableType2_P SerializableType2; 00261 typedef SerializableType3_P SerializableType3; 00262 typedef SerializableType4_P SerializableType4; 00263 typedef Debug_P Debug; 00264 typedef typename Radio::block_data_t block_data_t; 00265 typedef typename Radio::size_t size_t; 00266 typedef SerializableSet4_Type<Os, Radio, SerializableType1, SerializableType2, SerializableType3, SerializableType4, Debug> self_type; 00267 SerializableSet4_Type() 00268 {} 00269 SerializableSet4_Type( const self_type& _d ) 00270 { 00271 *this = _d; 00272 } 00273 SerializableSet4_Type( block_data_t* buff, size_t offset = 0 ) 00274 { 00275 get_from_buffer( buff, offset ); 00276 } 00277 inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 ) 00278 { 00279 uint8_t DATA1_POS = 0; 00280 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00281 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00282 uint8_t DATA4_POS = DATA3_POS + data3.get_buffer_size(); 00283 data1.set_buffer_from( buff, DATA1_POS + offset ); 00284 data2.set_buffer_from( buff, DATA2_POS + offset ); 00285 data3.set_buffer_from( buff, DATA3_POS + offset ); 00286 data4.set_buffer_from( buff, DATA4_POS + offset ); 00287 return buff; 00288 } 00289 inline void get_from_buffer(block_data_t* buff, size_t offset = 0 ) 00290 { 00291 uint8_t DATA1_POS = 0; 00292 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00293 uint8_t DATA3_POS = DATA3_POS + data2.get_buffer_size(); 00294 uint8_t DATA4_POS = DATA3_POS + data3.get_buffer_size(); 00295 data1.get_from_buffer( buff, DATA1_POS + offset ); 00296 data2.get_from_buffer( buff, DATA2_POS + offset ); 00297 data3.get_from_buffer( buff, DATA3_POS + offset ); 00298 data4.get_from_buffer( buff, DATA4_POS + offset ); 00299 } 00300 inline size_t get_buffer_size() 00301 { 00302 uint8_t DATA1_POS = 0; 00303 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00304 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00305 uint8_t DATA4_POS = DATA3_POS + data3.get_buffer_size(); 00306 return DATA4_POS + data4.get_buffer_size(); 00307 } 00308 inline self_type& operator=( const self_type& _t ) 00309 { 00310 data1 = _t.data1; 00311 data2 = _t.data2; 00312 data3 = _t.data3; 00313 data4 = _t.data4; 00314 return *this; 00315 } 00316 inline void set_data1( const SerializableType1& _d ) 00317 { 00318 data1 = _d; 00319 } 00320 inline void set_data2( const SerializableType2& _d ) 00321 { 00322 data2 = _d; 00323 } 00324 inline void set_data3( const SerializableType3& _d ) 00325 { 00326 data3 = _d; 00327 } 00328 inline void set_data4( const SerializableType4& _d ) 00329 { 00330 data4 = _d; 00331 } 00332 inline SerializableType1 get_data1() 00333 { 00334 return data1; 00335 } 00336 inline SerializableType2 get_data2() 00337 { 00338 return data2; 00339 } 00340 inline SerializableType3 get_data3() 00341 { 00342 return data3; 00343 } 00344 inline SerializableType4 get_data4() 00345 { 00346 return data4; 00347 } 00348 inline void print( Debug& debug ) 00349 { 00350 data1.print( debug ); 00351 data2.print( debug ); 00352 data3.print( debug ); 00353 data4.print( debug ); 00354 } 00355 private: 00356 SerializableType1 data1; 00357 SerializableType2 data2; 00358 SerializableType3 data3; 00359 SerializableType4 data4; 00360 }; 00361 00362 template< typename Os_P, 00363 typename Radio_P, 00364 typename SerializableType1_P, 00365 typename SerializableType2_P, 00366 typename SerializableType3_P, 00367 typename SerializableType4_P, 00368 typename SerializableType5_P, 00369 typename Debug_p > 00370 class SerializableSet5_Type 00371 { 00372 public: 00373 typedef Os_P Os; 00374 typedef Radio_P Radio; 00375 typedef SerializableType1_P SerializableType1; 00376 typedef SerializableType2_P SerializableType2; 00377 typedef SerializableType3_P SerializableType3; 00378 typedef SerializableType4_P SerializableType4; 00379 typedef SerializableType4_P SerializableType5; 00380 typedef Debug_P Debug; 00381 typedef typename Radio::block_data_t block_data_t; 00382 typedef typename Radio::size_t size_t; 00383 typedef SerializableSet5_Type<Os, Radio, SerializableType1, SerializableType2, SerializableType3, SerializableType4, SerializableType5, Debug> self_type; 00384 SerializableSet5_Type() 00385 {} 00386 SerializableSet5_Type( const self_type& _d ) 00387 { 00388 *this = _d; 00389 } 00390 SerializableSet5_Type( block_data_t* buff, size_t offset = 0 ) 00391 { 00392 get_from_buffer( buff, offset ); 00393 } 00394 inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 ) 00395 { 00396 uint8_t DATA1_POS = 0; 00397 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00398 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00399 uint8_t DATA4_POS = DATA3_POS + data3.get_buffer_size(); 00400 uint8_t DATA5_POS = DATA4_POS + data4.get_buffer_size(); 00401 data1.set_buffer_from( buff, DATA1_POS + offset ); 00402 data2.set_buffer_from( buff, DATA2_POS + offset ); 00403 data3.set_buffer_from( buff, DATA3_POS + offset ); 00404 data4.set_buffer_from( buff, DATA4_POS + offset ); 00405 data5.set_buffer_from( buff, DATA5_POS + offset ); 00406 return buff; 00407 } 00408 inline void get_from_buffer(block_data_t* buff, size_t offset = 0 ) 00409 { 00410 uint8_t DATA1_POS = 0; 00411 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00412 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00413 uint8_t DATA4_POS = DATA3_POS + data3.get_buffer_size(); 00414 uint8_t DATA5_POS = DATA4_POS + data4.get_buffer_size(); 00415 data1.get_from_buffer( buff, DATA1_POS + offset ); 00416 data2.get_from_buffer( buff, DATA2_POS + offset ); 00417 data3.get_from_buffer( buff, DATA3_POS + offset ); 00418 data4.get_from_buffer( buff, DATA4_POS + offset ); 00419 data5.get_from_buffer( buff, DATA5_POS + offset ); 00420 } 00421 inline size_t get_buffer_size() 00422 { 00423 uint8_t DATA1_POS = 0; 00424 uint8_t DATA2_POS = DATA1_POS + data1.get_buffer_size(); 00425 uint8_t DATA3_POS = DATA2_POS + data2.get_buffer_size(); 00426 uint8_t DATA4_POS = DATA3_POS + data3.get_buffer_size(); 00427 uint8_t DATA5_POS = DATA4_POS + data4.get_buffer_size(); 00428 return DATA5_POS + data5.get_buffer_size(); 00429 } 00430 inline self_type& operator=( const self_type& _t ) 00431 { 00432 data1 = _t.data1; 00433 data2 = _t.data2; 00434 data3 = _t.data3; 00435 data4 = _t.data4; 00436 data5 = _t.data5; 00437 return *this; 00438 } 00439 inline void set_data1( const SerializableType1& _d ) 00440 { 00441 data1 = _d; 00442 } 00443 inline void set_data2( const SerializableType2& _d ) 00444 { 00445 data2 = _d; 00446 } 00447 inline void set_data3( const SerializableType3& _d ) 00448 { 00449 data3 = _d; 00450 } 00451 inline void set_data4( const SerializableType4& _d ) 00452 { 00453 data4 = _d; 00454 } 00455 inline void set_data5( const SerializableType5& _d ) 00456 { 00457 data5 = _d; 00458 } 00459 inline SerializableType1 get_data1() 00460 { 00461 return data1; 00462 } 00463 inline SerializableType2 get_data2() 00464 { 00465 return data2; 00466 } 00467 inline SerializableType3 get_data3() 00468 { 00469 return data3; 00470 } 00471 inline SerializableType4 get_data4() 00472 { 00473 return data4; 00474 } 00475 inline SerializableType5 get_data5() 00476 { 00477 return data5; 00478 } 00479 inline void print( Debug& debug ) 00480 { 00481 data1.print( debug ); 00482 data2.print( debug ); 00483 data3.print( debug ); 00484 data4.print( debug ); 00485 data5.print( debug ); 00486 } 00487 private: 00488 SerializableType1 data1; 00489 SerializableType2 data2; 00490 SerializableType3 data3; 00491 SerializableType4 data4; 00492 SerializableType5 data5; 00493 }; 00494 } 00495 00496 00497 00498 00499 00500