예제 #1
0
Value ScriptVariable::Get(const String& name)
{
	ScriptVariable::Ptr sv = GetByName(name);

	if (!sv)
		BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to access undefined script variable '" + name + "'"));

	return sv->GetData();
}
예제 #2
0
Value ScriptVariable::Get(const String& name)
{
	ScriptVariable::Ptr sv = GetByName(name);

	if (!sv) {
		Log(LogWarning, "icinga", "Tried to access undefined variable: " + name);
		return Empty;
	}

	return sv->GetData();
}
예제 #3
0
ScriptVariable::Ptr ScriptVariable::Set(const String& name, const Value& value, bool overwrite, bool make_const)
{
	ScriptVariable::Ptr sv = GetByName(name);

	if (!sv) {
		sv = make_shared<ScriptVariable>(value);
		ScriptVariableRegistry::GetInstance()->Register(name, sv);
	} else if (overwrite) {
		if (sv->IsConstant())
			BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to modify read-only script variable '" + name + "'"));

		sv->SetData(value);
	}

	if (make_const)
		sv->SetConstant(true);

	return sv;
}