Peano
Loading...
Searching...
No Matches
DoublePointer.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
4
5
7 """!
8
9 A double pointer
10
11 Such a pointer is not initialised by default, i.e. how to handle the
12 underlying data structure is totally up to the user. This data type
13 also does not support any MPI data exchange.
14
15 """
17 self,
18 name,
19 ifdefs=[],
20 qualifier=Attribute.Qualifier.NONE,
21 ):
22 """
23
24 """
25
26 # Do we need to expose this attribute in the header file?
27 # Only necessary for functions that will be inlined, i.e. constexpr
28 expose = qualifier == Attribute.Qualifier.CONSTEXPR
29
30 Attribute.__init__(
31 self,
32 name,
33 ifdefs,
34 qualifier=qualifier,
35 initval="nullptr",
36 expose_in_header_file=expose,
37 )
38
39 assert not self._is_constexpr_is_constexpr, "double pointer cannot be constexpr"
40 return
41
42 def get_methods(self, _full_qualified_class_name, for_declaration=True):
43 accessor_name = self.get_accessor_name()
44 methods = []
45
46 if self._is_static:
47 if for_declaration:
48 # No 'const' here: static member function cannot have 'const' qualifier
49 getter = ("get" + accessor_name + "()", "static double*")
50 else:
51 # No 'static' here: 'static' can only be specified inside the class definition
52 getter = ("get" + accessor_name + "()", "double*")
53
54 elif self._is_const_static:
55 if for_declaration:
56 # No 'const' here: static member function cannot have 'const' qualifier
57 getter = ("get" + accessor_name + "()", "static double*")
58 else:
59 # No 'static' here: 'static' can only be specified inside the class definition
60 # No 'const' here either: function definition will then differ from that in declaration
61 getter = ("get" + accessor_name + "()", "double*")
62
63 elif self._is_const:
64 getter = ("get" + accessor_name + "() const", "const double*")
65
66 else:
67 # default case.
68 getter = ("get" + accessor_name + "() const", "double*")
69
70 methods.append(getter)
71
72 # Add a setter method, if it makes sense.
73 if not (self._is_const_static or self._is_const or self._is_constexpr_is_constexpr):
74 methods.append(("set" + accessor_name + "(double* value)", "void"))
75
76 return methods
77
78 def get_plain_C_attributes(self, for_constructor=False):
79 typestring = "double*"
80 namestring = "_" + self._name
81
82 # add const/static qualifiers and initialization values, if needed
83 if self._is_static:
84 typestring = "inline static double*"
85 if self._initval is not None:
86 namestring += " = " + str(self._initval)
87
88 elif self._is_const_static:
89 typestring = "inline const static double*"
90 namestring += " = " + str(self._initval)
91
92 elif self._is_const:
93 typestring = "const double*"
94 namestring += " = " + str(self._initval)
95
96 else:
97 # default case
98 # If an initial value is provided, add it
99 # However, only add it if we need it for a definition,
100 # not as optional argument for constructor method
101 if self._initval is not None and not for_constructor:
102 namestring += " = " + str(self._initval)
103
104 # Set up compression/packaging
105 return [(namestring, typestring, "")]
106
107 def get_method_body(self, signature):
108 if signature.startswith("get") and self.use_data_store:
109 return " return _dataStore._" + self._name + ";\n"
110 elif signature.startswith("get") and not self.use_data_store:
111 return " return _" + self._name + ";\n"
112 elif signature.startswith("set") and self.use_data_store:
113 return " _dataStore._" + self._name + " = value;\n"
114 elif signature.startswith("set") and not self.use_data_store:
115 return " _" + self._name + " = value;\n"
116 else:
117 assert False
118 return ""
119
121 return [("MPI_DOUBLE /* <double pointer should not be used for MPI data exchange> */", 1)]
122
123 def get_to_string(self):
124 """
125
126 Return string representation of attribute.
127
128 """
129 if self.use_data_store:
130 return "_dataStore._" + self._name
131 else:
132 return "_" + self._name
Represents one attribute.
Definition Attribute.py:8
get_accessor_name(self)
Generate the accessor name used throughout dastgen2 to create variables, function names,...
Definition Attribute.py:259
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
get_to_string(self)
Return string representation of attribute.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
__init__(self, name, ifdefs=[], qualifier=Attribute.Qualifier.NONE)
name: String This is a plain string which has to follow the C++ naming conventions,...
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
get_native_MPI_type(self)
Return native (built-in) MPI datatype.