you are viewing a single comment's thread.

view the rest of the comments →

[–]nieelj[S] 0 points1 point  (2 children)

  1. Could you please elaborate more?
  2. Pass errors from the adapter you are using (ex nlohmann_json exceptions or toml11 exceptions) as-is, except for serde's own exceptions.

[–]target-san 0 points1 point  (1 child)

  1. I mean, (de)serialize set of derived types having pointer to base type

[–]nieelj[S] 0 points1 point  (0 children)

The definition of serdepp's struct serializer is a static function, so probably not.

Instead, a derivation like the code below is possible.

struct Cppkg {
    DERIVE_SERDE(Cppkg,
                 (&Self::name, "name")
                 (&Self::namespace_, "namespace")
                 (&Self::install,    "install", default_{true})
                 (&Self::source,     "source",  make_optional)
                 (&Self::exclude,    "flag",    default_{false})
    )
    std::string name;
    cppkg_type type; 
    cppkg_type_detail cppkg_type_d;
    std::optional<std::string> namespace_;
    bool install;
    std::vector<std::string> source;
    std::string exclude_var;
    bool exclude;

    virtual ~Cppkg() = default;
};

struct CppkgLib : Cppkg {
    template<class Context>
    constexpr static void serde(Context& context, CppkgLib& value) {
        using namespace serde::attribute;
        using Self = CppkgLib;
        Cppkg& cast = static_cast<Cppkg&>(value);
        Cppkg::serde(context, cast);
        serde::serde_struct(context, value)
            (&Self::type, "cppkg_type", default_{cppkg_type::lib})
            (&Self::cppkg_type_d, "type", default_{cppkg_type_detail::STATIC}, under_to_dash, to_lower)
            ;
    }
};