lo_endian-msvc.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004 Steve Harris
00003  *
00004  *  This program is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Lesser General Public License
00006  *  as published by the Free Software Foundation; either version 2.1
00007  *  of the License, or (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  $Id$
00015  */
00016 
00017 #ifndef LO_ENDIAN_H
00018 #define LO_ENDIAN_H
00019 
00020 #include <sys/types.h>
00021 
00022 #ifdef _MSC_VER
00023 #define inline __inline
00024 #define uint64_t unsigned __int64
00025 #define uint32_t unsigned __int32
00026 #else
00027 #include <stdint.h>
00028 #endif
00029 
00030 #ifdef WIN32
00031 #include <winsock2.h>
00032 #include <ws2tcpip.h>
00033 #else
00034 #include <netinet/in.h>
00035 #endif
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 #define lo_swap16(x) htons(x)
00042 
00043 #define lo_swap32(x) htonl(x)
00044 
00045 /* These macros come from the Linux kernel */
00046 
00047 #ifndef lo_swap16
00048 #define lo_swap16(x) \
00049 ({ \
00050     uint16_t __x = (x); \
00051     ((uint16_t)( \
00052     (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
00053     (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
00054 })
00055 #warning USING UNOPTIMISED ENDIAN STUFF
00056 #endif
00057 
00058 #ifndef lo_swap32
00059 #define lo_swap32(x) \
00060 ({ \
00061     uint32_t __x = (x); \
00062     ((uint32_t)( \
00063     (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
00064     (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) <<  8) | \
00065     (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >>  8) | \
00066     (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
00067 })
00068 #endif
00069 
00070 #if 0
00071 #ifndef lo_swap64
00072 #define lo_swap64(x) \
00073 ({ \
00074     uint64_t __x = (x); \
00075     ((uint64_t)( \
00076     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
00077     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
00078     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
00079     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) <<  8) | \
00080     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >>  8) | \
00081     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
00082     (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
00083     (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
00084 })
00085 #endif
00086 #else
00087 
00088 typedef union {
00089     uint64_t all;
00090     struct {
00091     uint32_t a;
00092     uint32_t b;
00093     } part;
00094 } lo_split64;
00095 
00096 static inline uint64_t lo_swap64(uint64_t x)
00097 {
00098     lo_split64 in, out;
00099 
00100     in.all = x;
00101     out.part.a = lo_swap32(in.part.b);
00102     out.part.b = lo_swap32(in.part.a);
00103 
00104     return out.all;
00105 }
00106 #endif
00107 
00108 /* Host to OSC and OSC to Host conversion macros */
00109 
00110 #if 0
00111 #define lo_htoo16(x) (x)
00112 #define lo_htoo32(x) (x)
00113 #define lo_htoo64(x) (x)
00114 #define lo_otoh16(x) (x)
00115 #define lo_otoh32(x) (x)
00116 #define lo_otoh64(x) (x)
00117 #else
00118 #define lo_htoo16 lo_swap16
00119 #define lo_htoo32 lo_swap32
00120 #define lo_htoo64 lo_swap64
00121 #define lo_otoh16 lo_swap16
00122 #define lo_otoh32 lo_swap32
00123 #define lo_otoh64 lo_swap64
00124 #endif
00125 
00126 #ifdef __cplusplus
00127 }
00128 #endif
00129 
00130 #ifdef _MSC_VER
00131 #undef inline
00132 #undef uint64_t
00133 #undef uint32_t
00134 #endif
00135 
00136 #endif
00137 
00138 /* vi:set ts=8 sts=4 sw=4: */

Generated on Sat Oct 17 14:12:32 2009 for CSL by  doxygen 1.4.5-20051010