Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Version.h
Go to the documentation of this file.
1 //===-- serialbox/core/Version.h ----------------------------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_VERSION_H
16 #define SERIALBOX_CORE_VERSION_H
17 
19 #include <string>
20 
21 namespace serialbox {
22 
25 
27 struct Version {
28 private:
29  static int getVersion() {
30  return SERIALBOX_VERSION_MAJOR * 100 + SERIALBOX_VERSION_MINOR * 10 + SERIALBOX_VERSION_PATCH;
31  }
32 
33 public:
34  Version() = delete;
35 
38  static std::string toString(int version) {
39  int major = version / 100;
40  int minor = (version - major * 100) / 10;
41  return Version::toString(major, minor, version - 100 * major - 10 * minor);
42  }
43 
44  static std::string toString(int major, int minor, int patch) {
45  return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch);
46  }
48 
53  static bool match(int version) noexcept { return version == getVersion(); }
55 
61  static bool isCompatible(int version) noexcept { return version <= getVersion(); }
63 };
64 
66 
67 } // namespace serialbox
68 
69 #endif
static std::string toString(int version)
Convert to string.
Definition: Version.h:38
Utility to deal with Serialbox versions.
Definition: Version.h:27
Namespace of the serialbox library.
Definition: Archive.h:25
static bool match(int version) noexcept
Check if the given version matches the current library version.
Definition: Version.h:53
static bool isCompatible(int version) noexcept
Check if the given version is compatible with the current library version (i.e. is older) ...
Definition: Version.h:61