blob: 695cce6de531d74fb17097f1c3ef886d8e671441 [file] [log] [blame]
Rich Lane002e70c2013-05-09 17:08:16 -07001:: from loxi_ir import *
Rich Laneda11f8b2013-06-19 15:53:25 -07002:: import py_gen.oftype
Rich Lane002e70c2013-05-09 17:08:16 -07003:: normal_members = [m for m in ofclass.members if type(m) == OFDataMember]
Rich Laned1dd9e62013-02-20 18:28:01 -08004class ${ofclass.pyname}(${superclass}):
5:: for m in ofclass.type_members:
6 ${m.name} = ${m.value}
7:: #endfor
8
Rich Lane8ca3b772013-04-30 13:36:55 -07009 def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in normal_members])}):
10:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080011 if ${m.name} != None:
12 self.${m.name} = ${m.name}
13 else:
Andreas Wundsam69ecfdc2013-09-17 13:50:12 -070014 self.${m.name} = ${py_gen.oftype.gen_init_expr(m.oftype, version=version)}
Rich Laned1dd9e62013-02-20 18:28:01 -080015:: #endfor
16 return
17
18 def pack(self):
19 packed = []
20:: include("_pack.py", ofclass=ofclass)
21 return ''.join(packed)
22
23 @staticmethod
24 def unpack(buf):
25 obj = ${ofclass.pyname}()
26:: include("_unpack.py", ofclass=ofclass)
27 return obj
28
29 def __eq__(self, other):
30 if type(self) != type(other): return False
Rich Lane8ca3b772013-04-30 13:36:55 -070031:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080032 if self.${m.name} != other.${m.name}: return False
33:: #endfor
34 return True
35
36 def __ne__(self, other):
37 return not self.__eq__(other)
38
39 def show(self):
40 import loxi.pp
41 return loxi.pp.pp(self)
42
43 def pretty_print(self, q):
44:: include('_pretty_print.py', ofclass=ofclass)