@@ -68,6 +68,37 @@ struct AeroParticle {
6868 throw std::runtime_error (" AeroData size mistmatch" );
6969 }
7070
71+ template <typename T, typename Func>
72+ static T get_value (const AeroParticle &self, Func func) {
73+ T value{};
74+ func (self.ptr .f_arg (), &value);
75+ return value;
76+ }
77+
78+ template <typename T, typename Func>
79+ static void set_value (AeroParticle &self, Func func, T value) {
80+ func (self.ptr .f_arg_non_const (), &value);
81+ }
82+
83+ template <typename T, typename Func>
84+ static T get_derived_value (const AeroParticle &self, Func func)
85+ {
86+ T value{};
87+ func (self.ptr .f_arg (), self.aero_data .get (), &value);
88+ return value;
89+ }
90+
91+ template <typename T, typename Func>
92+ static T get_derived_value_env_state (
93+ const AeroParticle &self,
94+ const EnvState &env_state,
95+ Func func)
96+ {
97+ T value{};
98+ func (self.ptr .f_arg (), self.aero_data .get (), env_state.ptr .f_arg (), &value);
99+ return value;
100+ }
101+
71102 static auto volumes (const AeroParticle &self)
72103 {
73104 int len = AeroData::__len__ (*self.aero_data );
@@ -81,12 +112,7 @@ struct AeroParticle {
81112 }
82113
83114 static auto volume (const AeroParticle &self) {
84- double vol;
85- f_aero_particle_volume (
86- self.ptr .f_arg (),
87- &vol
88- );
89- return vol;
115+ return get_value<double >(self, f_aero_particle_volume);
90116 }
91117
92118 static auto species_volume (const AeroParticle &self, const int &i_spec) {
@@ -112,63 +138,27 @@ struct AeroParticle {
112138 }
113139
114140 static auto dry_volume (const AeroParticle &self) {
115- double vol;
116- f_aero_particle_dry_volume (
117- self.ptr .f_arg (),
118- self.aero_data .get (),
119- &vol
120- );
121- return vol;
141+ return get_derived_value<double >(self, f_aero_particle_dry_volume);
122142 }
123143
124144 static auto radius (const AeroParticle &self) {
125- double radius;
126- f_aero_particle_radius (
127- self.ptr .f_arg (),
128- self.aero_data .get (),
129- &radius
130- );
131- return radius;
145+ return get_derived_value<double >(self, f_aero_particle_radius);
132146 }
133147
134148 static auto dry_radius (const AeroParticle &self) {
135- double radius;
136- f_aero_particle_dry_radius (
137- self.ptr .f_arg (),
138- self.aero_data .get (),
139- &radius
140- );
141- return radius;
149+ return get_derived_value<double >(self, f_aero_particle_dry_radius);
142150 }
143151
144152 static auto diameter (const AeroParticle &self) {
145- double diameter;
146- f_aero_particle_diameter (
147- self.ptr .f_arg (),
148- self.aero_data .get (),
149- &diameter
150- );
151- return diameter;
153+ return get_derived_value<double >(self, f_aero_particle_diameter);
152154 }
153155
154156 static auto dry_diameter (const AeroParticle &self) {
155- double diameter;
156- f_aero_particle_dry_diameter (
157- self.ptr .f_arg (),
158- self.aero_data .get (),
159- &diameter
160- );
161- return diameter;
157+ return get_derived_value<double >(self, f_aero_particle_dry_diameter);
162158 }
163159
164160 static auto mass (const AeroParticle &self) {
165- double mass;
166- f_aero_particle_mass (
167- self.ptr .f_arg (),
168- self.aero_data .get (),
169- &mass
170- );
171- return mass;
161+ return get_derived_value<double >(self, f_aero_particle_mass);
172162 }
173163
174164 static auto species_mass (const AeroParticle &self, const int &i_spec) {
@@ -207,77 +197,43 @@ struct AeroParticle {
207197 }
208198
209199 static auto solute_kappa (const AeroParticle &self) {
210- double kappa;
211- f_aero_particle_solute_kappa (
212- self.ptr .f_arg (),
213- self.aero_data .get (),
214- &kappa
215- );
216- return kappa;
200+ return get_derived_value<double >(self, f_aero_particle_solute_kappa);
217201 }
218202
219203 static auto moles (const AeroParticle &self) {
220- double moles;
221- f_aero_particle_moles (
222- self.ptr .f_arg (),
223- self.aero_data .get (),
224- &moles
225- );
226- return moles;
204+ return get_derived_value<double >(self, f_aero_particle_moles);
227205 }
228206
229207 static auto mobility_diameter (const AeroParticle &self, const EnvState &env_state) {
230- double mobility_diameter;
231- f_aero_particle_mobility_diameter (
232- self.ptr .f_arg (),
233- self.aero_data .get (),
234- env_state.ptr .f_arg (),
235- &mobility_diameter
236- );
237- return mobility_diameter;
208+ return get_derived_value_env_state<double >(
209+ self,
210+ env_state,
211+ f_aero_particle_mobility_diameter);
238212 }
239213
240214 static auto density (const AeroParticle &self) {
241- double density;
242- f_aero_particle_density (
243- self.ptr .f_arg (),
244- self.aero_data .get (),
245- &density
246- );
247- return density;
215+ return get_derived_value<double >(self, f_aero_particle_density);
248216 }
249217
250218 static auto approx_crit_rel_humid (const AeroParticle &self, const EnvState &env_state) {
251- double approx_crit_rel_humid;
252- f_aero_particle_approx_crit_rel_humid (
253- self.ptr .f_arg (),
254- self.aero_data .get (),
255- env_state.ptr .f_arg (),
256- &approx_crit_rel_humid
257- );
258- return approx_crit_rel_humid;
219+ return get_derived_value_env_state<double >(
220+ self,
221+ env_state,
222+ f_aero_particle_approx_crit_rel_humid);
259223 }
260224
261225 static auto crit_rel_humid (const AeroParticle &self, const EnvState &env_state) {
262- double crit_rel_humid;
263- f_aero_particle_crit_rel_humid (
264- self.ptr .f_arg (),
265- self.aero_data .get (),
266- env_state.ptr .f_arg (),
267- &crit_rel_humid
268- );
269- return crit_rel_humid;
226+ return get_derived_value_env_state<double >(
227+ self,
228+ env_state,
229+ f_aero_particle_crit_rel_humid);
270230 }
271231
272232 static auto crit_diameter (const AeroParticle &self, const EnvState &env_state) {
273- double crit_diameter;
274- f_aero_particle_crit_diameter (
275- self.ptr .f_arg (),
276- self.aero_data .get (),
277- env_state.ptr .f_arg (),
278- &crit_diameter
279- );
280- return crit_diameter;
233+ return get_derived_value_env_state<double >(
234+ self,
235+ env_state,
236+ f_aero_particle_crit_diameter);
281237 }
282238
283239 static auto coagulate (const AeroParticle &self, const AeroParticle &two) {
@@ -357,39 +313,19 @@ struct AeroParticle {
357313 }
358314
359315 static auto least_create_time (const AeroParticle &self) {
360- double val;
361- f_aero_particle_least_create_time (
362- self.ptr .f_arg (),
363- &val
364- );
365- return val;
316+ return get_value<double >(self, f_aero_particle_least_create_time);
366317 }
367318
368319 static auto greatest_create_time (const AeroParticle &self) {
369- double val;
370- f_aero_particle_greatest_create_time (
371- self.ptr .f_arg (),
372- &val
373- );
374- return val;
320+ return get_value<double >(self, f_aero_particle_greatest_create_time);
375321 }
376322
377323 static auto id (const AeroParticle &self) {
378- int64_t val;
379- f_aero_particle_id (
380- self.ptr .f_arg (),
381- &val
382- );
383- return val;
324+ return get_value<int64_t >(self, f_aero_particle_id);
384325 }
385326
386327 static auto is_frozen (const AeroParticle &self) {
387- int val;
388- f_aero_particle_frozen (
389- self.ptr .f_arg (),
390- &val
391- );
392- return val;
328+ return get_value<int >(self, f_aero_particle_frozen);
393329 }
394330
395331 static auto refract_shell (const AeroParticle &self) {
@@ -414,42 +350,23 @@ struct AeroParticle {
414350 return refract_core;
415351 }
416352
417- static void set_weight_class (AeroParticle &self, const int weight_class) {
418- f_aero_particle_set_weight_class (
419- self.ptr .f_arg_non_const (),
420- &weight_class
421- );
422- }
423-
424353 static auto get_weight_class (const AeroParticle &self) {
425- int weight_class;
426-
427- f_aero_particle_get_weight_class (
428- self.ptr .f_arg (),
429- &weight_class
430- );
431- return weight_class;
354+ return get_value<int >(self, f_aero_particle_get_weight_class);
432355 }
433356
434- static void set_weight_group (AeroParticle &self, const int weight_group) {
435- f_aero_particle_set_weight_group (
436- self.ptr .f_arg_non_const (),
437- &weight_group
438- );
357+ static void set_weight_class (AeroParticle &self, const int weight_class) {
358+ set_value<int >(self, f_aero_particle_set_weight_class, weight_class);
439359 }
440360
441361 static auto get_weight_group (const AeroParticle &self) {
442- int weight_group;
362+ return get_value<int >(self, f_aero_particle_get_weight_group);
363+ }
443364
444- f_aero_particle_get_weight_group (
445- self.ptr .f_arg (),
446- &weight_group
447- );
448- return weight_group;
365+ static void set_weight_group (AeroParticle &self, const int weight_group) {
366+ set_value<int >(self, f_aero_particle_set_weight_group, weight_group);
449367 }
450368
451369 static void new_id (AeroParticle &self) {
452-
453370 f_aero_particle_new_id (self.ptr .f_arg_non_const ());
454371 }
455372};
0 commit comments