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) {
11 fprintf(stderr, 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 {
32 u32 r31 = 1UL << pos;
33 return data & r31;
34 }
35 bool any() const { return data != 0; }
36 void set(size_t pos, bool val) {
37 u32 r31 = 1UL << pos;
38 if (val) {
39 data |= r31;
40 } else {
41 data &= ~r31;
42 }
43 }
44 void reset(size_t pos) { data &= ~(1UL << pos); }
45private:
46 size_t data;
47};
48
49template<size_t N> __bitset_base<N>::__bitset_base() {
50 std::fill(data, data + N, 0);
51}
52
53template<size_t N> bool __bitset_base<N>::test(size_t pos) const {
54 size_t i = pos / (sizeof(size_t) * 8);
55 size_t mask = 1 << (pos % (sizeof(size_t) * 8));
56 return data[i] & mask;
57}
58
59template<size_t N> void __bitset_base<N>::set(size_t pos, bool val) {
60 size_t i = pos / (sizeof(size_t) * 8);
61 size_t mask = 1 << (pos % (sizeof(size_t) * 8));
62 if (val) {
63 data[i] |= mask;
64 } else {
65 data[i] &= ~mask;
66 }
67}
68
69template<size_t N> void __bitset_base<N>::reset(size_t pos) {
70 size_t i = pos / (sizeof(size_t) * 8);
71 size_t mask = 1 << (pos % (sizeof(size_t) * 8));
72 data[i] &= ~mask;
73}
74
75template<size_t N> bool __bitset_base<N>::any() const {
76 for (int i = 0; i < N; i++) {
77 if (data[i] != 0) {
78 return true;
79 }
80 }
81 return false;
82}
83
84template<size_t N> class bitset : private __bitset_base<(N - 1) / (sizeof(size_t) * 8) + 1> {
85public:
86 typedef __bitset_base<(N - 1) / (sizeof(size_t) * 8) + 1> base;
87
88 bitset() {};
89
90 void set(size_t pos, bool val) {
91 if (pos >= N) {
92 __msl_error("index out of range of bitset::set");
93 }
94 base::set(pos, val);
95 }
96 void reset(size_t pos) {
97 if (pos >= N) {
98 __msl_error("index out of range of bitset::reset");
99 }
100 base::reset(pos);
101 }
102 bool test(size_t pos) const {
103 if (pos >= N) {
104 __msl_error("index out of range of bitset::test");
105 }
106 return base::test(pos);
107 }
108 bool any() const {
109 return base::any();
110 }
111};
112} // namespace std
113
114#endif
DECL_WEAK void abort(void)
Definition __ppc_eabi_init.c:73
bool any() const
Definition bitset.h:35
void set(size_t pos, bool val)
Definition bitset.h:36
bool test(size_t pos) const
Definition bitset.h:31
size_t data
Definition bitset.h:46
__bitset_base()
Definition bitset.h:29
void reset(size_t pos)
Definition bitset.h:44
Definition bitset.h:15
bool test(size_t pos) const
Definition bitset.h:53
void reset(size_t pos)
Definition bitset.h:69
bool any() const
Definition bitset.h:75
__bitset_base()
Definition bitset.h:49
size_t data[N]
Definition bitset.h:24
void set(size_t pos, bool val)
Definition bitset.h:59
Definition bitset.h:84
bool any() const
Definition bitset.h:108
__bitset_base<(N - 1)/(sizeof(size_t) *8)+1 > base
Definition bitset.h:86
bitset()
Definition bitset.h:88
bool test(size_t pos) const
Definition bitset.h:102
void set(size_t pos, bool val)
Definition bitset.h:90
void reset(size_t pos)
Definition bitset.h:96
unsigned long u32
Definition types.h:12
int i
Definition e_pow.c:165
Definition JMATrigonometric.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:124
int fprintf(FILE *stream, const char *format,...)
Definition printf.c:1194
unsigned int size_t
Definition stddef.h:9