File tree Expand file tree Collapse file tree 6 files changed +48
-2
lines changed Expand file tree Collapse file tree 6 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
8
8
# Add source files for the core library
9
9
file (GLOB_RECURSE MALASIM_CORE_SOURCES
10
10
"*.cpp"
11
- "Config /*.cpp"
11
+ "Configuration /*.cpp"
12
12
"Utils/*.cpp"
13
13
)
14
14
Original file line number Diff line number Diff line change
1
+ #include " Config.h"
2
+
3
+ #include < iostream>
4
+
5
+ bool Config::ValidateNode (const YAML::Node &node, const YAML::Node &schema) {
6
+ for (auto it = schema.begin (); it != schema.end (); ++it) {
7
+ std::string key = it->first .as <std::string>();
8
+ const YAML::Node &schema_field = it->second ;
9
+
10
+ // Check if the field is required and present
11
+ if (schema_field[" required" ] && schema_field[" required" ].as <bool >()
12
+ && !node[key]) {
13
+ std::cerr << " Missing required field: " << key << std::endl;
14
+ return false ;
15
+ }
16
+
17
+ // If the field exists, check the type
18
+ if (node[key]) {
19
+ std::string expected_type = schema_field[" type" ].as <std::string>();
20
+ if (expected_type == " double" && !node[key].IsScalar ()) {
21
+ std::cerr << " Invalid type for field: " << key << " (expected double)"
22
+ << std::endl;
23
+ return false ;
24
+ }
25
+ if (expected_type == " string" && !node[key].IsScalar ()) {
26
+ std::cerr << " Invalid type for field: " << key << " (expected string)"
27
+ << std::endl;
28
+ return false ;
29
+ }
30
+
31
+ // Additional checks like min, max can be added
32
+ if (expected_type == " double" && schema_field[" min" ]) {
33
+ double value = node[key].as <double >();
34
+ if (value < schema_field[" min" ].as <double >()) {
35
+ std::cerr << " Value for " << key
36
+ << " is less than the minimum allowed: "
37
+ << schema_field[" min" ].as <double >() << std::endl;
38
+ return false ;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ return true ;
44
+ }
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ class Config {
48
48
// Load configuration from a YAML file
49
49
void Load (const std::string &filename);
50
50
51
+ bool ValidateNode (const YAML::Node &node, const YAML::Node &schema);
52
+
51
53
// Reload configuration (useful for dynamic updates)
52
54
void Reload ();
53
55
File renamed without changes.
Original file line number Diff line number Diff line change 3
3
#include < iostream>
4
4
#include < stdexcept>
5
5
6
- #include " Config /Config.h" // Assuming Config is defined here
6
+ #include " Configuration /Config.h" // Assuming Config is defined here
7
7
8
8
// Private constructor: creates the Config instance
9
9
Model::Model ()
You can’t perform that action at this time.
0 commit comments