Wiselib
wiselib.stable/util/serialization/endian.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_ENDIAN_H
00020 #define __WISELIB_UTIL_SERIALIZATION_ENDIAN_H
00021 
00022 #if defined(__APPLE__) || defined(__ba__) || defined(__arm__)
00023 #include <machine/endian.h>
00024 #elif defined(__MSP430__)
00025 #include <sys/ieeefp.h>
00026 #elif defined(__AVR__)
00027 // no include available
00028 #else
00029 #include <endian.h>
00030 #endif
00031 
00032 namespace wiselib
00033 {
00034 
00035    enum Endianness
00036    {
00037       WISELIB_LITTLE_ENDIAN,
00038       WISELIB_BIG_ENDIAN
00039    };
00040 
00041 #if (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) || \
00042       (defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN) || \
00043       (defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN) || \
00044       (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __BIG_ENDIAN__) || \
00045       defined(__IEEE_BIG_ENDIAN)
00046    const Endianness WISELIB_ENDIANNESS = WISELIB_BIG_ENDIAN;
00047 #elif (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
00048          (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) || \
00049          (defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN) || \
00050          (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __LITTLE_ENDIAN__) || \
00051          defined(__IEEE_LITTLE_ENDIAN) || \
00052          defined(__AVR__)
00053    const Endianness WISELIB_ENDIANNESS = WISELIB_LITTLE_ENDIAN;
00054 #else
00055   #error "Endian determination failed"
00056 #endif
00057 
00058 }
00059 
00060 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines