]> granicus.if.org Git - icinga2/blob - lib/base/configwriter.hpp
lib->compat->statusdatawriter: fix notifications_enabled
[icinga2] / lib / base / configwriter.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.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 CONFIGWRITER_H
21 #define CONFIGWRITER_H
22
23 #include "base/object.hpp"
24 #include "base/array.hpp"
25 #include "base/dictionary.hpp"
26 #include <iosfwd>
27
28 namespace icinga
29 {
30
31 /**
32  * A config identifier.
33  *
34  * @ingroup base
35  */
36 class ConfigIdentifier final : public Object
37 {
38 public:
39         DECLARE_PTR_TYPEDEFS(ConfigIdentifier);
40
41         ConfigIdentifier(String name);
42
43         String GetName() const;
44
45 private:
46         String m_Name;
47 };
48
49 /**
50  * A configuration writer.
51  *
52  * @ingroup base
53  */
54 class ConfigWriter
55 {
56 public:
57         static void EmitBoolean(std::ostream& fp, bool val);
58         static void EmitNumber(std::ostream& fp, double val);
59         static void EmitString(std::ostream& fp, const String& val);
60         static void EmitEmpty(std::ostream& fp);
61         static void EmitArray(std::ostream& fp, int indentLevel, const Array::Ptr& val);
62         static void EmitArrayItems(std::ostream& fp, int indentLevel, const Array::Ptr& val);
63         static void EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val,
64                 const Array::Ptr& imports = nullptr, bool splitDot = false);
65         static void EmitValue(std::ostream& fp, int indentLevel, const Value& val);
66         static void EmitRaw(std::ostream& fp, const String& val);
67         static void EmitIndent(std::ostream& fp, int indentLevel);
68
69         static void EmitIdentifier(std::ostream& fp, const String& identifier, bool inAssignment);
70         static void EmitConfigItem(std::ostream& fp, const String& type, const String& name, bool isTemplate,
71                 bool ignoreOnError, const Array::Ptr& imports, const Dictionary::Ptr& attrs);
72
73         static void EmitComment(std::ostream& fp, const String& text);
74         static void EmitFunctionCall(std::ostream& fp, const String& name, const Array::Ptr& arguments);
75
76         static const std::vector<String>& GetKeywords();
77 private:
78         static String EscapeIcingaString(const String& str);
79         ConfigWriter();
80 };
81
82 }
83
84 #endif /* CONFIGWRITER_H */