aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/Constants.py
blob: eafddd72e46266776d3dc2bd6dac97958f6c5114 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from .Bucket import Bucket

class Constants(Bucket):
    """
    The purpose of this class is to be hold user defined constants
    The constants will be concatenated into names and values string.
    """
    def __init__(self):
        Bucket.__init__(self, 'constants')

    def __setattr__(self, name, value):
        # Make sure that any constants redefined have a consistent value
        if name in self.argvattrs:
            assert self.argvattrs[name] == value, Exception('In consistent values given for user defined constants')
        Bucket.__setattr__(self, name, value)

    def attrlist(self):
        "Concatenate the attributes into a string"
        if self.argvattrs:
            names = ''
            values = ''
            for attr, value in self.argvattrs.items():
                names += ' ' + attr
                values += ' {}'.format(value)
            return ['constants.use_my_constants = 1',
                    'constants.constant_names = ' + names,
                    'constants.constant_values = ' + values]
        else:
            return []


constants = Constants()