Skip to content

Commit

Permalink
feat: improved support of fields of type 'any'
Browse files Browse the repository at this point in the history
Currently, types of 'any' are simply ignored when generating output.
This improves the handling of 'any' by adding explicit conversions to:

- float
- double
- char
- int8_t
- uint8_t
- int16_t
- uint16_t
- int32_t
- uint32_t
- int64_t
- uint64_t
and
- std::string

required to fix deNBI-cibi/tool_description_lib#59
  • Loading branch information
SGSSGene authored and mr-c committed Dec 4, 2024
1 parent 7e6d44d commit 86b620e
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions schema_salad/cpp_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,31 +700,52 @@ def epilogue(self, root_loader: Optional[TypeDef]) -> None:
}
// declaring toYaml
inline auto toYaml(bool v) {
return YAML::Node{v};
}
inline auto toYaml(float v) {
return YAML::Node{v};
}
inline auto toYaml(double v) {
return YAML::Node{v};
}
inline auto toYaml(int32_t v) {
return YAML::Node{v};
}
inline auto toYaml(int64_t v) {
return YAML::Node{v};
}
inline auto toYaml(std::any const&) {
return YAML::Node{};
}
inline auto toYaml(bool v) { return YAML::Node{v}; }
inline auto toYaml(float v) { return YAML::Node{v}; }
inline auto toYaml(double v) { return YAML::Node{v}; }
inline auto toYaml(char v) { return YAML::Node{v}; }
inline auto toYaml(int8_t v) { return YAML::Node{v}; }
inline auto toYaml(uint8_t v) { return YAML::Node{v}; }
inline auto toYaml(int16_t v) { return YAML::Node{v}; }
inline auto toYaml(uint16_t v) { return YAML::Node{v}; }
inline auto toYaml(int32_t v) { return YAML::Node{v}; }
inline auto toYaml(uint32_t v) { return YAML::Node{v}; }
inline auto toYaml(int64_t v) { return YAML::Node{v}; }
inline auto toYaml(uint64_t v) { return YAML::Node{v}; }
inline auto toYaml(std::monostate const&) {
return YAML::Node(YAML::NodeType::Undefined);
}
inline auto toYaml(std::string const& v) {
return YAML::Node{v};
}
template <typename T, typename ...Args>
auto anyToYaml_impl(std::any const& a) {
if (auto v = std::any_cast<T const>(&a)) {
return toYaml(*v);
}
if constexpr (sizeof...(Args) > 0) {
return anyToYaml_impl<Args...>(a);
}
return toYaml(std::monostate{});
}
inline auto toYaml(std::any const& a) {
return anyToYaml_impl<bool,
float,
double,
char,
int8_t,
uint8_t,
int16_t,
uint16_t,
int32_t,
uint32_t,
int64_t,
uint64_t,
std::string>(a);
}
// declaring fromYaml
inline void fromYaml(YAML::Node const& n, bool& v) {
v = n.as<bool>();
Expand Down

0 comments on commit 86b620e

Please sign in to comment.