MED fichier
MEDlogicalOp.hxx
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 EDF R&D, CEA/DEN
4 * MED is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * MED is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with MED. If not, see <http://www.gnu.org/licenses/>.
16 */
17#ifndef MED_LOGICAL_OP_HXX
18#define MED_LOGICAL_OP_HXX
19
20/* Pour tester la présence d'une entité */
21template <typename T> inline int MEDtestBits(const T & int_type, const int offset) {
22 T mask = 1 << offset;
23 return(int_type & mask);
24}
25
26/* Counting bits set, Brian Kernighan's way */
27template <typename T> inline T MEDnSetBits(const T & int_type) {
28
29 /*unsigned*/
30 T v=int_type; // count the number of bits set in v
31 /*unsigned*/
32 T c; // c accumulates the total bits set in v
33 for (c = 0; v; c++)
34 {
35 v &= v - 1; // clear the least significant bit set
36 }
37 return(c);
38}
39
40/* setBit() returns an integer with the bit at 'offset' set to 1. */
41 template <typename T> inline T& MEDsetBits(T& int_type, const int offset) {
42 T mask = 1 << offset;
43 int_type = int_type | mask;
44 return(int_type);
45}
46
47#endif
int MEDtestBits(const T &int_type, const int offset)
T MEDnSetBits(const T &int_type)
T & MEDsetBits(T &int_type, const int offset)