@@ -70,9 +70,61 @@ std::optional<Configuration> Parser::parse_config(const json::value& json)
70
70
71
71
bool Parser::check_configuration (const InterfaceData& data, Configuration& config)
72
72
{
73
- // TODO
74
- std::ignore = data;
75
- std::ignore = config;
73
+ bool erased = false ;
74
+
75
+ for (auto iter = config.task .begin (); iter != config.task .end ();) {
76
+ bool checked = check_task (data, *iter);
77
+ if (checked) {
78
+ ++iter;
79
+ }
80
+ else {
81
+ iter = config.task .erase (iter);
82
+ erased = true ;
83
+ }
84
+ }
85
+
86
+ auto resource_iter = std::ranges::find (data.resource , config.resource , std::mem_fn (&InterfaceData::Resource::name));
87
+ if (resource_iter == data.resource .end ()) {
88
+ LogWarn << " Resource not found" << VAR (config.resource );
89
+ config.resource .clear ();
90
+ return false ;
91
+ }
92
+
93
+ auto controller_iter =
94
+ std::ranges::find (data.controller , config.controller .name , std::mem_fn (&InterfaceData::Controller::name));
95
+ if (controller_iter == data.controller .end ()) {
96
+ LogWarn << " Controller not found" << VAR (config.controller .name );
97
+ config.controller .name .clear ();
98
+ return false ;
99
+ }
100
+
101
+ return !erased;
102
+ }
103
+
104
+ bool Parser::check_task (const InterfaceData& data, Configuration::Task& config_task)
105
+ {
106
+ auto data_iter = std::ranges::find (data.task , config_task.name , std::mem_fn (&InterfaceData::Task::name));
107
+ if (data_iter == data.task .end ()) {
108
+ LogWarn << " Task not found" << VAR (config_task.name );
109
+ return false ;
110
+ }
111
+
112
+ for (auto & config_option : config_task.option ) {
113
+ auto option_iter = data.option .find (config_option.name );
114
+ if (option_iter == data.option .end ()) {
115
+ LogWarn << " Option not found" << VAR (config_task.name ) << VAR (config_option.name );
116
+ return false ;
117
+ }
118
+
119
+ const InterfaceData::Option& data_option = option_iter->second ;
120
+
121
+ auto case_iter =
122
+ std::ranges::find (data_option.cases , config_option.value , std::mem_fn (&InterfaceData::Option::Case::name));
123
+ if (case_iter == data_option.cases .end ()) {
124
+ LogWarn << " Case not found" << VAR (config_task.name ) << VAR (config_option.name ) << VAR (config_option.value );
125
+ return false ;
126
+ }
127
+ }
76
128
77
129
return true ;
78
130
}
0 commit comments