summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inputdev.cc17
-rw-r--r--util.h52
2 files changed, 53 insertions, 16 deletions
diff --git a/inputdev.cc b/inputdev.cc
index d87a72f..b7c9399 100644
--- a/inputdev.cc
+++ b/inputdev.cc
@@ -28,22 +28,7 @@
#include <vdr/plugin.h>
-
-#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 <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#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 */