]> granicus.if.org Git - icinga2/commitdiff
Implement Array::ToString and Dictionary::ToString
authorGunnar Beutner <gunnar@beutner.name>
Mon, 26 Oct 2015 10:05:24 +0000 (11:05 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 26 Oct 2015 10:05:24 +0000 (11:05 +0100)
fixes #10329

13 files changed:
lib/base/CMakeLists.txt
lib/base/array.cpp
lib/base/array.hpp
lib/base/configwriter.cpp [moved from lib/config/configwriter.cpp with 82% similarity]
lib/base/configwriter.hpp [moved from lib/config/configwriter.hpp with 96% similarity]
lib/base/dictionary.cpp
lib/base/dictionary.hpp
lib/cli/consolecommand.cpp
lib/config/CMakeLists.txt
lib/config/configcompiler.cpp
lib/config/configcompiler.hpp
lib/icinga/icingaapplication.cpp
lib/remote/configobjectutility.cpp

index 0adaa2fbd533728d85c28381a19848c7d94c2af5..ce2e3c928bb9b951e0da6badb1f68277e7ea11bf 100644 (file)
@@ -26,7 +26,7 @@ set(base_SOURCES
   application.cpp application.thpp application-version.cpp array.cpp
   array-script.cpp boolean.cpp boolean-script.cpp console.cpp context.cpp
   convert.cpp debuginfo.cpp dictionary.cpp dictionary-script.cpp
-  configobject.cpp configobject.thpp configobject-script.cpp configtype.cpp dependencygraph.cpp
+  configobject.cpp configobject.thpp configobject-script.cpp configtype.cpp configwriter.cpp dependencygraph.cpp
   exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp
   json-script.cpp loader.cpp logger.cpp logger.thpp math-script.cpp
   netstring.cpp networkstream.cpp number.cpp number-script.cpp object.cpp
index b069dc78bb657155b0a651257eb57fbfed7093e3..d93e6ae251196f0cb9dc6ca1cc2d323a2f2c6704 100644 (file)
@@ -22,6 +22,7 @@
 #include "base/debug.hpp"
 #include "base/primitivetype.hpp"
 #include "base/dictionary.hpp"
+#include "base/configwriter.hpp"
 #include <boost/foreach.hpp>
 
 using namespace icinga;
@@ -211,3 +212,10 @@ Array::Ptr Array::Reverse(void) const
 
        return result;
 }
+
+String Array::ToString(void) const
+{
+       std::ostringstream msgbuf;
+       ConfigWriter::EmitArray(msgbuf, const_cast<Array *>(this));
+       return msgbuf.str();
+}
index f5fc8018bd50db027cf83815d106ce55594d5070..bb9a00ce5678cbac704e7fb3660d40edbf615de7 100644 (file)
@@ -122,6 +122,8 @@ public:
 
        Array::Ptr Reverse(void) const;
 
+       virtual String ToString(void) const override;
+
 private:
        std::vector<Value> m_Data; /**< The data for the array. */
 };
similarity index 82%
rename from lib/config/configwriter.cpp
rename to lib/base/configwriter.cpp
index 91af9a6c1cf0da0c2c41a55ec80f7118abc342e3..ec55146363fa4cc0b2547735e2bb2cda8165a55e 100644 (file)
@@ -17,7 +17,7 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#include "config/configwriter.hpp"
+#include "base/configwriter.hpp"
 #include "config/configcompiler.hpp"
 #include "base/exception.hpp"
 #include <boost/foreach.hpp>
