]> granicus.if.org Git - icinga2/blob - lib/base/configwriter.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / configwriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef CONFIGWRITER_H
4 #define CONFIGWRITER_H
5
6 #include "base/object.hpp"
7 #include "base/array.hpp"
8 #include "base/dictionary.hpp"
9 #include <iosfwd>
10
11 namespace icinga
12 {
13
14 /**
15  * A config identifier.
16  *
17  * @ingroup base
18  */
19 class ConfigIdentifier final : public Object
20 {
21 public:
22         DECLARE_PTR_TYPEDEFS(ConfigIdentifier);
23
24         ConfigIdentifier(String name);
25
26         String GetName() const;
27
28 private:
29         String m_Name;
30 };
31
32 /**
33  * A configuration writer.
34  *
35  * @ingroup base
36  */
37 class ConfigWriter
38 {
39 public:
40         static void EmitBoolean(std::ostream& fp, bool val);
41         static void EmitNumber(std::ostream& fp, double val);
42         static void EmitString(std::ostream& fp, const String& val);
43         static void EmitEmpty(std::ostream& fp);
44         static void EmitArray(std::ostream& fp, int indentLevel, const Array::Ptr& val);
45         static void EmitArrayItems(std::ostream& fp, int indentLevel, const Array::Ptr& val);
46         static void EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val,
47                 const Array::Ptr& imports = nullptr, bool splitDot = false);
48         static void EmitValue(std::ostream& fp, int indentLevel, const Value& val);
49         static void EmitRaw(std::ostream& fp, const String& val);
50         static void EmitIndent(std::ostream& fp, int indentLevel);
51
52         static void EmitIdentifier(std::ostream& fp, const String& identifier, bool inAssignment);
53         static void EmitConfigItem(std::ostream& fp, const String& type, const String& name, bool isTemplate,
54                 bool ignoreOnError, const Array::Ptr& imports, const Dictionary::Ptr& attrs);
55
56         static void EmitComment(std::ostream& fp, const String& text);
57         static void EmitFunctionCall(std::ostream& fp, const String& name, const Array::Ptr& arguments);
58
59         static const std::vector<String>& GetKeywords();
60 private:
61         static String EscapeIcingaString(const String& str);
62         ConfigWriter();
63 };
64
65 }
66
67 #endif /* CONFIGWRITER_H */