OGS
PropertyVectorMetaData.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <istream>
14#include <optional>
15#include <ostream>
16#include <string>
17
18#include "BaseLib/Logging.h"
19
20namespace MeshLib
21{
22namespace IO
23{
24
26{
27 std::string property_name;
35 unsigned long number_of_components;
36 unsigned long number_of_tuples;
37
38 template <typename T>
40 {
41 is_int_type = std::numeric_limits<T>::is_integer;
42 is_data_type_signed = std::numeric_limits<T>::is_signed;
43 data_type_size_in_bytes = sizeof(T);
44 }
45};
46
48 std::ostream& os, PropertyVectorMetaData const& pvmd)
49{
50 std::string::size_type s(pvmd.property_name.length());
51 os.write(reinterpret_cast<char*>(&s), sizeof(std::string::size_type));
52
53 os.write(
54 const_cast<char*>(
55 const_cast<PropertyVectorMetaData&>(pvmd).property_name.data()),
56 s);
57 os.write(reinterpret_cast<char*>(
58 &const_cast<PropertyVectorMetaData&>(pvmd).is_int_type),
59 sizeof(bool));
60 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
61 pvmd).is_data_type_signed),
62 sizeof(bool));
63 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
64 pvmd).data_type_size_in_bytes),
65 sizeof(unsigned long));
66 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
67 pvmd).number_of_components),
68 sizeof(unsigned long));
69 os.write(reinterpret_cast<char*>(
70 &const_cast<PropertyVectorMetaData&>(pvmd).number_of_tuples),
71 sizeof(unsigned long));
72}
73
75{
76 DBUG(
77 "name: '{:s}':\t is_int_data_type: {:d}, is_data_type_signed: "
78 "{:d}, data_type_size_in_bytes: {:d}, number of components / "
79 "tuples: {:d} / {:d}",
82 pvmd.number_of_tuples);
83}
84
85inline std::optional<PropertyVectorMetaData> readPropertyVectorMetaData(
86 std::istream& is)
87{
88 // read the size of the name of the PropertyVector
89 std::string::size_type s = 0;
90 if (!is.read(reinterpret_cast<char*>(&s), sizeof(std::string::size_type)))
91 {
92 return std::optional<PropertyVectorMetaData>();
93 }
94
96 char *dummy = new char[s];
97 if (!is.read(dummy, s))
98 {
99 return std::nullopt;
100 }
101 pvmd.property_name = std::string(dummy, s);
102 delete [] dummy;
103
104 if(!is.read(reinterpret_cast<char*>(&pvmd.is_int_type), sizeof(bool)))
105 return std::nullopt;
106 if(!is.read(reinterpret_cast<char*>(&pvmd.is_data_type_signed), sizeof(bool)))
107 return std::nullopt;
108 if(!is.read(reinterpret_cast<char*>(&pvmd.data_type_size_in_bytes),
109 sizeof(unsigned long)))
110 return std::nullopt;
111 if(!is.read(reinterpret_cast<char*>(&pvmd.number_of_components),
112 sizeof(unsigned long)))
113 return std::nullopt;
114 if(!is.read(reinterpret_cast<char*>(&pvmd.number_of_tuples),
115 sizeof(unsigned long)))
116 return std::nullopt;
117 return std::optional<PropertyVectorMetaData>(pvmd);
118}
119
121{
122 unsigned long offset;
123 unsigned long number_of_tuples;
124};
125
127 std::ostream& os, PropertyVectorPartitionMetaData const& pvpmd)
128{
129 os.write(reinterpret_cast<char*>(
130 &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
131 .offset),
132 sizeof(unsigned long));
133 os.write(reinterpret_cast<char*>(
134 &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
135 .number_of_tuples),
136 sizeof(unsigned long));
137}
138
139inline std::optional<PropertyVectorPartitionMetaData>
141{
143 if (!is.read(reinterpret_cast<char*>(&pvpmd.offset), sizeof(unsigned long)))
144 {
145 return std::optional<PropertyVectorPartitionMetaData>();
146 }
147 if (!is.read(reinterpret_cast<char*>(&pvpmd.number_of_tuples),
148 sizeof(unsigned long)))
149 {
150 return std::optional<PropertyVectorPartitionMetaData>();
151 }
152 return std::optional<PropertyVectorPartitionMetaData>(pvpmd);
153}
154} // namespace IO
155} // namespace MeshLib
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void writePropertyVectorPartitionMetaData(std::ostream &os, PropertyVectorPartitionMetaData const &pvpmd)
void writePropertyVectorMetaData(std::ostream &os, PropertyVectorMetaData const &pvmd)
std::optional< PropertyVectorMetaData > readPropertyVectorMetaData(std::istream &is)
std::optional< PropertyVectorPartitionMetaData > readPropertyVectorPartitionMetaData(std::istream &is)