#pragma once #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::string path_; public: data(const std::string& path): path_{path} {} data(std::string&& path): path_{std::move(path)} {} std::string_view get_path_view() { return path_; } const std::string& get_path() const { return path_; } }; 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 void_t{}; } /** * Decoder function */ template error_or decode(data& from_decode, data& to_decode) { int ncid{}; int rc{}; rc = nc_open(from_decode.get_path().c_str(), NC_NOWRITE, &ncid); if(rc){ // 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; } }; }