vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
image_location.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2
3#pragma once
4
5#include <vitrio/export.hpp>
6
7#include <cstddef>
8#include <limits>
9#include <ostream>
10#include <string>
11
12namespace vitrio
13{
14
29{
30public:
35 VITRIO_API
36 static constexpr std::size_t no_stack_index =
37 std::numeric_limits<std::size_t>::max();
38
47 VITRIO_API
49 std::string key,
50 std::size_t index_in_stack = no_stack_index
51 );
52
56 VITRIO_API
57 image_location() noexcept;
58 VITRIO_API
59 image_location(const image_location &other);
60 VITRIO_API
61 image_location(image_location &&other) noexcept;
62 VITRIO_API
64
65 VITRIO_API
66 image_location& operator=(const image_location &other);
67 VITRIO_API
68 image_location& operator=(image_location &&other) noexcept;
69
75 VITRIO_API
76 std::size_t hash() const noexcept;
77
85 VITRIO_API
86 const std::string& get_key() const noexcept;
87
95 VITRIO_API
96 std::size_t get_index_in_stack() const noexcept;
97
105 VITRIO_API
106 bool has_index_in_stack() const noexcept;
107
108 friend bool
109 operator==(const image_location &lhs, const image_location &rhs) noexcept
110 {
111 return
112 lhs.get_index_in_stack() == rhs.get_index_in_stack() &&
113 lhs.get_key() == rhs.get_key();
114 }
115
116 friend bool
117 operator!=(const image_location &lhs, const image_location &rhs) noexcept
118 {
119 return !(lhs == rhs);
120 }
121
122 friend bool
123 operator<(const image_location &lhs, const image_location &rhs) noexcept
124 {
125 if (lhs.get_key() < rhs.get_key())
126 {
127 return true;
128 }
129 else if (lhs.get_key() == rhs.get_key())
130 {
131 return lhs.get_index_in_stack() < rhs.get_index_in_stack();
132 }
133 return false;
134 }
135
136 friend bool
137 operator<=(const image_location &lhs, const image_location &rhs) noexcept
138 {
139 return !(rhs < lhs);
140 }
141
142 friend bool
143 operator>(const image_location &lhs, const image_location &rhs) noexcept
144 {
145 return rhs < lhs;
146 }
147
148 friend bool
149 operator>=(const image_location &lhs, const image_location &rhs) noexcept
150 {
151 return !(lhs < rhs);
152 }
153
154 friend std::ostream&
155 operator<<(std::ostream &os, const image_location &location)
156 {
157 if (location.has_index_in_stack())
158 {
159 os << (location.get_index_in_stack() + 1) << '@';
160 }
161 return os << location.get_key();
162 }
163
164private:
165 std::string m_key;
166 std::size_t m_index_in_stack;
167};
168
188VITRIO_API
189bool parse_image_location(const std::string &text, image_location &result);
190
201VITRIO_API
202std::string to_string(const image_location &location);
203
204} // namespace vitrio
205
206namespace std
207{
208
209template<>
210struct hash<vitrio::image_location>
211{
212 std::size_t operator()(
213 const vitrio::image_location &location
214 ) const noexcept
215 {
216 return location.hash();
217 }
218};
219
220} // namespace std
Address of an image file, or of one image or volume of a stack.
Definition image_location.hpp:29
const std::string & get_key() const noexcept
Get the key of the file.
std::size_t get_index_in_stack() const noexcept
Get the index of the image or volume within the stack.
image_location() noexcept
Construct a location with an empty key and no index.
static constexpr std::size_t no_stack_index
Index addressing the file as a whole rather than one image or volume of it.
Definition image_location.hpp:36
image_location(std::string key, std::size_t index_in_stack=no_stack_index)
Construct a location from its components.
std::size_t hash() const noexcept
Get the hash value for this location.
bool has_index_in_stack() const noexcept
Check whether this addresses one image or volume of its file rather than the file as a whole.