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