weh
This commit is contained in:
parent
bd402f57f5
commit
3ea546fe08
166 changed files with 18360 additions and 18199 deletions
|
@ -28,31 +28,32 @@ namespace rfl {
|
|||
template <class T>
|
||||
struct has_from_flexbuf<
|
||||
T,
|
||||
std::enable_if_t<std::is_invocable_r<T,
|
||||
decltype(T::from_flexbuf),
|
||||
InputVarType>::value>>
|
||||
: std::true_type {};
|
||||
std::enable_if_t<
|
||||
std::is_invocable_r<T, decltype(T::from_flexbuf), InputVarType>::
|
||||
value>> : std::true_type {};
|
||||
|
||||
template <class T>
|
||||
struct has_from_flexbuf<
|
||||
T,
|
||||
std::enable_if_t<std::is_invocable_r<rfl::Result<T>,
|
||||
decltype(T::from_flexbuf),
|
||||
InputVarType>::value>>
|
||||
: std::true_type {};
|
||||
std::enable_if_t<std::is_invocable_r<
|
||||
rfl::Result<T>,
|
||||
decltype(T::from_flexbuf),
|
||||
InputVarType>::value>> : std::true_type {};
|
||||
|
||||
template <class T>
|
||||
static constexpr bool has_custom_constructor = has_from_flexbuf<T>::value;
|
||||
|
||||
rfl::Result<InputVarType> get_field(
|
||||
const std::string& _name,
|
||||
const InputObjectType& _obj) const noexcept {
|
||||
const std::string& _name,
|
||||
const InputObjectType& _obj
|
||||
) const noexcept {
|
||||
const auto keys = _obj.Keys();
|
||||
for (size_t i = 0; i < keys.size(); ++i) {
|
||||
if (_name == keys[i].AsString().c_str()) { return _obj.Values()[i]; }
|
||||
}
|
||||
return rfl::Error("Map does not contain any element called '" + _name +
|
||||
"'.");
|
||||
return rfl::Error(
|
||||
"Map does not contain any element called '" + _name + "'."
|
||||
);
|
||||
}
|
||||
|
||||
bool is_empty(const InputVarType& _var) const noexcept {
|
||||
|
@ -88,8 +89,9 @@ namespace rfl {
|
|||
|
||||
template <class ArrayReader>
|
||||
std::optional<Error> read_array(
|
||||
const ArrayReader& _array_reader,
|
||||
const InputArrayType& _arr) const noexcept {
|
||||
const ArrayReader& _array_reader,
|
||||
const InputArrayType& _arr
|
||||
) const noexcept {
|
||||
const auto size = _arr.size();
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
const auto err = _array_reader.read(InputVarType(_arr[i]));
|
||||
|
@ -100,37 +102,39 @@ namespace rfl {
|
|||
|
||||
template <class ObjectReader>
|
||||
std::optional<Error> read_object(
|
||||
const ObjectReader& _object_reader,
|
||||
const InputObjectType& _obj) const noexcept {
|
||||
const ObjectReader& _object_reader,
|
||||
const InputObjectType& _obj
|
||||
) const noexcept {
|
||||
const auto keys = _obj.Keys();
|
||||
const auto values = _obj.Values();
|
||||
const auto num_values = std::min(keys.size(), values.size());
|
||||
|
||||
for (size_t i = 0; i < num_values; ++i) {
|
||||
_object_reader.read(std::string_view(keys[i].AsString().c_str()),
|
||||
values[i]);
|
||||
_object_reader.read(
|
||||
std::string_view(keys[i].AsString().c_str()), values[i]
|
||||
);
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
rfl::Result<InputArrayType> to_array(
|
||||
const InputVarType& _var) const noexcept {
|
||||
rfl::Result<InputArrayType> to_array(const InputVarType& _var
|
||||
) const noexcept {
|
||||
if (!_var.IsVector()) {
|
||||
return rfl::Error("Could not cast to Vector.");
|
||||
}
|
||||
return _var.AsVector();
|
||||
}
|
||||
|
||||
rfl::Result<InputObjectType> to_object(
|
||||
const InputVarType& _var) const noexcept {
|
||||
rfl::Result<InputObjectType> to_object(const InputVarType& _var
|
||||
) const noexcept {
|
||||
if (!_var.IsMap()) { return rfl::Error("Could not cast to Map!"); }
|
||||
return _var.AsMap();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
rfl::Result<T> use_custom_constructor(
|
||||
const InputVarType& _var) const noexcept {
|
||||
rfl::Result<T> use_custom_constructor(const InputVarType& _var
|
||||
) const noexcept {
|
||||
try {
|
||||
return T::from_flexbuf(_var);
|
||||
} catch (std::exception& e) { return rfl::Error(e.what()); }
|
||||
|
|
|
@ -58,28 +58,32 @@ namespace rfl {
|
|||
}
|
||||
|
||||
OutputArrayType add_array_to_array(
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent
|
||||
) const noexcept {
|
||||
return new_array();
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string_view& _name,
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return new_array(_name);
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_array(
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent
|
||||
) const noexcept {
|
||||
return new_object();
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string_view& _name,
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return new_object(_name);
|
||||
}
|
||||
|
||||
|
@ -92,8 +96,9 @@ namespace rfl {
|
|||
template <class T>
|
||||
OutputVarType add_value_to_object(
|
||||
const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const T& _var,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return insert_value(_name, _var);
|
||||
}
|
||||
|
||||
|
@ -104,7 +109,8 @@ namespace rfl {
|
|||
|
||||
OutputVarType add_null_to_object(
|
||||
const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
fbb_->Null(_name.data());
|
||||
return OutputVarType {};
|
||||
}
|
||||
|
@ -119,8 +125,8 @@ namespace rfl {
|
|||
|
||||
private:
|
||||
template <class T>
|
||||
OutputVarType insert_value(const std::string_view& _name,
|
||||
const T& _var) const noexcept {
|
||||
OutputVarType insert_value(const std::string_view& _name, const T& _var)
|
||||
const noexcept {
|
||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||
fbb_->String(_name.data(), _var);
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||
|
@ -161,8 +167,8 @@ namespace rfl {
|
|||
return OutputArrayType {start};
|
||||
}
|
||||
|
||||
OutputObjectType new_object(
|
||||
const std::string_view& _name) const noexcept {
|
||||
OutputObjectType new_object(const std::string_view& _name
|
||||
) const noexcept {
|
||||
const auto start = fbb_->StartMap(_name.data());
|
||||
return OutputObjectType {start};
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace rfl {
|
|||
template <class T, class... Ps>
|
||||
auto read(std::istream& _stream) {
|
||||
std::istreambuf_iterator<char> begin(_stream), end;
|
||||
const auto bytes = std::vector<char>(begin, end);
|
||||
const auto bytes = std::vector<char>(begin, end);
|
||||
return read<T, Ps...>(bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,10 @@ namespace rfl {
|
|||
using T = std::remove_cvref_t<decltype(_obj)>;
|
||||
using ParentType = parsing::Parent<Writer>;
|
||||
const auto fbb = Ref<flexbuffers::Builder>::make();
|
||||
auto w = Writer(fbb);
|
||||
Parser<T, Processors<Ps...>>::write(w, _obj,
|
||||
typename ParentType::Root {});
|
||||
auto w = Writer(fbb);
|
||||
Parser<T, Processors<Ps...>>::write(
|
||||
w, _obj, typename ParentType::Root {}
|
||||
);
|
||||
fbb->Finish();
|
||||
return fbb->GetBuffer();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue