This example demonstrates how to publish configuration attributes of a skill element.
#include <xentara/config/Context.hpp>
#include <xentara/config/Errors.hpp>
#include <xentara/data/ReadHandle.hpp>
#include <xentara/model/Attribute.hpp>
#include <xentara/model/ElementCategory.hpp>
#include <xentara/model/ForEachAttributeFunction.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:
double factor { 1.0 };
double offset { 0.0 };
};
using namespace std::literals;
{
for (auto && [name, value] : jsonObject)
{
if (name == "factor"sv)
{
_factor = value.toNumber<double>();
}
else if (name == "offset"sv)
{
_offset = value.asNumber<double>();
}
else
{
}
}
}
{
return
function(kFactorAttribute) ||
function(kOffsetAttribute);
}
{
if (attribute == kFactorAttribute)
{
return sharedFromThis(&_factor);
}
if (attribute == kOffsetAttribute)
{
return sharedFromThis(&_offset);
}
}
A context used when loading skill elements.
Definition Context.hpp:56
static const DataType kFloatingPoint
A floating point value.
Definition DataType.hpp:54
A Xentara attribute.
Definition Attribute.hpp:29
@ ReadOnly
The attribute supports reading only.
A function object used to iterate over all the attributes of an element.
Definition ForEachAttributeFunction.hpp:25
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 makeReadHandle(const model::Attribute &attribute) const noexcept -> std::optional< data::ReadHandle >
Called by the framework to get a read handle for a specific attribute.
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.
virtual auto forEachAttribute(const model::ForEachAttributeFunction &function) const -> bool
Called by the framework to iterate over all the attributes.
A mixin class that enables getting a shared pointer from the this pointer.
Definition EnableSharedFromThis.hpp:18
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.