This example demonstrates how to load the configuration of a skill element.
#include "MyQuery.hpp"
#include <xentara/config/Context.hpp>
#include <xentara/config/Errors.hpp>
#include <xentara/model/ElementCategory.hpp>
#include <xentara/skill/Element.hpp>
#include <xentara/utils/core/Uuid.hpp>
#include <xentara/utils/json/decoder/Errors.hpp>
#include <xentara/utils/json/decoder/Object.hpp>
using namespace std::literals;
{
public:
{
}
protected:
private:
int _minimum { 0 };
int _maximum { 100 };
double _divisor { 1.0 };
};
{
for (auto && [name, value] : jsonObject)
{
if (name == "minimum"sv)
{
_minimum = value.toNumber<int>();
}
else if (name == "maximum"sv)
{
_maximum = value.asNumber<int>();
}
else if (name == "divisor"sv)
{
_divisor = value.asNumber<double>();
if (_divisor == 0)
{
utils::json::decoder::throwWithLocation(value,
"the divisor must not be 0");
}
}
else if (name == "query"sv)
{
resolver.submit(_query);
}
else
{
}
}
if (_maximum <= _minimum)
{
utils::json::decoder::throwWithLocation(jsonObject,
"the maximum must be strictly greater than the minimum");
}
}
A context used when loading skill elements.
Definition Context.hpp:56
Convenience subclass of Class that implements all callbacks.
Definition Element.hpp:1032
Base class for elements provided by a Xentara skill.
Definition Element.hpp:82
virtual auto load(utils::json::decoder::Object &jsonObject, config::Context &context) -> void
Called by the framework to load the element’s configuration from a JSON object.
virtual auto category() const noexcept -> model::ElementCategory=0
Callback for getting the element category.
auto throwUnknownParameterError(const utils::json::decoder::Name &name) -> void
Throws an exception denoting that a member of a JSON object is unknown.
ElementCategory
Different categories of Xentara elements.
Definition ElementCategory.hpp:20
@ SpecialPurpose
A skill element representing anything that does not fit into any of the other categories.