forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubleBitMask.h
More file actions
143 lines (112 loc) · 4.42 KB
/
doubleBitMask.h
File metadata and controls
143 lines (112 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file doubleBitMask.h
* @author drose
* @date 2000-06-08
*/
#ifndef DOUBLEBITMASK_H
#define DOUBLEBITMASK_H
#include "pandabase.h"
#include "bitMask.h"
/**
* This is a special BitMask type that is implemented as a pair of lesser
* BitMask types, to present a double-wide bit mask. For instance, on a
* 32-bit system, this can be used to make a single 64-bit bit mask. More of
* these can be ganged up together to make a 128-bit mask, and so on.
*/
template<class BMType>
class DoubleBitMask {
public:
typedef typename BMType::WordType WordType;
PUBLISHED:
typedef BMType BitMaskType;
enum {
half_bits = BMType::num_bits,
num_bits = BMType::num_bits * 2,
};
constexpr DoubleBitMask() = default;
INLINE static DoubleBitMask<BMType> all_on();
INLINE static DoubleBitMask<BMType> all_off();
INLINE static DoubleBitMask<BMType> lower_on(int on_bits);
INLINE static DoubleBitMask<BMType> bit(int index);
INLINE static DoubleBitMask<BMType> range(int low_bit, int size);
constexpr static bool has_max_num_bits() {return true;}
constexpr static int get_max_num_bits() {return num_bits;}
constexpr int get_num_bits() const;
INLINE bool get_bit(int index) const;
INLINE void set_bit(int index);
INLINE void clear_bit(int index);
INLINE void set_bit_to(int index, bool value);
INLINE bool is_zero() const;
INLINE bool is_all_on() const;
INLINE WordType extract(int low_bit, int size) const;
INLINE void store(WordType value, int low_bit, int size);
INLINE bool has_any_of(int low_bit, int size) const;
INLINE bool has_all_of(int low_bit, int size) const;
INLINE void set_range(int low_bit, int size);
INLINE void clear_range(int low_bit, int size);
INLINE void set_range_to(bool value, int low_bit, int size);
INLINE int get_num_on_bits() const;
INLINE int get_num_off_bits() const;
INLINE int get_lowest_on_bit() const;
INLINE int get_lowest_off_bit() const;
INLINE int get_highest_on_bit() const;
INLINE int get_highest_off_bit() const;
INLINE int get_next_higher_different_bit(int low_bit) const;
INLINE void invert_in_place();
INLINE bool has_bits_in_common(const DoubleBitMask<BMType> &other) const;
INLINE void clear();
void output(std::ostream &out) const;
void output_binary(std::ostream &out, int spaces_every = 4) const;
void output_hex(std::ostream &out, int spaces_every = 4) const;
void write(std::ostream &out, int indent_level = 0) const;
INLINE bool operator == (const DoubleBitMask<BMType> &other) const;
INLINE bool operator != (const DoubleBitMask<BMType> &other) const;
INLINE bool operator < (const DoubleBitMask<BMType> &other) const;
INLINE int compare_to(const DoubleBitMask<BMType> &other) const;
INLINE DoubleBitMask<BMType>
operator & (const DoubleBitMask<BMType> &other) const;
INLINE DoubleBitMask<BMType>
operator | (const DoubleBitMask<BMType> &other) const;
INLINE DoubleBitMask<BMType>
operator ^ (const DoubleBitMask<BMType> &other) const;
INLINE DoubleBitMask<BMType>
operator ~ () const;
INLINE DoubleBitMask<BMType>
operator << (int shift) const;
INLINE DoubleBitMask<BMType>
operator >> (int shift) const;
INLINE void operator &= (const DoubleBitMask<BMType> &other);
INLINE void operator |= (const DoubleBitMask<BMType> &other);
INLINE void operator ^= (const DoubleBitMask<BMType> &other);
INLINE void operator <<= (int shift);
INLINE void operator >>= (int shift);
public:
INLINE void generate_hash(ChecksumHashGenerator &hashgen) const;
private:
BitMaskType _lo, _hi;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
#include "doubleBitMask.I"
template<class BMType>
INLINE std::ostream &operator << (std::ostream &out, const DoubleBitMask<BMType> &doubleBitMask) {
doubleBitMask.output(out);
return out;
}
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, DoubleBitMask<BitMaskNative>);
typedef DoubleBitMask<BitMaskNative> DoubleBitMaskNative;
EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, DoubleBitMask<DoubleBitMaskNative>);
typedef DoubleBitMask<DoubleBitMaskNative> QuadBitMaskNative;
#endif