Wiselib
wiselib.stable/util/serialization/pstl_pair.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 __WISELIB_UTIL_SERIALIZATION_PSTL_PAIR_H
00020 #define __WISELIB_UTIL_SERIALIZATION_PSTL_PAIR_H
00021 
00022 #include "util/serialization/serialization.h"
00023 #include "util/serialization/simple_types.h"
00024 #include "util/serialization/endian.h"
00025 #include "util/pstl/pair.h"
00026 
00027 namespace wiselib
00028 {
00029 
00030    template<typename OsModel_P,
00031             typename BlockData_P,
00032             typename A,
00033             typename B>
00034    struct Serialization<OsModel_P, WISELIB_BIG_ENDIAN, BlockData_P, pair<A, B> >
00035    {
00036       typedef OsModel_P OsModel;
00037       typedef BlockData_P BlockData;
00038       typedef pair<A, B> Type;
00039       typedef typename Type::first_type First;
00040       typedef typename Type::second_type Second;
00041 
00042       typedef typename OsModel::size_t size_t;
00043       // --------------------------------------------------------------------
00044       static inline Type read( BlockData *target )
00045       {
00046          Type x;
00047          read( target, x );
00048          return x;
00049       }
00050       // --------------------------------------------------------------------
00051       static inline void read( BlockData *target, Type& value )
00052       {
00053          value.first = Serialization<OsModel, WISELIB_BIG_ENDIAN, BlockData, First>::read( target );
00054          value.second = Serialization<OsModel, WISELIB_BIG_ENDIAN, BlockData, Second>::read( target + sizeof(A) );
00055       }
00056       // --------------------------------------------------------------------
00057       static inline size_t write( BlockData *target, Type& value )
00058       {
00059          size_t bytes_a = Serialization<OsModel, WISELIB_BIG_ENDIAN, BlockData, First>::write( target, value.first );
00060          size_t bytes_b = Serialization<OsModel, WISELIB_BIG_ENDIAN, BlockData, Second>::write( target + bytes_a, value.second );
00061          return bytes_a + bytes_b;
00062       }
00063    };
00064    // -----------------------------------------------------------------------
00065    // -----------------------------------------------------------------------
00066    // -----------------------------------------------------------------------
00067    template<typename OsModel_P,
00068             typename BlockData_P,
00069             typename A,
00070             typename B>
00071    struct Serialization<OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, pair<A, B> >
00072    {
00073       typedef OsModel_P OsModel;
00074       typedef BlockData_P BlockData;
00075       typedef pair<A, B> Type;
00076       typedef typename Type::first_type First;
00077       typedef typename Type::second_type Second;
00078 
00079       typedef typename OsModel::size_t size_t;
00080       // --------------------------------------------------------------------
00081       static inline Type read( BlockData *target )
00082       {
00083          Type x;
00084          read( target, x );
00085          return x;
00086       }
00087       // --------------------------------------------------------------------
00088       static inline void read( BlockData *target, Type& value )
00089       {
00090          value.first = Serialization<OsModel, WISELIB_LITTLE_ENDIAN, BlockData, First>::read( target );
00091          value.second = Serialization<OsModel, WISELIB_LITTLE_ENDIAN, BlockData, Second>::read( target + sizeof(A) );
00092       }
00093       // --------------------------------------------------------------------
00094       static inline size_t write( BlockData *target, Type& value )
00095       {
00096          size_t bytes_a = Serialization<OsModel, WISELIB_LITTLE_ENDIAN, BlockData, First>::write( target, value.first );
00097          size_t bytes_b = Serialization<OsModel, WISELIB_LITTLE_ENDIAN, BlockData, Second>::write( target + bytes_a, value.second );
00098          return bytes_a + bytes_b;
00099       }
00100    };
00101 
00102 }
00103 
00104 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines