3
# This file is part of Diamond.
5
# Diamond is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# Diamond is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with Diamond. If not, see <http://www.gnu.org/licenses/>.
19
def __init__(self, datatype, cardinality=''):
20
self.datatype = datatype
21
self.cardinality = cardinality
23
# The input to call is a string containing a list of elements seperated by "," or " ". It
24
# returns a string, containing the elements in val seperated by " ".
25
def __call__(self, val):
32
# Perform some checks on the list cardinality, for oneOrMore elements ('+')
33
# and compulsory elements ('').
34
if self.cardinality == '+':
36
elif self.cardinality == '':
39
# Check the list cardinality (as an integer) matches up with the number of elements
40
# in the seperated val string.
42
assert len(x) == int(self.cardinality)
44
pass # The int conversion may fail (if cardinality is '+' or ''), so just ignore it.
46
# Make sure each element can be converted to type 'self.datatype'. An exception will be
47
# thrown if this is not possible.
51
# Return a string of the elements in val, seperated by " ".
55
return "list of " + str(self.datatype) + " of cardinality: " + self.cardinality
58
return "list of " + str(self.datatype) + " of cardinality: " + self.cardinality