Peano
Loading...
Searching...
No Matches
Double.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 cardinality is a string (you can thus use symbols as well as long as
10 they will be defined at compile time). Pass None if you are working
11 with a scalar.
12
13 """
14
16 self,
17 name,
18 valid_mantissa_bits=None,
19 ifdefs=[],
20 qualifier=Attribute.Qualifier.NONE,
21 initval=None,
22 ):
23 """!
24
25
26 """
27
28 # Do we need to expose this attribute in the header file?
29 # Only necessary for functions that will be inlined, i.e. constexpr
30 expose = qualifier == Attribute.Qualifier.CONSTEXPR
31
32 Attribute.__init__(
33 self,
34 name,
35 ifdefs,
36 qualifier=qualifier,
37 initval=initval,
38 expose_in_header_file=expose,
39 )
40 self._valid_mantissa_bits = valid_mantissa_bits
41
42 return
43
44 def get_methods(self, _full_qualified_class_name, for_declaration=True):
45 accessor_name = self.get_accessor_name()
46 methods = []
47
48 if self._is_static:
49 if for_declaration:
50 # No 'const' here: static member function cannot have 'const' qualifier
51 getter = ("get" + accessor_name + "()", "static double")
52 else:
53 # No 'static' here: 'static' can only be specified inside the class definition
54 getter = ("get" + accessor_name + "()", "double")
55
56 elif self._is_const_static:
57 if for_declaration:
58 # No 'const' here: static member function cannot have 'const' qualifier
59 getter = ("get" + accessor_name + "()", "static double")
60 else:
61 # No 'static' here: 'static' can only be specified inside the class definition
62 # No 'const' here either: function definition will then differ from that in declaration
63 getter = ("get" + accessor_name + "()", "double")
64
65 elif self._is_const:
66 getter = ("get" + accessor_name + "() const", "const double")
67
69 getter = ("get" + accessor_name + "() const", "constexpr double")
70
71 else:
72 # default case.
73 getter = ("get" + accessor_name + "() const", "double")
74
75 methods.append(getter)
76
77 # Add a setter method, if it makes sense.
79 methods.append(("set" + accessor_name + "(double value)", "void"))
80
81 return methods
82
83 def get_plain_C_attributes(self, for_constructor=False):
84 typestring = "double"
85 namestring = "_" + self._name
86
87 # add const/static qualifiers and initialization values, if needed
88 if self._is_static:
89 typestring = "inline static double"
90 if self._initval is not None:
91 namestring += " = " + str(self._initval)
92
93 elif self._is_const_static:
94 typestring = "inline const static double"
95 namestring += " = " + str(self._initval)
96
97 elif self._is_const:
98 typestring = "const double"
99 namestring += " = " + str(self._initval)
100
102 typestring = "constexpr static double"
103 namestring += " = " + str(self._initval)
104
105 else:
106 # default case
107 # If an initial value is provided, add it
108 # However, only add it if we need it for a definition,
109 # not as optional argument for constructor method
110 if self._initval is not None and not for_constructor:
111 namestring += " = " + str(self._initval)
112
113 # Set up compression/packaging
114 if self._valid_mantissa_bits is None:
115 return [(namestring, typestring, "")]
116 else:
117 mantissastring = (
118 "[[clang::truncate_mantissa(" + str(self._valid_mantissa_bits) + ")]]"
119 )
120 return [(namestring, typestring, mantissastring)]
121
122 def get_method_body(self, signature):
123 if signature.startswith("get") and self.use_data_store:
124 return " return _dataStore._" + self._name + ";\n"
125 elif signature.startswith("get") and not self.use_data_store:
126 return " return _" + self._name + ";\n"
127 elif signature.startswith("set") and self.use_data_store:
128 return " _dataStore._" + self._name + " = value;\n"
129 elif signature.startswith("set") and not self.use_data_store:
130 return " _" + self._name + " = value;\n"
131 else:
132 assert False
133 return ""
134
136 return [("MPI_DOUBLE", 1)]
137
138 def get_to_string(self):
139 """
140
141 Return string representation of attribute.
142
143 """
144 if self.use_data_store:
145 return "_dataStore._" + self._name
146 else:
147 return "_" + self._name
148
149 @property
151 return self._valid_mantissa_bits
152
153 @valid_mantissa_bits.setter
154 def valid_mantissa_bits(self, value):
155 """!
156
157 Set mantissa used
158
159 Pass in None, if you want to use the default accuracy.
160
161 """
162 assert value == None or value > 0
163 self._valid_mantissa_bits = value
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
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
Definition Double.py:6
get_to_string(self)
Return string representation of attribute.
Definition Double.py:138
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
Definition Double.py:122
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
Definition Double.py:83
get_native_MPI_type(self)
Return native (built-in) MPI datatype.
Definition Double.py:135
__init__(self, name, valid_mantissa_bits=None, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
name: String This is a plain string which has to follow the C++ naming conventions,...
Definition Double.py:22
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
Definition Double.py:44