Release of synfigstudio 0.61.09 version. *****
[synfig.git] / ETL / tags / stable / ETL / _bit_rotate.h
1 /*! ========================================================================
2 ** Extended Template Library
3 ** Bit Rotation Implementation
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
12 **
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 ** General Public License for more details.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
22 **
23 ** These template functions have not yet been throughly tested,
24 ** and may be inaccurate or just plain wrong. You have been warned.
25 **
26 ** ========================================================================= */
27
28 /* === S T A R T =========================================================== */
29
30 #ifndef __ETL_BIT_ROTATE_H
31 #define __ETL_BIT_ROTATE_H
32
33 /* === H E A D E R S ======================================================= */
34
35 /* === M A C R O S ========================================================= */
36
37 /* === T Y P E D E F S ===================================================== */
38
39 /* === C L A S S E S & S T R U C T S ======================================= */
40
41 _ETL_BEGIN_NAMESPACE
42
43 template <typename T> T
44 rot_left(const T &val, const int &bits=1)
45 {
46         return (T)( ((unsigned)val<<bits)+((unsigned)val>>(sizeof(T)*8-bits)) );
47 }
48
49 template <typename T> T
50 rot_right(const T &val, const int &bits=1)
51 {
52         return (T)( ((unsigned)val>>bits)+((unsigned)val<<(sizeof(T)*8-bits)) );
53 }
54
55 _ETL_END_NAMESPACE
56
57 /* === E X T E R N S ======================================================= */
58
59 /* === E N D =============================================================== */
60
61 #endif
62