xref: /trunk/main/basebmp/inc/basebmp/endian.hxx (revision 0a1e220dee0308663a065fb3bbe3e59d2252f393)
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 #ifndef INCLUDED_BASEBMP_ENDIAN_HXX
23 #define INCLUDED_BASEBMP_ENDIAN_HXX
24 
25 #include <osl/endian.h>
26 
27 namespace basebmp
28 {
29 
30 // Swap the order of bytes for the given POD type
31 template< typename T > inline T byteSwap( T );
32 
33 #define BASEBMP_BYTE_SWAP(Type,SwapFunc) \
34     template<> inline Type byteSwap<Type>( Type v ) \
35     { \
36         return SwapFunc(v); \
37     }
38 
39 // byteSwap<T> shall fail for any type T not in the list below
40 BASEBMP_BYTE_SWAP(sal_Int8,)
41 BASEBMP_BYTE_SWAP(sal_uInt8,)
42 BASEBMP_BYTE_SWAP(sal_Int16,OSL_SWAPWORD)
43 BASEBMP_BYTE_SWAP(sal_uInt16,OSL_SWAPWORD)
44 BASEBMP_BYTE_SWAP(sal_Int32,OSL_SWAPDWORD)
45 BASEBMP_BYTE_SWAP(sal_uInt32,OSL_SWAPDWORD)
46 
47 #undef BASEBMP_BYTE_SWAP
48 
49 } // namespace basebmp
50 
51 #endif /* INCLUDED_BASEBMP_ENDIAN_HXX */
52 
53 /* vim: set noet sw=4 ts=4: */
54