From feae80e5e4236654ea5a843197e05d9211869750 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 8 Nov 2023 14:07:58 +0100 Subject: codec-netcdf: Basic netcdf implementation --- c++/codec-netcdf/netcdf.h | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 c++/codec-netcdf/netcdf.h (limited to 'c++/codec-netcdf/netcdf.h') diff --git a/c++/codec-netcdf/netcdf.h b/c++/codec-netcdf/netcdf.h new file mode 100644 index 0000000..d579b7f --- /dev/null +++ b/c++/codec-netcdf/netcdf.h @@ -0,0 +1,93 @@ +#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; + } +}; +} -- cgit v1.2.3