File indexing completed on 2025-09-17 08:54:12
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <iostream>
0010
0011 #include <covfie/core/concepts.hpp>
0012 #include <covfie/core/field_view.hpp>
0013 #include <covfie/core/parameter_pack.hpp>
0014 #include <covfie/core/utility/binary_io.hpp>
0015
0016 namespace covfie {
0017 template <concepts::field_backend _backend_t>
0018 class field
0019 {
0020 public:
0021 using backend_t = _backend_t;
0022 using view_t = field_view<backend_t>;
0023 using storage_t = typename backend_t::owning_data_t;
0024 using output_t = typename backend_t::covariant_output_t::vector_t;
0025 using coordinate_t = typename backend_t::contravariant_input_t::vector_t;
0026
0027 static constexpr uint32_t IO_MAGIC_HEADER = 0xAB000000;
0028
0029 field() = default;
0030 field(const field &) = default;
0031 field(field &&) = default;
0032
0033 template <concepts::field_backend other_backend>
0034 explicit field(field<other_backend> && other)
0035 : m_backend(std::move(other.m_backend))
0036 {
0037 }
0038
0039 template <concepts::field_backend other_backend>
0040 explicit field(const field<other_backend> & other)
0041 : m_backend(other.m_backend)
0042 {
0043 }
0044
0045 template <typename... Args>
0046 explicit field(parameter_pack<Args...> && args)
0047 : m_backend(std::forward<parameter_pack<Args...>>(args))
0048 {
0049 }
0050
0051 explicit field(const storage_t & backend)
0052 : m_backend(backend)
0053 {
0054 }
0055
0056 explicit field(storage_t && backend)
0057 : m_backend(std::move(backend))
0058 {
0059 }
0060
0061 explicit field(std::istream & fs)
0062 : m_backend(decltype(m_backend
0063 )::read_binary(utility::read_io_header(fs, IO_MAGIC_HEADER)))
0064 {
0065 utility::read_io_footer(fs, IO_MAGIC_HEADER);
0066 }
0067
0068 field & operator=(const field &) = default;
0069
0070 field & operator=(field &&) = default;
0071
0072 const storage_t & backend(void) const
0073 {
0074 return m_backend;
0075 }
0076
0077 void dump(std::ostream & fs) const
0078 {
0079 utility::write_io_header(fs, IO_MAGIC_HEADER);
0080 backend_t::owning_data_t::write_binary(fs, m_backend);
0081 utility::write_io_footer(fs, IO_MAGIC_HEADER);
0082 }
0083
0084 private:
0085 storage_t m_backend;
0086
0087 friend class field_view<_backend_t>;
0088
0089 template <concepts::field_backend other_backend>
0090 friend class field;
0091 };
0092 }