Peano
Loading...
Searching...
No Matches
IntegerArray.py
Go to the documentation of this file.
1# This file is part of the DaStGen2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from .Attribute import Attribute
4from .Integer import Integer
5
6
9 self,
10 name,
11 cardinality,
12 min_value=None,
13 max_value=None,
14 ifdefs=[],
15 qualifier=Attribute.Qualifier.NONE,
16 initval=None,
17 ):
18 if qualifier != Attribute.Qualifier.NONE:
19 raise NotImplementedError(
20 f"Attribute {name}: This data type can't work with qualifiers (yet)"
21 )
22 if initval is not None:
23 raise NotImplementedError(
24 f"Attribute {name}: Can't generate arrays with initial values (yet)."
25 )
26 Integer.__init__(
27 self, name, ifdefs=ifdefs, qualifier=qualifier, initval=initval
28 )
29 self._cardinality = str(cardinality) # ensure this is a string.
30 self._min_value_min_value = min_value
31 self._max_value_max_value = max_value
32 self.compress = min_value != None or max_value != None
33
35 """
36
37 Cannot use the default copy constructor, as it is an array,
38 i.e. we need some manual deep copying.
39
40 """
41 return False
42
43 def get_methods(self, _full_qualified_class_name, for_declaration=True):
44 accessor_name = self._name[:1].title() + self._name[1:]
45 return [
46 ("get" + accessor_name + "() const", "const int*"),
47 (
48 "set" + accessor_name + "(const int value[" + self._cardinality + "])",
49 "void",
50 ),
51 ("get" + accessor_name + "(int index) const", "int"),
52 ("set" + accessor_name + "(int index, int value)", "void"),
53 ]
54
55 def get_plain_C_attributes(self, for_constructor=False):
56 if self._min_value_min_value != None or self._max_value_max_value != None:
57 return [
58 (
59 "_" + self._name + "[" + self._cardinality + "]",
60 "int",
61 "[[clang::pack_range("
62 + str(self._min_value_min_value)
63 + ","
64 + str(self._max_value_max_value)
65 + ")]]",
66 )
67 ]
68 else:
69 return [("_" + self._name + "[" + self._cardinality + "]", "int", "")]
70
72 return [("_" + self._name + "[0]", "int")]
73
74 def get_method_body(self, signature):
75 if self.use_data_store:
76 name = " _dataStore._" + self._name
77 else:
78 name = " _" + self._name
79 if signature.startswith("get") and "index" in signature:
80 return " return " + name + "[index];\n"
81 elif signature.startswith("set") and "index" in signature:
82 return name + "[index] = value;\n"
83 elif signature.startswith("get"):
84 return " return " + name + ";\n"
85 elif signature.startswith("set"):
86 return " std::copy_n(value, " + self._cardinality + ", " + name + " );\n"
87 else:
88 assert False
89 return ""
90
92 return [("MPI_INT", self._cardinality)]
93
94 def get_to_string(self):
95 """
96
97 Return string representation of attribute.
98
99 """
100 if self.use_data_store:
101 return "_dataStore._" + self._name + '[0] << ",..."'
102 else:
103 return "_" + self._name + '[0] << ",..."'
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
get_to_string(self)
Return string representation of attribute.
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
__init__(self, name, cardinality, min_value=None, max_value=None, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
min_value: None or integer value Has to be smaller than max_value.
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
use_default_copy_constructor(self)
Cannot use the default copy constructor, as it is an array, i.e.