blob: 8c21bb36bb12ca39bdfe2840b65773ee5130d911 [file] [log] [blame]
Rich Lane8ca3b772013-04-30 13:36:55 -07001:: from py_gen.codegen import Member, LengthMember, TypeMember
Rich Lane5de3bb22013-05-01 13:38:39 -07002:: normal_members = [m for m in ofclass.members if type(m) == Member]
Rich Laned1dd9e62013-02-20 18:28:01 -08003class ${ofclass.pyname}(${superclass}):
4:: for m in ofclass.type_members:
5 ${m.name} = ${m.value}
6:: #endfor
7
Rich Lane8ca3b772013-04-30 13:36:55 -07008 def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in normal_members])}):
9:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080010 if ${m.name} != None:
11 self.${m.name} = ${m.name}
12 else:
13 self.${m.name} = ${m.oftype.gen_init_expr()}
14:: #endfor
15 return
16
17 def pack(self):
18 packed = []
19:: include("_pack.py", ofclass=ofclass)
20 return ''.join(packed)
21
22 @staticmethod
23 def unpack(buf):
24 obj = ${ofclass.pyname}()
25:: include("_unpack.py", ofclass=ofclass)
26 return obj
27
28 def __eq__(self, other):
29 if type(self) != type(other): return False
Rich Lane8ca3b772013-04-30 13:36:55 -070030:: for m in normal_members:
Rich Laned1dd9e62013-02-20 18:28:01 -080031 if self.${m.name} != other.${m.name}: return False
32:: #endfor
33 return True
34
35 def __ne__(self, other):
36 return not self.__eq__(other)
37
38 def show(self):
39 import loxi.pp
40 return loxi.pp.pp(self)
41
42 def pretty_print(self, q):
43:: include('_pretty_print.py', ofclass=ofclass)