blob: 53d6d7aa74fdcee627f3f3fe184d4c6e9048c602 [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 Lanea2de2192013-11-29 17:58:32 -08003:: type_members = [m for m in ofclass.members if type(m) == OFTypeMember]
Rich Lane002e70c2013-05-09 17:08:16 -07004:: normal_members = [m for m in ofclass.members if type(m) == OFDataMember]
Rich Laned1dd9e62013-02-20 18:28:01 -08005class ${ofclass.pyname}(${superclass}):
Rich Lanea2de2192013-11-29 17:58:32 -08006:: for m in type_members:
Rich Laned1dd9e62013-02-20 18:28:01 -08007 ${m.name} = ${m.value}
8:: #endfor
9
Rich Lane8ca3b772013-04-30 13:36:55 -070010 def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in normal_members])}):
11:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080012 if ${m.name} != None:
13 self.${m.name} = ${m.name}
14 else:
Rich Lane0f7f9d52013-11-29 17:00:49 -080015:: if m.name == 'xid':
16:: # HACK for message xid
17 self.${m.name} = None
18:: else:
Andreas Wundsam69ecfdc2013-09-17 13:50:12 -070019 self.${m.name} = ${py_gen.oftype.gen_init_expr(m.oftype, version=version)}
Rich Lane0f7f9d52013-11-29 17:00:49 -080020:: #endif
Rich Laned1dd9e62013-02-20 18:28:01 -080021:: #endfor
22 return
23
24 def pack(self):
25 packed = []
26:: include("_pack.py", ofclass=ofclass)
27 return ''.join(packed)
28
29 @staticmethod
30 def unpack(buf):
31 obj = ${ofclass.pyname}()
32:: include("_unpack.py", ofclass=ofclass)
33 return obj
34
35 def __eq__(self, other):
36 if type(self) != type(other): return False
Rich Lane8ca3b772013-04-30 13:36:55 -070037:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080038 if self.${m.name} != other.${m.name}: return False
39:: #endfor
40 return True
41
42 def __ne__(self, other):
43 return not self.__eq__(other)
44
45 def show(self):
46 import loxi.pp
47 return loxi.pp.pp(self)
48
49 def pretty_print(self, q):
50:: include('_pretty_print.py', ofclass=ofclass)