forked from DeepDiver1975/PHPZipStreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCount64_64.php
More file actions
83 lines (75 loc) · 2.63 KB
/
Count64_64.php
File metadata and controls
83 lines (75 loc) · 2.63 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
<?php
/**
* Simple class to support some very basic operations on 64 bit intergers
* on 32 bit machines.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Nicolai Ehemann <en@enlightened.de>
* @copyright Copyright (C) 2013-2014 Nicolai Ehemann and contributors
* @license GNU GPL
*/
namespace ZipStreamer\Lib;
use const \ZipStreamer\INT64_LOW_MAP;
use const \ZipStreamer\INT_MAX_32;
class Count64_64 extends Count64Base {
private $value;
public function getHiBytes() {
return urShift($this->value, 32);
}
public function getLoBytes() {
return $this->value & INT64_LOW_MAP;
}
public function _getValue() {
return $this->value;
}
public function set($value) {
if (is_int($value)) {
if ($this->limit32Bit && INT_MAX_32 < $value) {
throw new \OverFlowException(self::EXCEPTION_32BIT_OVERFLOW);
}
$this->value = $value;
} else if (is_array($value) && 2 == sizeof($value)) {
if ($this->limit32Bit && 0 !== $value[1]) {
throw new \OverFlowException(self::EXCEPTION_32BIT_OVERFLOW);
}
$this->value = $value[1];
$this->value = $this->value << 32;
$this->value = $this->value + $value[0];
} else if (is_object($value) && __CLASS__ == get_class($value)) {
$value = $value->_getValue();
if ($this->limit32Bit && INT_MAX_32 < $value) {
throw new \OverFlowException(self::EXCEPTION_32BIT_OVERFLOW);
}
$this->value = $value;
} else {
throw new \InvalidArgumentException(self::EXCEPTION_SET_INVALID_ARGUMENT);
}
return $this;
}
public function add($value) {
if (is_int($value)) {
$sum = (int) ($this->value + $value);
} else if (is_object($value) && __CLASS__ == get_class($value)) {
$sum = (int) ($this->value + $value->_getValue());
} else {
throw new \InvalidArgumentException(self::EXCEPTION_ADD_INVALID_ARGUMENT);
}
if ($this->limit32Bit && INT_MAX_32 < $sum) {
throw new \OverFlowException(self::EXCEPTION_32BIT_OVERFLOW);
}
$this->value = $sum;
return $this;
}
}