You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cannot implement custom parsing of n values in a single tag:
<gz:custom>0 0 0 0<gz:custom>
Cannot be parsed into a custom type (and can only be read as a sdf::Quaternion?). The problem comes from the fact that the parser uses an std::variant that is set on the library and cannot be extended.
An interesting solution to this would be to add a capacity to read an N valued std::array of arbitrary type
(which has operator >> defined).
But the code would not be easy to understand, and comes with issues if you are parsing uncommon data (not simple floats) that requires custom operator>>.
Implementation suggestion
Add a template that compiles when T is "parseable" and T is not in the variant.
template<typename T, unsignedint n>
boolParam::Get(std::array<T, n> &_value, sdf::Errors &_errors) const
{
std::holds_alternative<T>(this->dataPtr->value); // Check that T is parseable
T *value = std::get_if<std::vector<T>>(&this->dataPtr->value);
std::copy_n(value.begin(), n, _value.begin());
returntrue;
}
And add std::vector<std::variant> to the ParamVariant.
The text was updated successfully, but these errors were encountered:
Desired behavior
Cannot implement custom parsing of n values in a single tag:
Cannot be parsed into a custom type (and can only be read as a
sdf::Quaternion
?). The problem comes from the fact that the parser uses an std::variant that is set on the library and cannot be extended.An interesting solution to this would be to add a capacity to read an N valued std::array of arbitrary type
(which has
operator >>
defined).Alternatives considered
1 Using multiple tags
(I ended up using this)
This can get pretty long, especially in code as more coefficients are needed.
2 Hacking predefined types
Using any of:
But the code would not be easy to understand, and comes with issues if you are parsing uncommon data (not simple floats) that requires custom
operator>>
.Implementation suggestion
Add a template that compiles when T is "parseable" and T is not in the variant.
And add std::vector<std::variant> to the
ParamVariant
.The text was updated successfully, but these errors were encountered: