summaryrefslogtreecommitdiffstats
path: root/src/BitFlagg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/BitFlagg.cpp')
-rw-r--r--src/BitFlagg.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/BitFlagg.cpp b/src/BitFlagg.cpp
new file mode 100644
index 0000000..48cf990
--- a/dev/null
+++ b/src/BitFlagg.cpp
@@ -0,0 +1,55 @@
+#include "BitFlagg.h"
+#include "Constants.h"
+BitFlagg::BitFlagg (int number_of_bits)
+{
+ Flagg = new char[max = number_of_bits / 8 + 1];
+}
+
+BitFlagg::BitFlagg ()
+{
+ Flagg = new char[max = 1];
+}
+
+BitFlagg::~BitFlagg ()
+{
+ delete Flagg;
+}
+
+void BitFlagg::Store (int offset, int TorF)
+{
+ int offset_byte, c;
+ char offset_bit;
+ int temp;
+
+ if ((offset_byte = offset / 8) < (max + 1)) {
+ offset_bit = offset % 8;
+ if (TorF == TRUE) {
+ temp = 0x01;
+ temp <<= offset_bit;
+ Flagg[offset_byte] |= temp;
+ } else {
+ temp = 0xFE;
+ for (c = 0; c < offset_bit; c++) {
+ temp <<= 1;
+ temp |= 0x01;
+ }
+ Flagg[offset_byte] &= temp;
+ }
+ }
+}
+
+int BitFlagg::Get (int offset)
+{
+ int offset_byte;
+ char offset_bit, temp;
+
+ offset_byte = offset / 8;
+ offset_bit = offset % 8;
+ temp = 0x01;
+ temp <<= offset_bit;
+ temp &= Flagg[offset_byte];
+ if (temp)
+ return TRUE;
+ else
+ return FALSE;
+}