-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop_or.py
More file actions
37 lines (31 loc) · 1.19 KB
/
op_or.py
File metadata and controls
37 lines (31 loc) · 1.19 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
# AND CLASS
# Stores a collection of operands all to be AND'd together.
from op import *
class op_or(op):
# Init function - Stores data pertaining to the class
def __init__(self, *argv):
super(op_or, self).__init__(*argv)
# Returns the type of this operator
def getType(self):
return "or"
# Calculates the value of this operator given a dictionary of variable values
def calcValue(self, args):
output = 0
for operand in self.getOperands():
output = output | operand.calcValue(args)
return output
# Used to see if 2 AND statements are the same. Ignores operand order
def __eq__(self, other):
if other == None: return False
if other.getType() != "or": return False
if len(self.getOperands()) != len(other.getOperands()): return False
copy = self.getOperands()[:]
for var in other.getOperands():
try:
del copy[copy.index(var)]
except ValueError:
return False
return len(copy) == 0
# Used to print this class out nicely
def __str__(self):
return "[OR: {}]".format(", ".join([str(x) for x in self.getOperands()]))