12
12
13
13
module fpm_manifest_preprocess
14
14
use fpm_error, only : error_t, syntax_error
15
- use fpm_strings, only : string_t
16
- use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list
15
+ use fpm_strings, only : string_t, operator (==)
16
+ use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list, serializable_t, set_value, set_list, &
17
+ set_string
17
18
implicit none
18
19
private
19
20
20
21
public :: preprocess_config_t, new_preprocess_config, new_preprocessors
21
22
22
23
! > Configuration meta data for a preprocessor
23
- type :: preprocess_config_t
24
+ type, extends(serializable_t) :: preprocess_config_t
24
25
25
26
! > Name of the preprocessor
26
27
character (len= :), allocatable :: name
@@ -39,8 +40,15 @@ module fpm_manifest_preprocess
39
40
! > Print information on this instance
40
41
procedure :: info
41
42
43
+ ! > Serialization interface
44
+ procedure :: serializable_is_same = > preprocess_is_same
45
+ procedure :: dump_to_toml
46
+ procedure :: load_from_toml
47
+
42
48
end type preprocess_config_t
43
49
50
+ character (* ), parameter , private :: class_name = ' preprocess_config_t'
51
+
44
52
contains
45
53
46
54
! > Construct a new preprocess configuration from TOML data structure
@@ -154,7 +162,7 @@ subroutine info(self, unit, verbosity)
154
162
pr = 1
155
163
end if
156
164
157
- if (pr < 1 ) return
165
+ if (pr < 1 ) return
158
166
159
167
write (unit, fmt) " Preprocessor"
160
168
if (allocated (self% name)) then
@@ -181,4 +189,75 @@ subroutine info(self, unit, verbosity)
181
189
182
190
end subroutine info
183
191
192
+ logical function preprocess_is_same (this ,that )
193
+ class(preprocess_config_t), intent (in ) :: this
194
+ class(serializable_t), intent (in ) :: that
195
+
196
+ preprocess_is_same = .false.
197
+
198
+ select type (other= >that)
199
+ type is (preprocess_config_t)
200
+ if (allocated (this% name).neqv. allocated (other% name)) return
201
+ if (allocated (this% name)) then
202
+ if (.not. (this% name== other% name)) return
203
+ endif
204
+ if (.not. (this% suffixes== other% suffixes)) return
205
+ if (.not. (this% directories== other% directories)) return
206
+ if (.not. (this% macros== other% macros)) return
207
+
208
+ class default
209
+ ! Not the same type
210
+ return
211
+ end select
212
+
213
+ ! > All checks passed!
214
+ preprocess_is_same = .true.
215
+
216
+ end function preprocess_is_same
217
+
218
+ ! > Dump install config to toml table
219
+ subroutine dump_to_toml (self , table , error )
220
+
221
+ ! > Instance of the serializable object
222
+ class(preprocess_config_t), intent (inout ) :: self
223
+
224
+ ! > Data structure
225
+ type (toml_table), intent (inout ) :: table
226
+
227
+ ! > Error handling
228
+ type (error_t), allocatable , intent (out ) :: error
229
+
230
+ call set_string(table, " name" , self% name, error)
231
+ if (allocated (error)) return
232
+ call set_list(table, " suffixes" , self% suffixes, error)
233
+ if (allocated (error)) return
234
+ call set_list(table, " directories" , self% directories, error)
235
+ if (allocated (error)) return
236
+ call set_list(table, " macros" , self% macros, error)
237
+ if (allocated (error)) return
238
+
239
+ end subroutine dump_to_toml
240
+
241
+ ! > Read install config from toml table (no checks made at this stage)
242
+ subroutine load_from_toml (self , table , error )
243
+
244
+ ! > Instance of the serializable object
245
+ class(preprocess_config_t), intent (inout ) :: self
246
+
247
+ ! > Data structure
248
+ type (toml_table), intent (inout ) :: table
249
+
250
+ ! > Error handling
251
+ type (error_t), allocatable , intent (out ) :: error
252
+
253
+ call get_value(table, " name" , self% name)
254
+ call get_list(table, " suffixes" , self% suffixes, error)
255
+ if (allocated (error)) return
256
+ call get_list(table, " directories" , self% directories, error)
257
+ if (allocated (error)) return
258
+ call get_list(table, " macros" , self% macros, error)
259
+ if (allocated (error)) return
260
+
261
+ end subroutine load_from_toml
262
+
184
263
end module fpm_manifest_preprocess
0 commit comments