1#ifndef TATOOINE_GEOMETRY_VTK_XML_DATA_ARRAY_H
2#define TATOOINE_GEOMETRY_VTK_XML_DATA_ARRAY_H
12#include <rapidxml.hpp>
23 std::optional<std::string>
m_name = {};
26 std::size_t
m_offset = std::numeric_limits<std::size_t>::max();
28 rapidxml::xml_node<>*
m_node =
nullptr;
45 if constexpr (std::invocable<
decltype(f), std::vector<std::int8_t>>) {
46 f(read<std::int8_t>());
50 if constexpr (std::invocable<
decltype(f), std::vector<std::uint8_t>>) {
51 f(read<std::uint8_t>());
55 if constexpr (std::invocable<
decltype(f), std::vector<std::int16_t>>) {
56 f(read<std::int16_t>());
60 if constexpr (std::invocable<
decltype(f), std::vector<std::uint16_t>>) {
61 f(read<std::uint16_t>());
65 if constexpr (std::invocable<
decltype(f), std::vector<std::int32_t>>) {
66 f(read<std::int32_t>());
70 if constexpr (std::invocable<
decltype(f), std::vector<std::uint32_t>>) {
71 f(read<std::uint32_t>());
75 if constexpr (std::invocable<
decltype(f), std::vector<std::int64_t>>) {
76 f(read<std::int64_t>());
80 if constexpr (std::invocable<
decltype(f), std::vector<std::uint64_t>>) {
81 f(read<std::uint64_t>());
85 if constexpr (std::invocable<
decltype(f), std::vector<float>>) {
90 if constexpr (std::invocable<
decltype(f), std::vector<double>>) {
95 throw std::runtime_error {
96 "[vtk::xml::data_array] could not visit data because data_type is "
100 throw std::runtime_error {
101 "[vtk::xml::data_array] could not visit data because no function "
107 template <
typename T>
108 auto read() const -> std::vector<T> {
111 return read_data_ascii<T>();
113 return read_data_binary<T>();
115 return read_data_appended<T>();
123 template <
typename T>
125 throw std::runtime_error{
"[vtk::xml::data_array] cannot read ascii"};
126 auto data = std::vector<T>{};
130 template <
typename T>
132 throw std::runtime_error{
"[vtk::xml::data_array] cannot read binary"};
133 auto data = std::vector<T>{};
137 template <
typename T>
140 auto data = std::vector<T>(num_bytes /
sizeof(T));
145 template <
typename T>
148 auto data = std::vector<T>(num_bytes /
sizeof(T));
Definition: byte_order.h:6
format
Definition: format.h:8
data_type
Definition: data_type.h:11
Definition: data_array.h:19
auto read_data_ascii() const
Definition: data_array.h:124
auto name() const
Definition: data_array.h:37
auto visit_data(auto &&f) const
Definition: data_array.h:42
auto read_data_appended() const
Definition: data_array.h:138
auto type() const
Definition: data_array.h:36
std::size_t m_num_components
Definition: data_array.h:24
auto read() const -> std::vector< T >
Definition: data_array.h:108
auto read_appended_data(char *data, std::size_t num_bytes) const -> void
auto read_appended_data() const
Definition: data_array.h:146
auto format() const
Definition: data_array.h:39
data_type m_type
Definition: data_array.h:22
xml::format m_format
Definition: data_array.h:25
auto read_data_binary() const
Definition: data_array.h:131
data_array(reader &r, rapidxml::xml_node<> *node)
std::size_t m_offset
Definition: data_array.h:26
auto offset() const
Definition: data_array.h:40
reader * m_reader
Definition: data_array.h:27
auto operator=(data_array const &) -> data_array &=default
std::optional< std::string > m_name
Definition: data_array.h:23
data_array(data_array const &)=default
rapidxml::xml_node * m_node
Definition: data_array.h:28
auto read_appended_data_size() const -> std::size_t
auto num_components() const
Definition: data_array.h:38