2024-05-31 22:59:00 -04:00
|
|
|
#ifndef RFL_SIZE_HPP_
|
|
|
|
#define RFL_SIZE_HPP_
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "Ref.hpp"
|
|
|
|
#include "Result.hpp"
|
|
|
|
#include "parsing/Parser.hpp"
|
|
|
|
#include "parsing/schema/ValidationType.hpp"
|
|
|
|
|
|
|
|
namespace rfl {
|
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
template <class V>
|
|
|
|
struct Size {
|
|
|
|
template <class T>
|
|
|
|
static rfl::Result<T> validate(const T& _t) {
|
|
|
|
const auto to_t = [&](const auto& _v) { return _t; };
|
|
|
|
const auto embellish_error = [](const auto& _err) {
|
|
|
|
return Error("Size validation failed: " + _err.what());
|
|
|
|
};
|
|
|
|
return V::validate(_t.size()).transform(to_t).or_else(embellish_error);
|
|
|
|
}
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
template <class T>
|
|
|
|
static parsing::schema::ValidationType to_schema() {
|
|
|
|
return V::template to_schema<size_t>();
|
|
|
|
}
|
|
|
|
};
|
2024-05-31 22:59:00 -04:00
|
|
|
|
2024-06-08 14:10:59 -04:00
|
|
|
} // namespace rfl
|
2024-05-31 22:59:00 -04:00
|
|
|
|
|
|
|
#endif
|