From f61e396038188da8be6cee24392a230e2791e2b9 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sat, 2 Mar 2013 14:44:13 +0100 Subject: moved common functions in util.h --- inputdev.cc | 17 +---------------- util.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 util.h diff --git a/inputdev.cc b/inputdev.cc index d87a72f..b7c9399 100644 --- a/inputdev.cc +++ b/inputdev.cc @@ -28,22 +28,7 @@ #include - -#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a)[0]) -inline static bool test_bit(unsigned int bit, unsigned long const mask[]) -{ - unsigned long m = mask[bit / (sizeof mask[0] * 8)]; - unsigned int i = bit % (sizeof mask[0] * 8); - - return (m & (1u << i)) != 0u; -} - -inline static void set_bit(unsigned int bit, unsigned long mask[]) -{ - unsigned int i = bit % (sizeof mask[0] * 8); - - mask[bit / (sizeof mask[0] * 8)] |= (1u << i); -} +#include "util.h" class MagicState { private: diff --git a/util.h b/util.h new file mode 100644 index 0000000..d51e022 --- /dev/null +++ b/util.h @@ -0,0 +1,52 @@ +/* --*- c -*-- + * Copyright (C) 2013 Enrico Scholz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 and/or 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef HH_ENSC_VDR_INPUTDEV_UTIL_HH +#define HH_ENSC_VDR_INPUTDEV_UTIL_HH + +#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a)[0]) + +inline static bool test_bit(unsigned int bit, unsigned long const mask[]) +{ + unsigned long m = mask[bit / (sizeof mask[0] * 8)]; + unsigned int i = bit % (sizeof mask[0] * 8); + + return (m & (1u << i)) != 0u; +} + +inline static void set_bit(unsigned int bit, unsigned long mask[]) +{ + unsigned int i = bit % (sizeof mask[0] * 8); + + mask[bit / (sizeof mask[0] * 8)] |= (1u << i); +} + +inline static void clear_bit(unsigned int bit, unsigned long mask[]) +{ + unsigned int i = bit % (sizeof mask[0] * 8); + + mask[bit / (sizeof mask[0] * 8)] &= ~(1u << i); +} + +inline static void change_bit(unsigned int bit, unsigned long mask[]) +{ + if (test_bit(bit, mask)) + clear_bit(bit, mask); + else + set_bit(bit, mask); +} + +#endif /* HH_ENSC_VDR_INPUTDEV_UTIL_HH */ -- cgit v1.2.3