libmongo-client 0.1.4
|
00001 /* libmongo-macros.h - helper macros for libmongo-client. 00002 * Copyright 2011 Gergely Nagy <algernon@balabit.hu> 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef LIBMONGO_MACROS_H 00018 #define LIBMONGO_MACROS_H 1 00019 00020 #include <glib.h> 00021 00022 inline static gdouble 00023 GDOUBLE_SWAP_LE_BE(gdouble in) 00024 { 00025 union 00026 { 00027 guint64 i; 00028 gdouble d; 00029 } u; 00030 00031 u.d = in; 00032 u.i = GUINT64_SWAP_LE_BE (u.i); 00033 return u.d; 00034 } 00035 00036 #if G_BYTE_ORDER == G_LITTLE_ENDIAN 00037 #define GDOUBLE_TO_LE(val) ((gdouble) (val)) 00038 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val)) 00039 00040 #elif G_BYTE_ORDER == G_BIG_ENDIAN 00041 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val)) 00042 #define GDOUBLE_TO_BE(val) ((gdouble) (val)) 00043 00044 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */ 00045 #error unknown ENDIAN type 00046 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */ 00047 00048 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val)) 00049 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val)) 00050 00051 #endif