Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 1 | :: nonskip_members = [m for m in ofclass.members if not m.skip] |
| 2 | class ${ofclass.pyname}(${superclass}): |
| 3 | :: for m in ofclass.type_members: |
| 4 | ${m.name} = ${m.value} |
| 5 | :: #endfor |
| 6 | |
| 7 | def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in nonskip_members])}): |
| 8 | :: for m in nonskip_members: |
| 9 | if ${m.name} != None: |
| 10 | self.${m.name} = ${m.name} |
| 11 | else: |
| 12 | self.${m.name} = ${m.oftype.gen_init_expr()} |
| 13 | :: #endfor |
| 14 | return |
| 15 | |
| 16 | def pack(self): |
| 17 | packed = [] |
| 18 | :: include("_pack.py", ofclass=ofclass) |
| 19 | return ''.join(packed) |
| 20 | |
| 21 | @staticmethod |
| 22 | def unpack(buf): |
| 23 | obj = ${ofclass.pyname}() |
| 24 | :: include("_unpack.py", ofclass=ofclass) |
| 25 | return obj |
| 26 | |
| 27 | def __eq__(self, other): |
| 28 | if type(self) != type(other): return False |
| 29 | :: for m in nonskip_members: |
| 30 | if self.${m.name} != other.${m.name}: return False |
| 31 | :: #endfor |
| 32 | return True |
| 33 | |
| 34 | def __ne__(self, other): |
| 35 | return not self.__eq__(other) |
| 36 | |
| 37 | def show(self): |
| 38 | import loxi.pp |
| 39 | return loxi.pp.pp(self) |
| 40 | |
| 41 | def pretty_print(self, q): |
| 42 | :: include('_pretty_print.py', ofclass=ofclass) |