Rich Lane | 8ca3b77 | 2013-04-30 13:36:55 -0700 | [diff] [blame] | 1 | :: from py_gen.codegen import Member, LengthMember, TypeMember |
Rich Lane | 5de3bb2 | 2013-05-01 13:38:39 -0700 | [diff] [blame] | 2 | :: normal_members = [m for m in ofclass.members if type(m) == Member] |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 3 | class ${ofclass.pyname}(${superclass}): |
| 4 | :: for m in ofclass.type_members: |
| 5 | ${m.name} = ${m.value} |
| 6 | :: #endfor |
| 7 | |
Rich Lane | 8ca3b77 | 2013-04-30 13:36:55 -0700 | [diff] [blame] | 8 | def __init__(${', '.join(['self'] + ["%s=None" % m.name for m in normal_members])}): |
| 9 | :: for m in normal_members: |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 10 | 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 Lane | 8ca3b77 | 2013-04-30 13:36:55 -0700 | [diff] [blame] | 30 | :: for m in normal_members: |
Rich Lane | d1dd9e6 | 2013-02-20 18:28:01 -0800 | [diff] [blame] | 31 | 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) |