blob: f902ae877f994a687e2de3ea7ca9bfb73725b650 [file] [log] [blame]
Rich Lane9d98adf2013-11-29 18:37:24 -08001:: superclass_pyname = ofclass.superclass.pyname if ofclass.superclass else "loxi.OFObject"
Rich Lane002e70c2013-05-09 17:08:16 -07002:: from loxi_ir import *
Rich Laneda11f8b2013-06-19 15:53:25 -07003:: import py_gen.oftype
Rich Lanea2de2192013-11-29 17:58:32 -08004:: type_members = [m for m in ofclass.members if type(m) == OFTypeMember]
Rich Lane002e70c2013-05-09 17:08:16 -07005:: normal_members = [m for m in ofclass.members if type(m) == OFDataMember]
Rich Lane9d98adf2013-11-29 18:37:24 -08006class ${ofclass.pyname}(${superclass_pyname}):
Rich Lanea2de2192013-11-29 17:58:32 -08007:: for m in type_members:
Rich Laned1dd9e62013-02-20 18:28:01 -08008 ${m.name} = ${m.value}
9:: #endfor
10
Rich Lane8ca3b772013-04-30 13:36:55 -070011 def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in normal_members])}):
12:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080013 if ${m.name} != None:
14 self.${m.name} = ${m.name}
15 else:
Rich Lane0f7f9d52013-11-29 17:00:49 -080016:: if m.name == 'xid':
17:: # HACK for message xid
18 self.${m.name} = None
19:: else:
Andreas Wundsam69ecfdc2013-09-17 13:50:12 -070020 self.${m.name} = ${py_gen.oftype.gen_init_expr(m.oftype, version=version)}
Rich Lane0f7f9d52013-11-29 17:00:49 -080021:: #endif
Rich Laned1dd9e62013-02-20 18:28:01 -080022:: #endfor
23 return
24
25 def pack(self):
26 packed = []
27:: include("_pack.py", ofclass=ofclass)
28 return ''.join(packed)
29
30 @staticmethod
Rich Lane5b2745c2013-11-30 00:36:24 -080031 def unpack(reader):
Rich Laned1dd9e62013-02-20 18:28:01 -080032 obj = ${ofclass.pyname}()
33:: include("_unpack.py", ofclass=ofclass)
34 return obj
35
36 def __eq__(self, other):
37 if type(self) != type(other): return False
Rich Lane8ca3b772013-04-30 13:36:55 -070038:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080039 if self.${m.name} != other.${m.name}: return False
40:: #endfor
41 return True
42
Rich Laned1dd9e62013-02-20 18:28:01 -080043 def pretty_print(self, q):
44:: include('_pretty_print.py', ofclass=ofclass)
Rich Lane78a3bc42013-11-29 19:22:08 -080045
46:: # Register with our superclass
47:: if ofclass.superclass:
48:: type_field_name = ofclass.superclass.discriminator.name
49:: type_value = ofclass.member_by_name(type_field_name).value
50${superclass_pyname}.subtypes[${type_value}] = ${ofclass.pyname}
51:: #endif