LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
datasize.h
Go to the documentation of this file.
1 
15 #ifndef LARDATAALG_UTILITIES_QUANTITIES_DATASIZE_H
16 #define LARDATAALG_UTILITIES_QUANTITIES_DATASIZE_H
17 
18 // LArSoft libraries
20 
21 // C/C++ standard libraries
22 #include <ratio>
23 #include <string_view>
24 
25 //------------------------------------------------------------------------------
26 namespace util::quantities {
27 
28  namespace units {
29 
30  using namespace std::string_view_literals; // for operator""sv()
31 
32  struct Byte : public concepts::UnitBase {
33  static constexpr auto symbol = "B"sv;
34  static constexpr auto name = "byte"sv;
35  };
36 
37  } // namespace units
38 
39  namespace prefixes {
40 
42  using kibi = std::ratio<(1LL << 10)>;
43 
45  using mebi = std::ratio<(1LL << 20)>;
46 
48  using gibi = std::ratio<(1LL << 30)>;
49 
51  using tebi = std::ratio<(1LL << 40)>;
52 
54  using pebi = std::ratio<(1LL << 50)>;
55 
57  using exbi = std::ratio<(1LL << 60)>;
58 
59  } // namespace prefixes
60 
61  // -- BEGIN Data size --------------------------------------------------------
76 
79  template <typename R, typename T = unsigned long long int>
81 
82  //
83  // byte
84  //
86  template <typename T = unsigned long long int>
88 
90  template <typename T = unsigned long long int>
92 
94  using byte = byte_as<>;
95 
97  using bytes = byte;
98 
99  //
100  // kibibyte
101  //
103  template <typename T = unsigned long long int>
105 
107  template <typename T = unsigned long long int>
109 
112 
115 
116  //
117  // mebibyte
118  //
120  template <typename T = unsigned long long int>
122 
124  template <typename T = unsigned long long int>
126 
129 
132 
133  //
134  // gibibyte
135  //
137  template <typename T = unsigned long long int>
139 
141  template <typename T = unsigned long long int>
143 
146 
149 
150  //
151  // tebibyte
152  //
154  template <typename T = unsigned long long int>
156 
158  template <typename T = unsigned long long int>
160 
163 
166 
167  //
168  // pebibyte
169  //
171  template <typename T = unsigned long long int>
173 
175  template <typename T = unsigned long long int>
177 
180 
183 
184  //
185  // exbibyte
186  //
188  template <typename T = unsigned long long int>
190 
192  template <typename T = unsigned long long int>
194 
197 
200 
219  namespace datasize_literals {
220 
221  // @{
223  constexpr byte operator""_B(long double v)
224  {
225  return byte{static_cast<unsigned long long int>(v)};
226  }
227  constexpr byte operator""_B(unsigned long long int v)
228  {
229  return byte{v};
230  }
231  // @}
232 
233  // @{
235  constexpr kibibyte operator""_kiB(long double v)
236  {
237  return kibibyte{static_cast<unsigned long long int>(v)};
238  }
239  constexpr kibibyte operator""_kiB(unsigned long long int v)
240  {
241  return kibibyte{v};
242  }
243  // @}
244 
245  // @{
247  constexpr mebibyte operator""_MiB(long double v)
248  {
249  return mebibyte{static_cast<unsigned long long int>(v)};
250  }
251  constexpr mebibyte operator""_MiB(unsigned long long int v)
252  {
253  return mebibyte{v};
254  }
255  // @}
256 
257  // @{
259  constexpr gibibyte operator""_GiB(long double v)
260  {
261  return gibibyte{static_cast<unsigned long long int>(v)};
262  }
263  constexpr gibibyte operator""_GiB(unsigned long long int v)
264  {
265  return gibibyte{v};
266  }
267  // @}
268 
269  // @{
271  constexpr tebibyte operator""_TiB(long double v)
272  {
273  return tebibyte{static_cast<unsigned long long int>(v)};
274  }
275  constexpr tebibyte operator""_TiB(unsigned long long int v)
276  {
277  return tebibyte{v};
278  }
279  // @}
280 
281  // @{
283  constexpr pebibyte operator""_PiB(long double v)
284  {
285  return pebibyte{static_cast<unsigned long long int>(v)};
286  }
287  constexpr pebibyte operator""_PiB(unsigned long long int v)
288  {
289  return pebibyte{v};
290  }
291  // @}
292 
293  // @{
295  constexpr exbibyte operator""_EiB(long double v)
296  {
297  return exbibyte{static_cast<unsigned long long int>(v)};
298  }
299  constexpr exbibyte operator""_EiB(unsigned long long int v)
300  {
301  return exbibyte{v};
302  }
303  // @}
304 
305  } // datasize_literals
306 
308  // -- END Data size ----------------------------------------------------------
309 
310 } // namespace util::quantities
311 
312 //------------------------------------------------------------------------------
313 //--- Template specializations
314 //------------------------------------------------------------------------------
315 namespace util::quantities::concepts {
316 
318  template <>
319  struct Prefix<prefixes::kibi> {
320 
322  static constexpr auto symbol() { return "ki"sv; }
323 
325  static constexpr auto name() { return "kibi"sv; }
326 
327  }; // struct Prefix<prefixes::kibi>
328 
330  template <>
331  struct Prefix<prefixes::mebi> {
332 
334  static constexpr auto symbol() { return "Mi"sv; }
335 
337  static constexpr auto name() { return "mebi"sv; }
338 
339  }; // struct Prefix<prefixes::mebi>
340 
342  template <>
343  struct Prefix<prefixes::gibi> {
344 
346  static constexpr auto symbol() { return "Gi"sv; }
347 
349  static constexpr auto name() { return "gibi"sv; }
350 
351  }; // struct Prefix<prefixes::gibi>
352 
354  template <>
355  struct Prefix<prefixes::tebi> {
356 
358  static constexpr auto symbol() { return "Ti"sv; }
359 
361  static constexpr auto name() { return "tebi"sv; }
362 
363  }; // struct Prefix<prefixes::tebi>
364 
366  template <>
367  struct Prefix<prefixes::pebi> {
368 
370  static constexpr auto symbol() { return "Pi"sv; }
371 
373  static constexpr auto name() { return "pebi"sv; }
374 
375  }; // struct Prefix<prefixes::pebi>
376 
378  template <>
379  struct Prefix<prefixes::exbi> {
380 
382  static constexpr auto symbol() { return "Ei"sv; }
383 
385  static constexpr auto name() { return "exbi"sv; }
386 
387  }; // struct Prefix<prefixes::exbi>
388 
389 } // namespace util::quantities::concepts
390 
391 //------------------------------------------------------------------------------
392 
393 #endif // LARDATAALG_UTILITIES_QUANTITIES_DATASIZE_H
static constexpr auto name()
Returns the full name of the prefix.
Definition: datasize.h:325
static constexpr auto name()
Returns the full name of the prefix.
Definition: datasize.h:349
static constexpr auto symbol()
Returns the symbol of the prefix.
Definition: datasize.h:358
static constexpr auto symbol()
Returns the symbol of the prefix.
Definition: datasize.h:382
kibibyte_as<> kibibyte
Type of data size stored in kibibytes, in long long precision.
Definition: datasize.h:111
exbibyte_as<> exbibyte
Type of data size stored in exbibytes, in long long precision.
Definition: datasize.h:196
std::ratio<(1LL<< 60)> exbi
Factor 2^60.
Definition: datasize.h:57
std::ratio<(1LL<< 40)> tebi
Factor 2^40.
Definition: datasize.h:51
tebibyte_as<> tebibyte
Type of data size stored in tebibytes, in long long precision.
Definition: datasize.h:162
static constexpr auto symbol()
Returns the symbol of the prefix.
Definition: datasize.h:334
std::ratio<(1LL<< 30)> gibi
Factor 1&#39;073&#39;741&#39;824 (2^30).
Definition: datasize.h:48
static constexpr auto symbol()
Returns the symbol of the prefix.
Definition: datasize.h:346
static constexpr auto name()
Returns the full name of the prefix.
Definition: datasize.h:373
mebibyte_as<> mebibyte
Type of data size stored in mebibytes, in long long precision.
Definition: datasize.h:128
Infrastructure for the quantities library.
Definition: intervals.h:25
A value measured in the specified unit.
Definition: quantities.h:554
std::ratio<(1LL<< 50)> pebi
Factor 2^50.
Definition: datasize.h:54
static constexpr auto symbol()
Returns the symbol of the prefix.
Definition: datasize.h:322
static constexpr auto symbol()
Returns the symbol of the prefix.
Definition: datasize.h:370
Numeric variable proxies with embedded unit of measurement.
pebibyte_as<> pebibyte
Type of data size stored in pebibytes, in long long precision.
Definition: datasize.h:179
static constexpr auto name()
Returns the full name of the prefix.
Definition: datasize.h:385
byte_as<> byte
Type of data size stored in bytes, in long long precision.
Definition: datasize.h:94
static constexpr auto name()
Returns the full name of the prefix.
Definition: datasize.h:337
gibibyte_as<> gibibyte
Type of data size stored in pebibytes, in long long precision.
Definition: datasize.h:145
Types of variables with a unit.
Definition: intervals.h:20
std::ratio<(1LL<< 10)> kibi
Factor 1&#39;024 (2^10).
Definition: datasize.h:42
std::ratio<(1LL<< 20)> mebi
Factor 1&#39;048&#39;576 (2^20).
Definition: datasize.h:45
static constexpr auto name()
Returns the full name of the prefix.
Definition: datasize.h:361