This repository was archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMask.php
90 lines (80 loc) · 1.67 KB
/
Mask.php
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
<?php namespace nyx\core;
/**
* Mask
*
* Base class for concrete fields/objects utilizing bitmasks (permissions, statuses etc.). This could also be used
* as a generic mask builder.
*
* @package Nyx\Core
* @version 0.1.0
* @author Michal Chojnacki <[email protected]>
* @copyright 2012-2016 Nyx Dev Team
* @link http://docs.muyo.io/nyx/core/index.html
*/
class Mask
{
/**
* @var int The current bitmask.
*/
private $mask;
/**
* Constructs a new Mask instance.
*
* @param int $mask The bitmask to start with.
*/
public function __construct(int $mask = 0)
{
$this->mask = $mask;
}
/**
* Returns the current bitmask.
*
* @return int
*/
public function get() : int
{
return $this->mask;
}
/**
* Checks if the given bits are set in the mask.
*
* @param int $mask
* @return bool
*/
public function is(int $mask) : bool
{
return ($this->mask & $mask) === $mask;
}
/**
* Sets the given bits in the mask.
*
* @param int $mask
* @return $this
*/
public function set(int $mask) : self
{
$this->mask |= $mask;
return $this;
}
/**
* Removes the given bits from the mask.
*
* @param int $mask
* @return $this
*/
public function remove(int $mask) : self
{
$this->mask &= ~$mask;
return $this;
}
/**
* Resets the mask to a state with no bits set.
*
* @return $this
*/
public function reset() : self
{
$this->mask = 0;
return $this;
}
}