From 83f4ebc0df25218d7969af0f78450ae01e4a20c9 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 20 Apr 2015 14:16:19 +0200 Subject: [PATCH] Fix compiler warnings w/ config validators fixes #9015 --- lib/icinga/checkable.cpp | 10 +++++++++- lib/icinga/checkable.ti | 3 --- lib/icinga/host.ti | 4 ++++ lib/icinga/service.ti | 4 ++++ tools/mkclass/classcompiler.cpp | 17 ++++++----------- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 75561bed1..6ec3294c3 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -19,6 +19,8 @@ #include "icinga/checkable.hpp" #include "icinga/checkable.tcpp" +#include "icinga/host.hpp" +#include "icinga/service.hpp" #include "base/objectlock.hpp" #include "base/utility.hpp" #include "base/exception.hpp" @@ -81,7 +83,13 @@ void Checkable::AddGroup(const String& name) { boost::mutex::scoped_lock lock(m_CheckableMutex); - Array::Ptr groups = GetGroups(); + Array::Ptr groups; + Host *host = dynamic_cast(this); + + if (host) + groups = host->GetGroups(); + else + groups = static_cast(this)->GetGroups(); if (groups && groups->Contains(name)) return; diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti index 6c868300e..749a26748 100644 --- a/lib/icinga/checkable.ti +++ b/lib/icinga/checkable.ti @@ -40,9 +40,6 @@ enum AcknowledgementType abstract class Checkable : CustomVarObject { - [config] Array::Ptr groups { - default {{{ return new Array(); }}} - }; [config, protected, required] name(CheckCommand) check_command (CheckCommandRaw); [config] int max_check_attempts (MaxCheckAttemptsRaw) { default {{{ return 3; }}} diff --git a/lib/icinga/host.ti b/lib/icinga/host.ti index 670f0b317..d0fde7902 100644 --- a/lib/icinga/host.ti +++ b/lib/icinga/host.ti @@ -25,6 +25,10 @@ namespace icinga class Host : Checkable { + [config] Array::Ptr groups { + default {{{ return new Array(); }}} + }; + [config] String display_name { get {{{ if (m_DisplayName.IsEmpty()) diff --git a/lib/icinga/service.ti b/lib/icinga/service.ti index a516fac7e..0f92ee6a8 100644 --- a/lib/icinga/service.ti +++ b/lib/icinga/service.ti @@ -37,6 +37,10 @@ class Service : Checkable < ServiceNameComposer { load_after Host; + [config] Array::Ptr groups { + default {{{ return new Array(); }}} + }; + [config] String display_name { get {{{ if (m_DisplayName.IsEmpty()) diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 1cd9b0514..1c1a6e611 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -645,14 +645,10 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& if (validatorType != ValidatorField) m_Impl << "const String& key, "; - bool static_known_attribute = false; - m_Impl << fieldType.GetArgumentType() << " value, std::vector& location, const ValidationUtils& utils)" << std::endl << "{" << std::endl; if (validatorType == ValidatorField) { - static_known_attribute = true; - bool required = false; for (std::vector::size_type i = 0; i < rules.size(); i++) { @@ -679,7 +675,7 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& } } - if (!static_known_attribute) + if (validatorType != ValidatorField) m_Impl << "\t" << "bool known_attribute = false;" << std::endl; bool type_check = false; @@ -703,11 +699,9 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& m_Impl << "\t\t" << "if (key != \"" << rule.Pattern << "\")" << std::endl; m_Impl << "\t\t\t" << "break;" << std::endl; - } else - static_known_attribute = true; + } - if (!static_known_attribute) - m_Impl << "\t\t" << "known_attribute = true;" << std::endl; + m_Impl << "\t\t" << "known_attribute = true;" << std::endl; } if (rule.IsName) { @@ -824,12 +818,13 @@ void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& } if (type_check || validatorType != ValidatorField) { - if (!static_known_attribute) + if (validatorType != ValidatorField) { m_Impl << "\t" << "if (!known_attribute)" << std::endl << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast(object), location, \"Invalid attribute: \" + key));" << std::endl << "\t" << "else" << std::endl; + } - m_Impl << (!static_known_attribute ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast(object), location, \"Invalid type.\"));" << std::endl; + m_Impl << (validatorType != ValidatorField ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast(object), location, \"Invalid type.\"));" << std::endl; } m_Impl << "}" << std::endl << std::endl;