#pragma once #include #include #include #include #include namespace saw { namespace encode { /** * Template type hint */ struct Netcdf {}; } /** * Class representing the files system netcdf file */ template class data { private: std::vector buff_; public: data(std::vector buff): buff_{std::move(buff)} {} template data(const std::array& arr): buff_{arr.begin(), arr.end()} {} std::vector& get_data() { return buff_; } const std::vector& get_data() const { return buff_; } }; template class codec{ static_assert(always_false, "NetCDF only supports Structs as a root object"); }; } #include "netcdf.tmpl.h" namespace saw { template class codec...>, encode::Netcdf> { private: using Schema = schema::Struct...>; public: SAW_FORBID_COPY(codec); SAW_DEFAULT_MOVE(codec); /** * Default constructor */ codec() = default; /** * Encoder function */ template error_or encode() { return make_error(); } /** * Decoder function */ template error_or decode(data& from_decode, data& to_decode) { int ncid{}; int rc{}; rc = nc_open_mem("forstio_internal_memory", NC_NOWRITE, from_decode.get_data().size(), &from_decode.get_data()[0], &ncid); if(rc != NC_NOERR){ // Don't know how to get the error, so fail critically. return make_error(); } auto eov = impl::netcdf_decode::decode(to_decode, ncid); nc_close(ncid); return eov; } }; }