libpressio 0.93.0
Loading...
Searching...
No Matches
printers.h
Go to the documentation of this file.
1#ifndef LIBPRESSIO_PRINTERS_H
2#define LIBPRESSIO_PRINTERS_H
3
4
5
6#include <iterator>
7#include <string>
8#include <ostream>
9#include "options.h"
10#include "data.h"
11#include "compressor.h"
12#include "pressio_dtype.h"
13#include "pressio_compressor.h"
14
22template <class CharT = char, class Traits = std::char_traits<CharT>>
23std::basic_ostream<CharT, Traits>&
24operator<<(std::basic_ostream<CharT, Traits>& out, pressio_thread_safety const& safety) {
25 switch(safety) {
26 case pressio_thread_safety_single: return out << "single";
27 case pressio_thread_safety_multiple: return out << "multiple";
28 case pressio_thread_safety_serialized: return out << "serialized";
29 default: throw std::logic_error("invalid thread safety");
30 }
31}
32
33
37template <class CharT = char, class Traits = std::char_traits<CharT>>
38std::basic_ostream<CharT, Traits>&
39operator<<(std::basic_ostream<CharT, Traits>& out, pressio_options_key_status const& safety) {
40 switch(safety) {
41 case pressio_options_key_set: return out << "set";
42 case pressio_options_key_exists: return out << "exists";
43 case pressio_options_key_does_not_exist: return out << "does not exist";
44 default: throw std::logic_error("invalid key status");
45 }
46}
47
52template <class CharT = char, class Traits = std::char_traits<CharT>>
54 template <class T>
58 int operator()(T const* begin, T const* end) {
59 out << '[';
60 std::copy( begin, end, std::ostream_iterator<T>(out, ", "));
61 out << ']';
62 return 0;
63 }
65 std::basic_ostream<CharT, Traits>& out;
66};
67
73template <class CharT = char, class Traits = std::char_traits<CharT>>
74print_elements_helper<CharT, Traits> print_elements(std::basic_ostream<CharT, Traits> &out) {
76}
77
83template <class CharT = char, class Traits = std::char_traits<CharT>>
84std::basic_ostream<CharT, Traits>&
85operator<<(std::basic_ostream<CharT, Traits>& out, pressio_data const& data) {
86
87 out << "data{ type=" << data.dtype();
88 out << " dims={";
89 for (auto const& dim : data.dimensions()) {
90 out << dim << ", ";
91 }
92 out << "} has_data=" ;
93 if(data.has_data() && data.num_elements() < 10 ) {
94 pressio_data_for_each<int>(data, print_elements(out));
95 out << '}';
96 } else {
97 out << std::boolalpha << data.has_data() << "}";
98 }
99
100 return out;
101}
102
108template <class CharT = char, class Traits = std::char_traits<CharT>>
109std::basic_ostream<CharT, Traits>&
110operator<<(std::basic_ostream<CharT, Traits>& out, enum pressio_option_type type) {
111 switch(type)
112 {
114 return out << "int8";
116 return out << "uint8";
118 return out << "int16";
120 return out << "uint16";
122 return out << "int32";
124 return out << "uint32";
126 return out << "int64";
128 return out << "uint64";
130 return out << "float";
132 return out << "double";
134 return out << "bool";
136 return out << "char*";
138 return out << "threadsafety";
140 return out << "dtype";
142 return out << "void*";
144 return out << "char*[]";
146 return out << "data";
147 default:
149 return out << "unset";
150 }
151}
152
158template <class CharT = char, class Traits = std::char_traits<CharT>>
159std::basic_ostream<CharT, Traits>&
160operator<<(std::basic_ostream<CharT, Traits>& out, pressio_option const& option) {
161 auto type = option.type();
162 out << "<" << type << "> = ";
163 if (option.has_value()) {
164 switch(type)
165 {
167 return out << int16_t{option.get_value<int8_t>()};
169 return out << uint16_t{option.get_value<uint8_t>()};
171 return out << std::boolalpha << option.get_value<bool>();
173 return out << option.get_value<int16_t>();
175 return out << option.get_value<uint16_t>();
177 return out << option.get_value<int32_t>();
179 return out << option.get_value<uint32_t>();
181 return out << option.get_value<int64_t>();
183 return out << option.get_value<uint64_t>();
185 return out << option.get_value<float>();
187 return out << option.get_value<double>();
189 return out << "\"" << option.get_value<std::string>() << "\"";
191 return out << option.get_value<userdata>();
193 {
194 auto const& values = option.get_value<std::vector<std::string>>();
195 out << "{";
196 for (auto const& value : values) {
197 out << value << ", ";
198 }
199 return out << "}";
200 }
202 return out << option.get_value<pressio_data>();
204 return out << option.get_value<pressio_thread_safety>();
206 return out << option.get_value<pressio_dtype>();
208 return out << "<empty>";
209 default:
210 return out << "<unsupported>";
211 }
212 } else {
213 return out << "<empty>" ;
214 }
215}
216
217
223template <class CharT = char, class Traits = std::char_traits<CharT>>
224std::basic_ostream<CharT, Traits>&
225operator<<(std::basic_ostream<CharT, Traits>& out, pressio_options const& options) {
226 for (auto const& option : options) {
227 out << option.first << " " << option.second << "\n" ;
228 }
229 return out;
230}
231
237template <class CharT = char, class Traits = std::char_traits<CharT>>
238std::basic_ostream<CharT, Traits>&
239operator<<(std::basic_ostream<CharT, Traits>& out, enum pressio_dtype type)
240{
241 switch (type) {
243 return out << "double";
245 return out << "float";
247 return out << "uint8_t";
249 return out << "uint16_t";
251 return out << "uint32_t";
253 return out << "uint64_t";
255 return out << "int8_t";
257 return out << "int16_t";
259 return out << "int32_t";
261 return out << "int64_t";
263 return out << "bool";
264 default:
266 return out << "byte";
267 }
268}
269
275template <class CharT = char, class Traits = std::char_traits<CharT>>
276std::basic_ostream<CharT, Traits>&
277operator<<(std::basic_ostream<CharT, Traits>& out, libpressio_compressor_plugin const& comp) {
278 return out << comp.prefix();
279}
280
281#endif /* end of include guard: LIBPRESSIO_PRINTERS_H */
Definition: compressor.h:22
virtual const char * prefix() const =0
Definition: userptr.h:29
an extension header for adding compressor plugins to libpressio
C++ pressio_data interface.
C++ pressio_options and pressio_option interfaces.
Compress, decompress, and configure pressio and lossless compressors.
pressio_thread_safety
Definition: pressio_compressor.h:268
@ pressio_thread_safety_multiple
Definition: pressio_compressor.h:274
@ pressio_thread_safety_serialized
Definition: pressio_compressor.h:272
@ pressio_thread_safety_single
Definition: pressio_compressor.h:270
Information on types used by libpressio.
pressio_dtype
Definition: pressio_dtype.h:16
@ pressio_byte_dtype
Definition: pressio_dtype.h:27
@ pressio_bool_dtype
Definition: pressio_dtype.h:28
@ pressio_double_dtype
Definition: pressio_dtype.h:17
@ pressio_int16_dtype
Definition: pressio_dtype.h:24
@ pressio_uint64_dtype
Definition: pressio_dtype.h:22
@ pressio_float_dtype
Definition: pressio_dtype.h:18
@ pressio_uint16_dtype
Definition: pressio_dtype.h:20
@ pressio_int64_dtype
Definition: pressio_dtype.h:26
@ pressio_int8_dtype
Definition: pressio_dtype.h:23
@ pressio_uint8_dtype
Definition: pressio_dtype.h:19
@ pressio_uint32_dtype
Definition: pressio_dtype.h:21
@ pressio_int32_dtype
Definition: pressio_dtype.h:25
pressio_option_type
Definition: pressio_options.h:57
@ pressio_option_uint8_type
Definition: pressio_options.h:67
@ pressio_option_charptr_array_type
Definition: pressio_options.h:65
@ pressio_option_charptr_type
Definition: pressio_options.h:62
@ pressio_option_data_type
Definition: pressio_options.h:66
@ pressio_option_int64_type
Definition: pressio_options.h:72
@ pressio_option_uint64_type
Definition: pressio_options.h:71
@ pressio_option_unset_type
Definition: pressio_options.h:64
@ pressio_option_float_type
Definition: pressio_options.h:60
@ pressio_option_bool_type
Definition: pressio_options.h:73
@ pressio_option_double_type
Definition: pressio_options.h:61
@ pressio_option_uint32_type
Definition: pressio_options.h:58
@ pressio_option_int32_type
Definition: pressio_options.h:59
@ pressio_option_int16_type
Definition: pressio_options.h:70
@ pressio_option_userptr_type
Definition: pressio_options.h:63
@ pressio_option_int8_type
Definition: pressio_options.h:68
@ pressio_option_uint16_type
Definition: pressio_options.h:69
@ pressio_option_threadsafety_type
Definition: pressio_options.h:75
@ pressio_option_dtype_type
Definition: pressio_options.h:74
pressio_options_key_status
Definition: pressio_options.h:27
@ pressio_options_key_does_not_exist
Definition: pressio_options.h:35
@ pressio_options_key_set
Definition: pressio_options.h:29
@ pressio_options_key_exists
Definition: pressio_options.h:32
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &out, pressio_thread_safety const &safety)
Definition: printers.h:24
print_elements_helper< CharT, Traits > print_elements(std::basic_ostream< CharT, Traits > &out)
Definition: printers.h:74
Definition: data.h:52
bool has_data() const
Definition: data.h:334
pressio_dtype dtype() const
Definition: data.h:341
size_t num_elements() const
Definition: data.h:432
std::vector< size_t > const & dimensions() const
Definition: data.h:367
Definition: options.h:80
enum pressio_option_type type() const
void * get_value() const
Definition: options.h:187
bool has_value() const
Definition: options.h:199
Definition: options.h:352
Definition: printers.h:53
int operator()(T const *begin, T const *end)
Definition: printers.h:58
std::basic_ostream< CharT, Traits > & out
Definition: printers.h:65