@@ -145,7 +145,7 @@ void ConfigWriter::EmitIdentifier(std::ostream& fp, const String& identifier, bo
 {
        static std::set<String> keywords;
        if (keywords.empty()) {
-               const std::vector<String>& vkeywords = ConfigCompiler::GetKeywords();
+               const std::vector<String>& vkeywords = GetKeywords();
                std::copy(vkeywords.begin(), vkeywords.end(), std::inserter(keywords, keywords.begin()));
        }
 
@@ -204,3 +204,44 @@ String ConfigWriter::EscapeIcingaString(const String& str)
        boost::algorithm::replace_all(result, "\"", "\\\"");
        return result;
 }
+
+const std::vector<String>& ConfigWriter::GetKeywords(void)
+{
+       static std::vector<String> keywords;
+
+       if (keywords.empty()) {
+               keywords.push_back("object");
+               keywords.push_back("template");
+               keywords.push_back("include");
+               keywords.push_back("include_recursive");
+               keywords.push_back("include_zones");
+               keywords.push_back("library");
+               keywords.push_back("null");
+               keywords.push_back("true");
+               keywords.push_back("false");
+               keywords.push_back("const");
+               keywords.push_back("var");
+               keywords.push_back("this");
+               keywords.push_back("globals");
+               keywords.push_back("locals");
+               keywords.push_back("use");
+               keywords.push_back("ignore_on_error");
+               keywords.push_back("apply");
+               keywords.push_back("to");
+               keywords.push_back("where");
+               keywords.push_back("import");
+               keywords.push_back("assign");
+               keywords.push_back("ignore");
+               keywords.push_back("function");
+               keywords.push_back("return");
+               keywords.push_back("break");
+               keywords.push_back("continue");
+               keywords.push_back("for");
+               keywords.push_back("if");
+               keywords.push_back("else");
+               keywords.push_back("while");
+               keywords.push_back("throw");
+       }
+
+       return keywords;
+}
similarity index 96%
rename from lib/config/configwriter.hpp
rename to lib/base/configwriter.hpp
index c7fa1bb8ee38d5ab8b3089616729cec24ed9ce61..fcee04ab9b6e719bce42f5c2f79d8d9cf4ef9d5a 100644 (file)
@@ -20,7 +20,6 @@
 #ifndef CONFIGWRITER_H
 #define CONFIGWRITER_H
 
-#include "config/i2-config.hpp"
 #include "base/object.hpp"
 #include "base/array.hpp"
 #include "base/dictionary.hpp"
@@ -32,9 +31,9 @@ namespace icinga
 /**
  * A configuration writer.
  *
- * @ingroup config
+ * @ingroup base
  */
-class I2_CONFIG_API ConfigWriter
+class I2_BASE_API ConfigWriter
 {
 public:
        static void EmitBoolean(std::ostream& fp, bool val);
@@ -56,6 +55,7 @@ public:
        static void EmitComment(std::ostream& fp, const String& text);
        static void EmitFunctionCall(std::ostream& fp, const String& name, const Array::Ptr& arguments);
 
+       static const std::vector<String>& GetKeywords(void);
 private:
        ConfigWriter(void);
 
index 9afb2568121e2b589bc027c20aa6a06581637b57..ee652039fefe687ba1d554bb392ac26aea6f9a7a 100644 (file)
@@ -21,6 +21,7 @@
 #include "base/objectlock.hpp"
 #include "base/debug.hpp"
 #include "base/primitivetype.hpp"
+#include "base/configwriter.hpp"
 #include <boost/foreach.hpp>
 
 using namespace icinga;
@@ -198,3 +199,10 @@ std::vector<String> Dictionary::GetKeys(void) const
 
        return keys;
 }
+
+String Dictionary::ToString(void) const
+{
+       std::ostringstream msgbuf;
+       ConfigWriter::EmitScope(msgbuf, 0, const_cast<Dictionary *>(this));
+       return msgbuf.str();
+}
index 0556aa31f95ab9b3ff9b3515fea4dc9a4d6625fe..fd625a0480ee01f855e5fd8ebd6bc48e28cee12a 100644 (file)
@@ -115,6 +115,8 @@ public:
        
        virtual Object::Ptr Clone(void) const override;
 
+       virtual String ToString(void) const override;
+
 private:
        std::map<String, Value> m_Data; /**< The data for the dictionary. */
 };
index cea3f884deb262e677ca3370fb6e412bb70ce91b..801c5f8eead245dba08be1f136aa41522e43d51a 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "cli/consolecommand.hpp"
 #include "config/configcompiler.hpp"
+#include "base/configwriter.hpp"
 #include "base/json.hpp"
 #include "base/console.hpp"
 #include "base/application.hpp"
