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