Branch data Line data Source code
1 : : /* 2 : : ** Copyright (C) 2022 CERN 3 : : ** 4 : : ** This software is provided 'as-is', without any express or implied 5 : : ** warranty. In no event will the authors be held liable for any damages 6 : : ** arising from the use of this software. 7 : : ** 8 : : ** Permission is granted to anyone to use this software for any purpose, 9 : : ** including commercial applications, and to alter it and redistribute it 10 : : ** freely, subject to the following restrictions: 11 : : ** 12 : : ** 1. The origin of this software must not be misrepresented; you must not 13 : : ** claim that you wrote the original software. If you use this software 14 : : ** in a product, an acknowledgment in the product documentation would be 15 : : ** appreciated but is not required. 16 : : ** 2. Altered source versions must be plainly marked as such, and must not be 17 : : ** misrepresented as being the original software. 18 : : ** 3. This notice may not be removed or altered from any source distribution. 19 : : ** 20 : : ** Created on: 2022-09-27T10:04:30 21 : : ** Author: Sylvain Fargier <sylvain.fargier@cern.ch> 22 : : */ 23 : : 24 : : #ifndef BITMASK_HXX__ 25 : : #define BITMASK_HXX__ 26 : : 27 : : #include "BitMask.hpp" 28 : : 29 : : namespace ccut { 30 : : 31 : : template<typename T> 32 : : typename std::enable_if<ccut_enable_bitmask<T>::value, const logger::Logger &>::type 33 : 2 : operator<<(const logger::Logger &logger, 34 : : const ccut::BitMask<T> &mask) 35 : : { 36 : 2 : if (logger.isEnabled()) 37 : : { 38 : 2 : bool first = true; 39 : 2 : logger << "("; 40 : 18 : for (size_t i = 0; i < sizeof(typename ccut::BitMask<T>::underlying_type) * 8; 41 : : ++i) 42 : : { 43 : 16 : typename ccut::BitMask<T>::underlying_type value(1 << i); 44 : 16 : if (mask.bits() & value) 45 : : { 46 : 3 : if (!first) 47 : 1 : logger << "|"; 48 : 3 : logger << static_cast<T>(value); 49 : 3 : first = false; 50 : : } 51 : : } 52 : 2 : logger << ")"; 53 : : } 54 : 2 : return logger; 55 : : } 56 : : 57 : : } 58 : : 59 : : template<typename T> 60 : 3 : typename std::enable_if<ccut_enable_bitmask<T>::value, ccut::BitMask<T>>::type operator|( 61 : : const T &v1, 62 : : const T &v2) 63 : : { 64 : 3 : return ccut::BitMask<T>(v1) | v2; 65 : : } 66 : : 67 : : template<typename T> 68 : 1 : typename std::enable_if<ccut_enable_bitmask<T>::value, ccut::BitMask<T>>::type operator&( 69 : : const T &v1, 70 : : const T &v2) 71 : : { 72 : 1 : return ccut::BitMask<T>(v1) & v2; 73 : : } 74 : : 75 : : #endif