Describers set restrictions on properties.
Mapped to std::nullptr_t
prop<Type::Nil>();
No restrictions available.
Mapped to bool
prop<Type::Bool>();
No restrictions available.
Mapped to integer types such as int
, long
, unsigned int
, etc.
prop<Type::Int>()
.multipleOf(3)
.interval(5 < x <= 42)
.withClamp();
Value is restricted to multiples of the given value.
Value is restricted to the given interval.
Validation passes even if the value is not in the specified interval. Instead, when the value is accessed, it is clamped to fit the interval.
Mapped to floating point types such as float
, double
, long double
, etc.
prop<Type::Num>()
.multipleOf(0.2)
.interval(2.718 < x <= 3.14)
.withClamp();
Value is restricted to multiples of the given value.
Value is restricted to the given interval.
Validation passes even if the value is not in the specified interval. Instead, when the value is accessed, it is clamped to fit the interval.
Mapped to std::string
.
prop<Type::Str>()
.oneOf({"foo", "bar", "baz"})
.length(2 < x <= 7);
Value is restricted to one of the given values.
Length of the value is restricted to the given interval.
Mapped to std::unordered_map<std::string, P::StorageType>
.
prop<Type::Map>()
.of(
prop<Type::Int>()
.multipleOf(7)
)
.containing({"foo", "bar", "baz"});
// Shorthand
prop<Type::Map>().of<Type::Int>
.containing({"foo", "bar", "baz"});
Value is restricted to contain the given keys.
No type is mapped. Accessible only by Node.
Node node(...);
node["foo"].is<Type::Int>().interval(0 < x).withDefault(2);
node[req("bar")].is<Type::Str>().oneOf({"get", "set"});
node["baz"].is<Type::Map>().of<Type::Str>();
Value is restricted to contain the given key.
Mapped to struct V
.
struct V {
int foo;
std::optional<std::string> bar;
std::vector<double> baz;
};
prop<Type::Map>().to<V>()
| field("foo", &V::foo)
| field("bar", &V::bar)
| field("baz", &V::baz, prop<Num>().interval(0 < x));
Value is restricted to contain the given key with the given type. The key can be omitted if the given type is instance of std::optional
.
Mapped to std::array<P::StorageType, N>
.
prop<Type::List>()
.of<3>(
prop<Type::Str>()
.length(3 < x < 12)
);
// Shorthand
prop<Type::List>().of<Type::Int, 3>();
No restrictions available.
Mapped to std::vector<P::StorageType>
.
prop<Type::List>()
.of(
prop<Type::Str>()
.oneOf({"foo", "bar", "baz"})
)
.size(x < 13);
// Shorthand
prop<Type::List>().of<Type::Int>()
.size(x < 13);
Size of the value is restricted to the given interval.