‪TYPO3CMS  10.4
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 
61 class ‪BitSet
62 {
66  private ‪$set;
67 
71  public function ‪__construct(int ‪$set = 0)
72  {
73  $this->set = ‪$set;
74  }
75 
82  public function set(int $bitIndex): void
83  {
84  $this->set |= $bitIndex;
85  }
86 
91  public function ‪setValue(int $bitIndex, bool $value): void
92  {
93  if ($value) {
94  $this->set($bitIndex);
95  } else {
96  $this->‪unset($bitIndex);
97  }
98  }
99 
106  public function ‪unset(int $bitIndex): void
107  {
108  $this->set &= ~$bitIndex;
109  }
110 
115  public function get(int $bitIndex): bool
116  {
117  return ($bitIndex & $this->set) === $bitIndex;
118  }
119 
123  public function ‪clear(): void
124  {
125  $this->set = 0;
126  }
127 
135  public function ‪and(‪BitSet ‪$set): void
136  {
137  $this->set &= $set->‪__toInt();
138  }
139 
147  public function ‪or(‪BitSet ‪$set): void
148  {
149  $this->set |= $set->‪__toInt();
150  }
151 
163  public function ‪xor(‪BitSet ‪$set): void
164  {
165  $this->set ^= $set->‪__toInt();
166  }
167 
173  public function ‪andNot(‪BitSet ‪$set): void
174  {
175  $this->set &= ~$set->‪__toInt();
176  }
177 
185  public function ‪__toInt(): int
186  {
187  return ‪$this->set;
188  }
189 
195  public function ‪__toString(): string
196  {
197  return '0b' . decbin($this->set);
198  }
199 }
‪TYPO3\CMS\Core\Type\BitSet\setValue
‪setValue(int $bitIndex, bool $value)
Definition: BitSet.php:90
‪TYPO3\CMS\Core\Type\BitSet\__toString
‪string __toString()
Definition: BitSet.php:194
‪TYPO3\CMS\Core\Type\BitSet\xor
‪xor(BitSet $set)
Definition: BitSet.php:162
‪TYPO3\CMS\Core\Type\BitSet\__construct
‪__construct(int $set=0)
Definition: BitSet.php:70
‪TYPO3\CMS\Core\Type\BitSet\or
‪or(BitSet $set)
Definition: BitSet.php:146
‪TYPO3\CMS\Core\Type\BitSet\unset
‪unset(int $bitIndex)
Definition: BitSet.php:105
‪TYPO3\CMS\Core\Type\BitSet\and
‪and(BitSet $set)
Definition: BitSet.php:134
‪TYPO3\CMS\Core\Type\BitSet
Definition: BitSet.php:62
‪TYPO3\CMS\Core\Type\BitSet\andNot
‪andNot(BitSet $set)
Definition: BitSet.php:172
‪TYPO3\CMS\Core\Type\BitSet\clear
‪clear()
Definition: BitSet.php:122
‪TYPO3\CMS\Core\Type\BitSet\__toInt
‪int __toInt()
Definition: BitSet.php:184
‪TYPO3\CMS\Core\Type\BitSet\$set
‪int $set
Definition: BitSet.php:65
‪TYPO3\CMS\Core\Type