@@ -80,7 +81,7 @@ static char *ConsoleCompleteHelper(const char *word, int state)
        if (state == 0) {
                matches.clear();
 
-               BOOST_FOREACH(const String& keyword, ConfigCompiler::GetKeywords()) {
+               BOOST_FOREACH(const String& keyword, ConfigWriter::GetKeywords()) {
                        AddSuggestion(matches, word, keyword);
                }
 
index 048250cf4b0b101aedaae13e79a592e7947dc397..72038ff1a373dcedb29aa5a9b8abf8fe6a4ba3db 100644 (file)
@@ -37,7 +37,6 @@ set(config_SOURCES
   applyrule.cpp
   configcompilercontext.cpp configcompiler.cpp configitembuilder.cpp
   configitem.cpp ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS}
-  configwriter.cpp
   expression.cpp objectrule.cpp
 )
 
index 12ce409188e8502a26eb7224e05da6e01be7f026..688f506817cc284106580d1b6d59dde2921b9c16 100644 (file)
@@ -320,43 +320,3 @@ void ConfigCompiler::RegisterZoneDir(const String& tag, const String& ppath, con
        m_ZoneDirs[zoneName].push_back(zf);
 }
 
-const std::vector<String>& ConfigCompiler::GetKeywords(void)
-{
-       static std::vector<String> keywords;
-
-       if (keywords.empty()) {
-               keywords.push_back("object");
-               keywords.push_back("template");
-               keywords.push_back("include");
-               keywords.push_back("include_recursive");
-               keywords.push_back("include_zones");
-               keywords.push_back("library");
-               keywords.push_back("null");
-               keywords.push_back("true");
-               keywords.push_back("false");
-               keywords.push_back("const");
-               keywords.push_back("var");
-               keywords.push_back("this");
-               keywords.push_back("globals");
-               keywords.push_back("locals");
-               keywords.push_back("use");
-               keywords.push_back("ignore_on_error");
-               keywords.push_back("apply");
-               keywords.push_back("to");
-               keywords.push_back("where");
-               keywords.push_back("import");
-               keywords.push_back("assign");
-               keywords.push_back("ignore");
-               keywords.push_back("function");
-               keywords.push_back("return");
-               keywords.push_back("break");
-               keywords.push_back("continue");
-               keywords.push_back("for");
-               keywords.push_back("if");
-               keywords.push_back("else");
-               keywords.push_back("while");
-               keywords.push_back("throw");
-       }
-
-       return keywords;
-}
index 66e8df177f67a328f64b2f8382332f7eb5d1ac11..154717766043e8fcfb279d91716a2622f7b6576e 100644 (file)
@@ -118,8 +118,6 @@ public:
        static std::vector<ZoneFragment> GetZoneDirs(const String& zone);
        static void RegisterZoneDir(const String& tag, const String& ppath, const String& zoneName);
 
-       static const std::vector<String>& GetKeywords(void);
-
 private:
        boost::promise<boost::shared_ptr<Expression> > m_Promise;
 
index a240b6944da5d129d44da876ac393c08cbf472f6..0320460c370a02474f6eacdc326fdfddf0f4157d 100644 (file)
@@ -21,8 +21,8 @@
 #include "icinga/icingaapplication.tcpp"
 #include "icinga/cib.hpp"
 #include "icinga/macroprocessor.hpp"
-#include "config/configwriter.hpp"
 #include "config/configcompiler.hpp"
+#include "base/configwriter.hpp"
 #include "base/configtype.hpp"
 #include "base/logger.hpp"
 #include "base/objectlock.hpp"
index cd83d87bdb29a723598ef1215a7321ade38532ad..3254514036b34f9b4bbfc81a678972b1a0edea49 100644 (file)
@@ -21,7 +21,7 @@
 #include "remote/configpackageutility.hpp"
 #include "config/configcompiler.hpp"
 #include "config/configitem.hpp"
-#include "config/configwriter.hpp"
+#include "base/configwriter.hpp"
 #include "base/exception.hpp"
 #include "base/serializer.hpp"
 #include "base/dependencygraph.hpp"