‪TYPO3CMS  ‪main
BitSet.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Core\Type;
19 
65 class ‪BitSet
66 {
70  protected ‪$set;
71 
72  public function ‪__construct(int ‪$set = 0)
73  {
74  $this->set = ‪$set;
75  }
76 
81  public function set(int $bitIndex): void
82  {
83  $this->set |= $bitIndex;
84  }
85 
86  public function ‪setValue(int $bitIndex, bool $value): void
87  {
88  if ($value) {
89  $this->set($bitIndex);
90  } else {
91  $this->‪unset($bitIndex);
92  }
93  }
94 
99  public function ‪unset(int $bitIndex): void
100  {
101  $this->set &= ~$bitIndex;
102  }
103 
104  public function get(int $bitIndex): bool
105  {
106  return ($bitIndex & $this->set) === $bitIndex;
107  }
108 
112  public function ‪clear(): void
113  {
114  $this->set = 0;
115  }
116 
122  public function ‪and(BitSet ‪$set): void
123  {
124  $this->set &= $set->__toInt();
125  }
126 
132  public function ‪or(BitSet ‪$set): void
133  {
134  $this->set |= $set->__toInt();
135  }
136 
148  public function ‪xor(BitSet ‪$set): void
149  {
150  $this->set ^= $set->__toInt();
151  }
152 
156  public function ‪andNot(BitSet ‪$set): void
157  {
158  $this->set &= ~$set->__toInt();
159  }
160 
166  public function ‪__toInt(): int
167  {
168  return ‪$this->set;
169  }
170 
174  public function ‪__toString(): string
175  {
176  return '0b' . decbin($this->set);
177  }
178 }
‪TYPO3\CMS\Core\Type\BitSet\setValue
‪setValue(int $bitIndex, bool $value)
Definition: BitSet.php:85
‪TYPO3\CMS\Core\Type\BitSet\__toInt
‪__toInt()
Definition: BitSet.php:165
‪TYPO3\CMS\Core\Type\BitSet\xor
‪xor(BitSet $set)
Definition: BitSet.php:147
‪TYPO3\CMS\Core\Type\BitSet\__construct
‪__construct(int $set=0)
Definition: BitSet.php:71
‪TYPO3\CMS\Core\Type\BitSet\or
‪or(BitSet $set)
Definition: BitSet.php:131
‪TYPO3\CMS\Core\Type\BitSet\unset
‪unset(int $bitIndex)
Definition: BitSet.php:98
‪TYPO3\CMS\Core\Type\BitSet\and
‪and(BitSet $set)
Definition: BitSet.php:121
‪TYPO3\CMS\Core\Type\BitSet
Definition: BitSet.php:66
‪TYPO3\CMS\Core\Type\BitSet\andNot
‪andNot(BitSet $set)
Definition: BitSet.php:155
‪TYPO3\CMS\Core\Type\BitSet\clear
‪clear()
Definition: BitSet.php:111
‪TYPO3\CMS\Core\Type\BitSet\__toString
‪__toString()
Definition: BitSet.php:173
‪TYPO3\CMS\Core\Type\BitSet\$set
‪int $set
Definition: BitSet.php:69
‪TYPO3\CMS\Core\Type