MyGUI: MyGUI_Bitwise.h Source File

MyGUI 3.2.2

MyGUI_Bitwise.h
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #ifndef MYGUI_BITWISE_H_
8 #define MYGUI_BITWISE_H_
9
10 #include "MyGUI_Prerequest.h"
11
12 namespace MyGUI
13 {
14
15 class Bitwise
16 {
17 public:
20 template<typename Type>
21 static MYGUI_FORCEINLINE Type firstPO2From(Type _value)
22 {
23 --_value;
24 _value |= _value >> 16;
25 _value |= _value >> 8;
26 _value |= _value >> 4;
27 _value |= _value >> 2;
28 _value |= _value >> 1;
29 ++_value;
30 return _value;
31 }
32
34 template<typename Type>
35 static MYGUI_FORCEINLINE bool isPO2(Type _value)
36 {
37 return (_value & (_value - 1)) == 0;
38 }
39
43 template<typename Type>
44 static MYGUI_FORCEINLINE size_t getBitShift(Type _mask)
45 {
46 if (_mask == 0)
47 return 0;
48
49 size_t result = 0;
50 while ((_mask & 1) == 0)
51 {
52 ++result;
53 _mask >>= 1;
54 }
55 return result;
56 }
57 };
58
59 } // namespace MyGUI
60
61 #endif // MYGUI_BITWISE_H_
MyGUI::Bitwise
Definition: MyGUI_Bitwise.h:15
MyGUI::Bitwise::getBitShift
static __inline size_t getBitShift(Type _mask)
Definition: MyGUI_Bitwise.h:44
MyGUI::Bitwise::isPO2
static __inline bool isPO2(Type _value)
Definition: MyGUI_Bitwise.h:35
MyGUI_Prerequest.h
MyGUI::Bitwise::firstPO2From
static __inline Type firstPO2From(Type _value)
Definition: MyGUI_Bitwise.h:21
MYGUI_FORCEINLINE
#define MYGUI_FORCEINLINE
Definition: MyGUI_Platform.h:53
MyGUI
Definition: MyGUI_ActionController.h:14