added ABS_Parameter, an abstract class definition to flexibly store parameters

This commit is contained in:
Richard Hartmann 2019-07-04 12:50:24 +02:00
parent fae9b47ae8
commit 2e68e98c2a

View file

@ -33,6 +33,7 @@ from __future__ import division, print_function
is the same among different python versions (they should be though!) is the same among different python versions (they should be though!)
""" """
from collections import namedtuple from collections import namedtuple
from math import ceil from math import ceil
import numpy as np import numpy as np
@ -143,6 +144,41 @@ class BFUnkownClassError(Exception):
"Please provide the lookup 'classes' when calling load, that maps the class name of the object to the actual "+ "Please provide the lookup 'classes' when calling load, that maps the class name of the object to the actual "+
"class definition (class object).") "class definition (class object).")
class ABS_Parameter(object):
__slots__ = ['__non_key__']
def __init__(self):
pass
def __bfkey__(self):
key = []
sorted_slots = sorted(self.__slots__)
if '__non_key__' in sorted_slots: sorted_slots.remove('__non_key__')
for k in sorted_slots:
atr = getattr(self, k)
if atr is not None:
key.append((k, atr))
return key
def __repr__(self):
s = ""
sorted_slots = sorted(self.__slots__)
if '__non_key__' in sorted_slots: sorted_slots.remove('__non_key__')
max_l = max([len(k) for k in sorted_slots])
for k in sorted_slots:
atr = getattr(self, k)
if atr is not None:
s += "{1:>{0}} : {2}\n".format(max_l, k, atr)
if '__non_key__' in self.__slots__:
s += "--- extra info ---\n"
keys = sorted(self.__non_key__.keys())
mal_l = max([k for k in keys])
for k in keys:
s += "{1:>{0}} : {2}\n".format(max_l, k, self.__non_key__[k])
return s
def _dump_spec(ob): def _dump_spec(ob):
if ob == True: if ob == True:
b = init_BYTES([_SPEC, char_to_byte('T')]) b = init_BYTES([_SPEC, char_to_byte('T')])