Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
bitset.h
Go to the documentation of this file.
1#ifndef MSL_BITSET_H_
2#define MSL_BITSET_H_
3
4#include "stdio.h"
5#include "stdlib.h"
6#include "algorithm.h"
7
8namespace std {
9// TODO: where does this go?
10inline void __msl_error(const char* param_0) {
12 abort();
13}
14
15template<size_t N> class __bitset_base {
16public:
18
19 bool test(size_t pos) const;
20 bool any() const;
21 void set(size_t pos, bool val);
22 void reset(size_t pos);
23private:
24 size_t data[N];
25};
26
27template<> class __bitset_base<1> {
28public:
30
31 bool test(size_t pos) const { return data & (1 << pos); }
32 bool any() const;
33 void set(size_t pos, bool val) { data |= (1 << pos); }
34 void reset(size_t pos) { data &= ~(1 << pos); }
35private:
36 size_t data;
37};
38
39template<size_t N> __bitset_base<N>::__bitset_base() {
40 std::fill(data, data + N, 0);
41}
42
43template<size_t N> bool __bitset_base<N>::test(size_t pos) const {
44 size_t i = pos / (sizeof(size_t) * 8);
45 size_t mask = 1 << (pos % (sizeof(size_t) * 8));
46 return data[i] & mask;
47}
48
49template<size_t N> void __bitset_base<N>::set(size_t pos, bool val) {
50 size_t i = pos / (sizeof(size_t) * 8);
51 size_t mask = 1 << (pos % (sizeof(size_t) * 8));
52 if (val) {
53 data[i] |= mask;
54 } else {
55 data[i] &= ~mask;
56 }
57}
58
59template<size_t N> void __bitset_base<N>::reset(size_t pos) {
60 size_t i = pos / (sizeof(size_t) * 8);
61 size_t mask = 1 << (pos % (sizeof(size_t) * 8));
62 data[i] &= ~mask;
63}
64
65template<size_t N> class bitset : private __bitset_base<(N - 1) / (sizeof(size_t) * 8) + 1> {
66public:
67 typedef __bitset_base<(N - 1) / (sizeof(size_t) * 8) + 1> base;
68
69 bitset() {};
70
71 void set(size_t pos, bool val) {
72 if (pos >= N) {
73 __msl_error("index out of range of bitset::set");
74 }
75 base::set(pos, val);
76 }
77 void reset(size_t pos) {
78 if (pos >= N) {
79 __msl_error("index out of range of bitset::reset");
80 }
82 }
83 bool test(size_t pos) const {
84 if (pos >= N) {
85 __msl_error("index out of range of bitset::test");
86 }
87 return base::test(pos);
88 }
89 bool any() const;
90};
91} // namespace std
92
93#endif
void abort(void)
Definition abort_exit.c:23
T cLib_calcTimer(T *value)
Definition c_lib.h:74
void set(size_t pos, bool val)
Definition bitset.h:33
bool test(size_t pos) const
Definition bitset.h:31
size_t data
Definition bitset.h:36
__bitset_base()
Definition bitset.h:29
void reset(size_t pos)
Definition bitset.h:34
Definition bitset.h:15
bool test(size_t pos) const
Definition bitset.h:43
void reset(size_t pos)
Definition bitset.h:59
bool any() const
__bitset_base()
Definition bitset.h:39
size_t data[N]
Definition bitset.h:24
void set(size_t pos, bool val)
Definition bitset.h:49
Definition bitset.h:65
bool any() const
bitset()
Definition bitset.h:69
bool test(size_t pos) const
Definition bitset.h:83
void set(size_t pos, bool val)
Definition bitset.h:71
void reset(size_t pos)
Definition bitset.h:77
static u8 pos[12]
Definition d_a_obj_kago.cpp:839
static u16 data[4]
Definition d_vibration.cpp:114
int i
Definition e_pow.c:165
Definition d_a_e_wb.cpp:12
void __msl_error(const char *param_0)
Definition bitset.h:10
void fill(ForwardIt first, ForwardIt last, const T &value)
Definition algorithm.h:41
int fprintf(FILE *stream, const char *format,...)
Definition printf.c:1205
unsigned int size_t
Definition stddef.h:9