-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboolean.class.php
More file actions
62 lines (51 loc) · 1.36 KB
/
boolean.class.php
File metadata and controls
62 lines (51 loc) · 1.36 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
<?php
require_once 'variable.class.php';
/*
* boolean variable - same as variable except it may be negated
*/
class Boolean {
// actual variable we contain (e.g. x0, y1, etc.)
public $var;
// negated or not
public $negated;
/*
* constructor - variable and negation
*/
public function __construct($var, $negated = false) {
$this->var = $var;
$this->negated = $negated;
}
/*
* returns the negated version of the variable
*/
public function negate() {
return new Boolean($this->var, !$this->negated);
}
/*
* returns the variable as a string
*/
public function toString() {
return $this->var->toString() . ($this->negated ? "'" : '');
}
/*
* make a copy of the boolean variable
*/
public function copy() {
return new Boolean($this->var->copy(), $this->negated);
}
/*
* checks if the variable equals another variable
*/
public function equals($var) {
if (!is_object($var) || !is_a($var, 'Boolean')) return false;
if ($this->var->equals($var->var) && $this->negated == $var->negated) return true;
else return false;
}
/*
* checks if the variable equals another variable as negated form
*/
public function equalsNegated($var) {
if ($this->var->equals($var->var) && $this->negated == !$var->negated) return true;
else return false;
}
}