Menu

generic_endianess.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2008-2010 Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de>
00004  *                    2010 Marcus Foerster <MarcusFoerster1@gmx.de>
00005  * All rights reserved.
00006  *
00007  *    Redistribution and use in source and binary forms, with or without
00008  *    modification, are permitted provided that the following conditions
00009  *    are met:
00010  *
00011  *    * Redistributions of source code must retain the above copyright
00012  *      notice, this list of conditions and the following disclaimer.
00013  *
00014  *    * Redistributions in binary form must reproduce the above copyright
00015  *      notice, this list of conditions and the following disclaimer in
00016  *      the documentation and/or other materials provided with the
00017  *      distribution.
00018  *
00019  *    * Neither the name of the copyright holders nor the names of
00020  *      contributors may be used to endorse or promote products derived
00021  *      from this software without specific prior written permission.
00022  *
00023  *
00024  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00025  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *
00037  * $Id$
00038  *
00039  ******************************************************************************/
00040 
00041 #ifndef _generic_endianess_
00042 #define _generic_endianess_
00043 
00044 #include <stdint.h>
00045 
00046 #include "util/endianness.h"
00047 
00048 namespace famouso {
00049     namespace util {
00050 
00058         static inline const uint8_t hton(const uint8_t value) {
00059             return (value);
00060         }
00061 
00065         static inline const int8_t hton(const int8_t value) {
00066             return (value);
00067         }
00068 
00072         static inline const uint16_t hton(const uint16_t value) {
00073             return (htons(value));
00074         }
00075 
00079         static inline const int16_t hton(const int16_t value) {
00080             return (htons(value));
00081         }
00082 
00086         static inline const uint32_t hton(const uint32_t value) {
00087             return (htonl(value));
00088         }
00089 
00093         static inline const int32_t hton(const int32_t value) {
00094             return (htonl(value));
00095         }
00096 
00100         static inline const uint64_t hton(const uint64_t value) {
00101             return (htonll(value));
00102         }
00103 
00107         static inline const int64_t hton(const int64_t value) {
00108             return (htonll(value));
00109         }
00110 
00118         static inline const uint8_t ntoh(const uint8_t value) {
00119             return (value);
00120         }
00121 
00125         static inline const int8_t ntoh(const int8_t value) {
00126             return (value);
00127         }
00128 
00132         static inline const uint16_t ntoh(const uint16_t value) {
00133             return (ntohs(value));
00134         }
00135 
00139         static inline const int16_t ntoh(const int16_t value) {
00140             return (ntohs(value));
00141         }
00142 
00146         static inline const uint32_t ntoh(const uint32_t value) {
00147             return (ntohl(value));
00148         }
00149 
00153         static inline const int32_t ntoh(const int32_t value) {
00154             return (ntohl(value));
00155         }
00156 
00160         static inline const uint64_t ntoh(const uint64_t value) {
00161             return (ntohll(value));
00162         }
00163 
00167         static inline const int64_t ntoh(const int64_t value) {
00168             return (ntohll(value));
00169         }
00170 
00171     } // end namespace util
00172 } // end namespace famouso
00173 
00174 #endif // _generic_endianess_