1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 #ifndef _VOS_MACROS_HXX_ 26 #define _VOS_MACROS_HXX_ 27 28 29 #include <osl/endian.h> 30 31 // ********************************************************************* 32 // Macro definitions 33 34 #ifndef VOS_CAST 35 # define VOS_CAST(type,value) (*((type*)&(value))) 36 #endif 37 38 #ifndef VOS_UNUSED 39 # define VOS_UNUSED(x) (x=x) 40 #endif 41 42 #ifndef VOS_FOREVER 43 # define VOS_FOREVER for(;;) 44 #endif 45 46 #ifndef VOS_MAX 47 # define VOS_MAX(a,b) (((a) > (b)) ? (a) : (b)) 48 #endif 49 #ifndef VOS_MIN 50 # define VOS_MIN(a,b) (((a) < (b)) ? (a) : (b)) 51 #endif 52 53 #ifndef VOS_ABS 54 # define VOS_ABS(a) (((a) < 0) ? (-(a)) : (a)) 55 #endif 56 #ifndef VOS_SIGN 57 # define VOS_SIGN(a) ( ((a) < 0) ? (-1) : (((a) > 0) ? (1) : (0)) ) 58 #endif 59 60 #ifndef VOS_BOUND 61 # define VOS_BOUND(x,l,h) ((x) <= (l) ? (l) : ((x) >= (h) ? (h) : (x))) 62 #endif 63 64 #ifndef VOS_SWAP 65 # define VOS_SWAP(a,b) ((a) ^= (b) ^= (a) ^= (b)) 66 #endif 67 68 #ifndef VOS_BYTEBOUND 69 # define VOS_BYTEBOUND(a) (((a) + 7) / 8) 70 #endif 71 72 #ifndef VOS_WORDBOUND 73 # define VOS_WORDBOUND(a) ((((a) + 15) / 16) * 2) 74 #endif 75 76 #ifndef VOS_DWORDBOUND 77 # define VOS_DWORDBOUND(a) ((((a) + 31) / 32) * 4) 78 #endif 79 80 #ifndef VOS_MAKEDWORD 81 # define VOS_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16)) 82 #endif 83 #ifndef VOS_LOWORD 84 # define VOS_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF)) 85 #endif 86 #ifndef VOS_HIWORD 87 # define VOS_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF)) 88 #endif 89 #ifndef VOS_MAKEWORD 90 # define VOS_MAKEWORD(bl, bh) ((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8)) 91 #endif 92 #ifndef VOS_LOBYTE 93 # define VOS_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF)) 94 #endif 95 #ifndef VOS_HIBYTE 96 # define VOS_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF)) 97 #endif 98 #ifndef VOS_MAKEBYTE 99 # define VOS_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4))) 100 #endif 101 #ifndef VOS_LONIBBLE 102 # define VOS_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F)) 103 #endif 104 #ifndef VOS_HINIBBLE 105 # define VOS_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F)) 106 #endif 107 108 #ifndef VOS_SWAPWORD 109 # define VOS_SWAPWORD(w) VOS_MAKEWORD(VOS_HIBYTE(w),VOS_LOBYTE(w)) 110 #endif 111 #ifndef VOS_SWAPDWORD 112 # define VOS_SWAPDWORD(d) VOS_MAKEDWORD(VOS_SWAPWORD(VOS_HIWORD(d)),VOS_SWAPWORD(VOS_LOWORD(d))) 113 #endif 114 115 #ifdef OSL_BIGENDIAN 116 #ifndef VOS_NETWORD 117 # define VOS_NETWORD(w) (sal_uInt16)(w) 118 #endif 119 #ifndef VOS_NETDWORD 120 # define VOS_NETDWORD(d) (sal_uInt32)(d) 121 #endif 122 #else // OSL_LITENDIAN 123 #ifndef VOS_NETWORD 124 # define VOS_NETWORD(w) VOS_MAKEWORD(VOS_HIBYTE(w),VOS_LOBYTE(w)) 125 #endif 126 #ifndef VOS_NETDWORD 127 # define VOS_NETDWORD(d) VOS_MAKEDWORD(VOS_NETWORD(VOS_HIWORD(d)),VOS_NETWORD(VOS_LOWORD(d))) 128 #endif 129 #endif // OSL_BIGENDIAN 130 131 #ifdef _OSL_MEMSEG 132 # define VOS_MAKEPTR(base, off) ((void _far *)VOS_MAKEDWORD((off), (base))) 133 # define VOS_BASEOF(ptr) VOS_HIWORD(ptr) 134 # define VOS_OFSTOF(ptr) VOS_LOWORD(ptr) 135 #else 136 # define VOS_MAKEPTR(base, off) ((void *)((base) + (off))) 137 # define VOS_BASEOF(ptr) (ptr) 138 # define VOS_OFSTOF(ptr) 0 139 #endif 140 141 #ifndef VOS_FIELDOFFSET 142 # define VOS_FIELDOFFSET(type, field) ((sal_Int32)(&((type *)1)->field) - 1) 143 #endif 144 145 // def. for arbitrary namespace 146 #define VOS_NAMESPACE(class_name, name_space) name_space::class_name 147 148 // sal_Int16 def. for namespace std 149 #define NAMESPACE_STD(class_name) std::class_name 150 151 #endif //_VOS_MACROS_HXX_ 152 153