]> granicus.if.org Git - icinga2/blob - lib/config/applyrule.hpp
Merge pull request #6731 from Icinga/bugfix/doc-comment
[icinga2] / lib / config / applyrule.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)      *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef APPLYRULE_H
21 #define APPLYRULE_H
22
23 #include "config/i2-config.hpp"
24 #include "config/expression.hpp"
25 #include "base/debuginfo.hpp"
26
27 namespace icinga
28 {
29
30 /**
31  * @ingroup config
32  */
33 class ApplyRule
34 {
35 public:
36         typedef std::map<String, std::vector<String> > TypeMap;
37         typedef std::map<String, std::vector<ApplyRule> > RuleMap;
38
39         String GetTargetType() const;
40         String GetName() const;
41         std::shared_ptr<Expression> GetExpression() const;
42         std::shared_ptr<Expression> GetFilter() const;
43         String GetPackage() const;
44         String GetFKVar() const;
45         String GetFVVar() const;
46         std::shared_ptr<Expression> GetFTerm() const;
47         bool GetIgnoreOnError() const;
48         DebugInfo GetDebugInfo() const;
49         Dictionary::Ptr GetScope() const;
50         void AddMatch();
51         bool HasMatches() const;
52
53         bool EvaluateFilter(ScriptFrame& frame) const;
54
55         static void AddRule(const String& sourceType, const String& targetType, const String& name, const std::shared_ptr<Expression>& expression,
56                 const std::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm,
57                 bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
58         static std::vector<ApplyRule>& GetRules(const String& type);
59
60         static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes);
61         static bool IsValidSourceType(const String& sourceType);
62         static bool IsValidTargetType(const String& sourceType, const String& targetType);
63         static std::vector<String> GetTargetTypes(const String& sourceType);
64
65         static void CheckMatches(bool silent);
66
67 private:
68         String m_TargetType;
69         String m_Name;
70         std::shared_ptr<Expression> m_Expression;
71         std::shared_ptr<Expression> m_Filter;
72         String m_Package;
73         String m_FKVar;
74         String m_FVVar;
75         std::shared_ptr<Expression> m_FTerm;
76         bool m_IgnoreOnError;
77         DebugInfo m_DebugInfo;
78         Dictionary::Ptr m_Scope;
79         bool m_HasMatches;
80
81         static TypeMap m_Types;
82         static RuleMap m_Rules;
83
84         ApplyRule(String targetType, String name, std::shared_ptr<Expression> expression,
85                 std::shared_ptr<Expression> filter, String package, String fkvar, String fvvar, std::shared_ptr<Expression> fterm,
86                 bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope);
87 };
88
89 }
90
91 #endif /* APPLYRULE_H */