ArmNN
 20.05
EncodeVersion.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <cstdint>
8 #include <string>
9 #include <ostream>
10 #include <sstream>
11 
12 namespace armnn
13 {
14 
15 namespace profiling
16 {
17 
18 constexpr inline uint32_t EncodeVersion(uint32_t major, uint32_t minor, uint32_t patch)
19 {
20  return (major << 22) | (minor << 12) | patch;
21 }
22 
23 // Encodes a semantic version https://semver.org/ into a 32 bit integer in the following fashion
24 //
25 // bits 22:31 major: Unsigned 10-bit integer. Major component of the schema version number.
26 // bits 12:21 minor: Unsigned 10-bit integer. Minor component of the schema version number.
27 // bits 0:11 patch: Unsigned 12-bit integer. Patch component of the schema version number.
28 //
29 class Version
30 {
31 public:
32  Version(uint32_t encodedValue)
33  {
34  m_Major = (encodedValue >> 22) & 1023;
35  m_Minor = (encodedValue >> 12) & 1023;
36  m_Patch = encodedValue & 4095;
37  }
38 
39  Version(uint32_t major, uint32_t minor, uint32_t patch) :
40  m_Major(major),
41  m_Minor(minor),
42  m_Patch(patch)
43  {}
44 
45  uint32_t GetEncodedValue()
46  {
47  return EncodeVersion(m_Major, m_Minor, m_Patch);
48  }
49 
50  uint32_t GetMajor() { return m_Major; }
51  uint32_t GetMinor() { return m_Minor; }
52  uint32_t GetPatch() { return m_Patch; }
53 
54  bool operator==(const Version& other) const
55  {
56  return m_Major == other.m_Major && m_Minor == other.m_Minor && m_Patch == other.m_Patch;
57  }
58 
59  std::string ToString() const
60  {
61  constexpr char separator = '.';
62 
63  std::stringstream stringStream;
64  stringStream << m_Major << separator << m_Minor << separator << m_Patch;
65 
66  return stringStream.str();
67  }
68 
69 private:
70  uint32_t m_Major;
71  uint32_t m_Minor;
72  uint32_t m_Patch;
73 };
74 
75 inline std::ostream& operator<<(std::ostream& os, const Version& version)
76 {
77  os << version.ToString();
78  return os;
79 }
80 
81 } // namespace profiling
82 
83 } // namespace armnn
bool operator==(const Version &other) const
Version(uint32_t encodedValue)
Copyright (c) 2020 ARM Limited.
constexpr uint32_t EncodeVersion(uint32_t major, uint32_t minor, uint32_t patch)
std::ostream & operator<<(std::ostream &os, const Version &version)
Version(uint32_t major, uint32_t minor, uint32_t patch)
std::string ToString() const