Ember
Loading...
Searching...
No Matches
BehaviorTreeValidator.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/BehaviorTree.h"
5#include "Types/Types.h"
6#include <algorithm>
7#include <memory>
8#include <vector>
9
10namespace EmberCore {
11
19 public:
20 enum class Severity {
21 ERROR, // Critical issue - should prevent loading
22 WARNING // Issue that should be warned about but can be ignored
23 };
24
28 EmberCore::String node_path; // Path to problematic node (e.g., "Root/Sequence/Action")
29
31 : severity(sev), message(msg), node_path(path) {}
32 };
33
36 std::vector<ValidationIssue> issues;
37
39
40 void AddError(const EmberCore::String &message, const EmberCore::String &node_path = "") {
41 issues.emplace_back(Severity::ERROR, message, node_path);
42 is_valid = false;
43 }
44
45 void AddWarning(const EmberCore::String &message, const EmberCore::String &node_path = "") {
46 issues.emplace_back(Severity::WARNING, message, node_path);
47 }
48
49 bool HasErrors() const {
50 return std::any_of(issues.begin(), issues.end(),
51 [](const ValidationIssue &issue) { return issue.severity == Severity::ERROR; });
52 }
53
54 bool HasWarnings() const {
55 return std::any_of(issues.begin(), issues.end(),
56 [](const ValidationIssue &issue) { return issue.severity == Severity::WARNING; });
57 }
58
59 size_t ErrorCount() const {
60 return std::count_if(issues.begin(), issues.end(),
61 [](const ValidationIssue &issue) { return issue.severity == Severity::ERROR; });
62 }
63
64 size_t WarningCount() const {
65 return std::count_if(issues.begin(), issues.end(),
66 [](const ValidationIssue &issue) { return issue.severity == Severity::WARNING; });
67 }
68 };
69
71 explicit BehaviorTreeValidator(const ParserConfig &config);
72
86 ValidationResult Validate(const BehaviorTree *tree) const;
87
94 static ValidationResult ValidateWithConfig(const BehaviorTree *tree, const ParserConfig &config);
95
96 private:
98
99 // Validation methods
100 void ValidateTreeStructure(const BehaviorTree *tree, ValidationResult &result) const;
101 void ValidateNode(const Node *node, ValidationResult &result, std::vector<const Node *> &visited,
102 const EmberCore::String &path) const;
103 void ValidateNodeType(const Node *node, ValidationResult &result, const EmberCore::String &path) const;
104 void ValidateNodeAttributes(const Node *node, ValidationResult &result, const EmberCore::String &path) const;
105 void ValidateChildCount(const Node *node, ValidationResult &result, const EmberCore::String &path) const;
106 void ValidateBlackboards(const BehaviorTree *tree, ValidationResult &result) const;
107
108 // Helper methods
109 EmberCore::String BuildNodePath(const EmberCore::String &parent_path, const Node *node) const;
110 bool HasCycles(const Node *node, std::vector<const Node *> &visited) const;
111};
112
113} // namespace EmberCore
ValidationResult Validate(const BehaviorTree *tree) const
Validate a behavior tree against the parser profile.
EmberCore::String BuildNodePath(const EmberCore::String &parent_path, const Node *node) const
void ValidateTreeStructure(const BehaviorTree *tree, ValidationResult &result) const
static ValidationResult ValidateWithConfig(const BehaviorTree *tree, const ParserConfig &config)
Validate a behavior tree with profile override.
void ValidateNodeType(const Node *node, ValidationResult &result, const EmberCore::String &path) const
bool HasCycles(const Node *node, std::vector< const Node * > &visited) const
void ValidateNodeAttributes(const Node *node, ValidationResult &result, const EmberCore::String &path) const
void ValidateNode(const Node *node, ValidationResult &result, std::vector< const Node * > &visited, const EmberCore::String &path) const
void ValidateBlackboards(const BehaviorTree *tree, ValidationResult &result) const
void ValidateChildCount(const Node *node, ValidationResult &result, const EmberCore::String &path) const
Represents a complete behavior tree data structure.
Represents a node in a behavior tree structure.
Definition Node.h:20
Configuration for XML parser behavior and element/attribute mappings.
Main types header for EmberCore.
std::string String
Framework-agnostic string type.
Definition String.h:14
ValidationIssue(Severity sev, const EmberCore::String &msg, const EmberCore::String &path="")
void AddError(const EmberCore::String &message, const EmberCore::String &node_path="")
void AddWarning(const EmberCore::String &message, const EmberCore::String &node_path="")