vitrio 0.3.1
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
image_metadata_value.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2
3#pragma once
4
5#include <vitrio/export.hpp>
6#include <vitrio/image_metadata_value_type.hpp>
7
8#include <cstddef>
9#include <cstdint>
10#include <string>
11#include <type_traits>
12
13namespace vitrio
14{
15
29{
30public:
38 template <
39 typename T,
40 typename std::enable_if<
41 std::is_integral<T>::value && !std::is_same<T, bool>::value,
42 int
43 >::type = 0
44 >
46
52 template <
53 typename T,
54 typename std::enable_if<
55 std::is_floating_point<T>::value,
56 int
57 >::type = 0
58 >
59 image_metadata_value(T value) noexcept;
60
66 VITRIO_API
67 image_metadata_value(std::string value) noexcept;
68
75 VITRIO_API
76 image_metadata_value(const char *value);
77
78 image_metadata_value(bool value) = delete;
79 image_metadata_value(std::nullptr_t value) = delete;
80
81 VITRIO_API
83 VITRIO_API
85 VITRIO_API
87
88 VITRIO_API
89 image_metadata_value& operator=(const image_metadata_value &other);
90 VITRIO_API
91 image_metadata_value& operator=(image_metadata_value &&other) noexcept;
92
98 VITRIO_API
99 image_metadata_value_type get_type() const noexcept;
100
108 VITRIO_API
109 const std::int64_t& get_integer() const;
110
120 VITRIO_API
121 const double& get_real() const;
122
130 VITRIO_API
131 const std::string& get_text() const;
132
139 friend bool operator==(
140 const image_metadata_value &lhs,
141 const image_metadata_value &rhs
142 ) noexcept
143 {
144 // What a value does not hold is kept as it is constructed, so the
145 // three compare whatever the type is.
146 return
147 lhs.m_type == rhs.m_type &&
148 lhs.m_integer == rhs.m_integer &&
149 lhs.m_real == rhs.m_real &&
150 lhs.m_text == rhs.m_text;
151 }
152
153 friend bool operator!=(
154 const image_metadata_value &lhs,
155 const image_metadata_value &rhs
156 ) noexcept
157 {
158 return !(lhs == rhs);
159 }
160
161private:
162 template <typename T>
163 static std::int64_t to_integer(T value, std::true_type is_signed) noexcept;
164 template <typename T>
165 static std::int64_t to_integer(T value, std::false_type is_signed);
166
167 VITRIO_API
168 static std::int64_t to_integer(std::uintmax_t value);
169
170 image_metadata_value_type m_type;
171 std::int64_t m_integer;
172 double m_real;
173 std::string m_text;
174};
175
176} // namespace vitrio
177
178#include "image_metadata_value.inl"
One value of the metadata of an image file: an integer, a real or a text.
Definition image_metadata_value.hpp:29
image_metadata_value(T value)
Construct an integer.
const std::string & get_text() const
Get this value as the text it is.
const std::int64_t & get_integer() const
Get this value as the integer it is.
image_metadata_value_type get_type() const noexcept
Get the type of this value.
image_metadata_value(T value) noexcept
Construct a real.
image_metadata_value(std::string value) noexcept
Construct a text.
const double & get_real() const
Get this value as the real it is.
image_metadata_value(const char *value)
Construct a text.