]> granicus.if.org Git - icinga2/blobdiff - lib/config/configcompiler.cpp
Merge pull request #7113 from Elias481/fix/incorrect-usage-of-global-namespace-6874...
[icinga2] / lib / config / configcompiler.cpp
index 0df1cad5213c4e52f8c2d58ff412f004c254e954..8f450994fd5db6dd7dc0b8531942c8747473253f 100644 (file)
@@ -1,21 +1,4 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)  *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
+/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
 
 #include "config/configcompiler.hpp"
 #include "config/configitem.hpp"
@@ -40,10 +23,10 @@ std::map<String, std::vector<ZoneFragment> > ConfigCompiler::m_ZoneDirs;
  * @param input Input stream for the configuration file.
  * @param zone The zone.
  */
-ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
-       const String& zone, const String& package)
-       : m_Path(path), m_Input(input), m_Zone(zone), m_Package(package),
-       m_Eof(false), m_OpenBraces(0)
+ConfigCompiler::ConfigCompiler(String path, std::istream *input,
+       String zone, String package)
+       : m_Path(std::move(path)), m_Input(input), m_Zone(std::move(zone)),
+       m_Package(std::move(package)), m_Eof(false), m_OpenBraces(0)
 {
        InitializeScanner();
 }
@@ -51,7 +34,7 @@ ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
 /**
  * Destructor for the ConfigCompiler class.
  */
-ConfigCompiler::~ConfigCompiler(void)
+ConfigCompiler::~ConfigCompiler()
 {
        DestroyScanner();
 }
@@ -74,7 +57,7 @@ size_t ConfigCompiler::ReadInput(char *buffer, size_t max_size)
  *
  * @returns The scanner object.
  */
-void *ConfigCompiler::GetScanner(void) const
+void *ConfigCompiler::GetScanner() const
 {
        return m_Scanner;
 }
@@ -84,7 +67,7 @@ void *ConfigCompiler::GetScanner(void) const
  *
  * @returns The path.
  */
-const char *ConfigCompiler::GetPath(void) const
+const char *ConfigCompiler::GetPath() const
 {
        return m_Path.CStr();
 }
@@ -94,7 +77,7 @@ void ConfigCompiler::SetZone(const String& zone)
        m_Zone = zone;
 }
 
-String ConfigCompiler::GetZone(void) const
+String ConfigCompiler::GetZone() const
 {
        return m_Zone;
 }
@@ -104,7 +87,7 @@ void ConfigCompiler::SetPackage(const String& package)
        m_Package = package;
 }
 
-String ConfigCompiler::GetPackage(void) const
+String ConfigCompiler::GetPackage() const
 {
        return m_Package;
 }
@@ -339,6 +322,8 @@ bool ConfigCompiler::HasZoneConfigAuthority(const String& zoneName)
 
        if (!empty) {
                std::vector<String> paths;
+               paths.reserve(zoneDirs.size());
+
                for (const ZoneFragment& zf : zoneDirs) {
                        paths.push_back(zf.Path);
                }
@@ -360,3 +345,12 @@ bool ConfigCompiler::IsAbsolutePath(const String& path)
 #endif /* _WIN32 */
 }
 
+void ConfigCompiler::AddImport(const std::shared_ptr<Expression>& import)
+{
+       m_Imports.push_back(import);
+}
+
+std::vector<std::shared_ptr<Expression> > ConfigCompiler::GetImports() const
+{
+       return m_Imports;
+}