]> granicus.if.org Git - icinga2/blob - lib/config/applyrule.hpp
Merge pull request #7113 from Elias481/fix/incorrect-usage-of-global-namespace-6874...
[icinga2] / lib / config / applyrule.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef APPLYRULE_H
4 #define APPLYRULE_H
5
6 #include "config/i2-config.hpp"
7 #include "config/expression.hpp"
8 #include "base/debuginfo.hpp"
9
10 namespace icinga
11 {
12
13 /**
14  * @ingroup config
15  */
16 class ApplyRule
17 {
18 public:
19         typedef std::map<String, std::vector<String> > TypeMap;
20         typedef std::map<String, std::vector<ApplyRule> > RuleMap;
21
22         String GetTargetType() const;
23         String GetName() const;
24         std::shared_ptr<Expression> GetExpression() const;
25         std::shared_ptr<Expression> GetFilter() const;
26         String GetPackage() const;
27         String GetFKVar() const;
28         String GetFVVar() const;
29         std::shared_ptr<Expression> GetFTerm() const;
30         bool GetIgnoreOnError() const;
31         DebugInfo GetDebugInfo() const;
32         Dictionary::Ptr GetScope() const;
33         void AddMatch();
34         bool HasMatches() const;
35
36         bool EvaluateFilter(ScriptFrame& frame) const;
37
38         static void AddRule(const String& sourceType, const String& targetType, const String& name, const std::shared_ptr<Expression>& expression,
39                 const std::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm,
40                 bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
41         static std::vector<ApplyRule>& GetRules(const String& type);
42
43         static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
44         static bool IsValidSourceType(const String& sourceType);
45         static bool IsValidTargetType(const String& sourceType, const String& targetType);
46         static std::vector<String> GetTargetTypes(const String& sourceType);
47
48         static void CheckMatches(bool silent);
49
50 private:
51         String m_TargetType;
52         String m_Name;
53         std::shared_ptr<Expression> m_Expression;
54         std::shared_ptr<Expression> m_Filter;
55         String m_Package;
56         String m_FKVar;
57         String m_FVVar;
58         std::shared_ptr<Expression> m_FTerm;
59         bool m_IgnoreOnError;
60         DebugInfo m_DebugInfo;
61         Dictionary::Ptr m_Scope;
62         bool m_HasMatches;
63
64         static TypeMap m_Types;
65         static RuleMap m_Rules;
66
67         ApplyRule(String targetType, String name, std::shared_ptr<Expression> expression,
68                 std::shared_ptr<Expression> filter, String package, String fkvar, String fvvar, std::shared_ptr<Expression> fterm,
69                 bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope);
70 };
71
72 }
73
74 #endif /* APPLYRULE_H */