MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_BITWISE_H__ 00023 #define __MYGUI_BITWISE_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 00027 namespace MyGUI 00028 { 00029 00030 class Bitwise 00031 { 00032 public: 00035 template<typename Type> 00036 static MYGUI_FORCEINLINE Type firstPO2From(Type _value) 00037 { 00038 --_value; 00039 _value |= _value >> 16; 00040 _value |= _value >> 8; 00041 _value |= _value >> 4; 00042 _value |= _value >> 2; 00043 _value |= _value >> 1; 00044 ++_value; 00045 return _value; 00046 } 00047 00049 template<typename Type> 00050 static MYGUI_FORCEINLINE bool isPO2(Type _value) 00051 { 00052 return (_value & (_value - 1)) == 0; 00053 } 00054 00058 template<typename Type> 00059 static MYGUI_FORCEINLINE size_t getBitShift(Type _mask) 00060 { 00061 if (_mask == 0) 00062 return 0; 00063 00064 size_t result = 0; 00065 while ((_mask & 1) == 0) 00066 { 00067 ++result; 00068 _mask >>= 1; 00069 } 00070 return result; 00071 } 00072 }; 00073 00074 } // namespace MyGUI 00075 00076 #endif // __MYGUI_BITWISE_H__