2012-07-09 20:32:02 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2012-07-06 14:33:10 +02:00
|
|
|
#include "i2-dyn.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
ConfigItemBuilder::ConfigItemBuilder(void)
|
|
|
|
: m_Local(false), m_Abstract(false),
|
|
|
|
m_ExpressionList(boost::make_shared<ExpressionList>())
|
|
|
|
{
|
|
|
|
m_DebugInfo.FirstLine = 0;
|
|
|
|
m_DebugInfo.FirstColumn = 0;
|
|
|
|
m_DebugInfo.LastLine = 0;
|
|
|
|
m_DebugInfo.LastColumn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigItemBuilder::ConfigItemBuilder(const DebugInfo& debugInfo)
|
|
|
|
: m_Local(false), m_Abstract(false),
|
|
|
|
m_ExpressionList(boost::make_shared<ExpressionList>())
|
|
|
|
{
|
|
|
|
m_DebugInfo = debugInfo;
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ConfigItemBuilder::SetType(const String& type)
|
2012-07-06 14:33:10 +02:00
|
|
|
{
|
|
|
|
m_Type = type;
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ConfigItemBuilder::SetName(const String& name)
|
2012-07-06 14:33:10 +02:00
|
|
|
{
|
|
|
|
m_Name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigItemBuilder::SetLocal(bool local)
|
|
|
|
{
|
|
|
|
m_Local = local;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigItemBuilder::SetAbstract(bool abstract)
|
|
|
|
{
|
|
|
|
m_Abstract = abstract;
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ConfigItemBuilder::AddParent(const String& parent)
|
2012-07-06 14:33:10 +02:00
|
|
|
{
|
|
|
|
m_Parents.push_back(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigItemBuilder::AddExpression(const Expression& expr)
|
|
|
|
{
|
|
|
|
m_ExpressionList->AddExpression(expr);
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ConfigItemBuilder::AddExpression(const String& key, ExpressionOperator op, const Value& value)
|
2012-07-06 14:33:10 +02:00
|
|
|
{
|
|
|
|
Expression expr(key, op, value, m_DebugInfo);
|
|
|
|
AddExpression(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigItemBuilder::AddExpressionList(const ExpressionList::Ptr& exprl)
|
|
|
|
{
|
|
|
|
AddExpression("", OperatorExecute, exprl);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
|
|
|
{
|
2012-08-02 09:38:08 +02:00
|
|
|
assert(!m_Type.IsEmpty());
|
|
|
|
assert(!m_Name.IsEmpty());
|
2012-07-06 14:33:10 +02:00
|
|
|
|
|
|
|
ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>();
|
|
|
|
|
|
|
|
Expression execExpr("", OperatorExecute, m_ExpressionList, m_DebugInfo);
|
|
|
|
exprl->AddExpression(execExpr);
|
|
|
|
|
|
|
|
Expression typeExpr("__type", OperatorSet, m_Type, m_DebugInfo);
|
|
|
|
exprl->AddExpression(typeExpr);
|
|
|
|
|
|
|
|
Expression nameExpr("__name", OperatorSet, m_Name, m_DebugInfo);
|
|
|
|
exprl->AddExpression(nameExpr);
|
|
|
|
|
|
|
|
Expression localExpr("__local", OperatorSet, m_Local, m_DebugInfo);
|
|
|
|
exprl->AddExpression(localExpr);
|
|
|
|
|
|
|
|
Expression abstractExpr("__abstract", OperatorSet, m_Abstract, m_DebugInfo);
|
|
|
|
exprl->AddExpression(abstractExpr);
|
|
|
|
|
|
|
|
return boost::make_shared<ConfigItem>(m_Type, m_Name, exprl, m_Parents, m_DebugInfo);
|
|
|
|
}
|