1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 /**************************************************************************
25 
26   Version.h
27 
28 
29   **************************************************************************/
30 
31 #pragma once
32 
33 namespace ts
34 {
35 /** Container for standard two part version number.
36  */
37 struct VersionNumber {
38   /// Construct invalid (0.0) version.
39   constexpr VersionNumber() = default;
40 
41   /// Construct explicit version.
42   constexpr explicit VersionNumber(unsigned short major, unsigned short minor = 0);
43 
44   // Can't use unadorned "major" because that's a macro.
45   unsigned short _major = 0; ///< Major version.
46   unsigned short _minor = 0; ///< Minor version.
47 };
48 
VersionNumber(unsigned short major,unsigned short minor)49 inline constexpr VersionNumber::VersionNumber(unsigned short major, unsigned short minor) : _major(major), _minor(minor) {}
50 
51 inline bool
52 operator<(VersionNumber const &lhs, VersionNumber const &rhs)
53 {
54   return lhs._major < rhs._major || (lhs._major == rhs._major && lhs._minor < rhs._minor);
55 }
56 
57 inline bool
58 operator==(VersionNumber const &lhs, VersionNumber const &rhs)
59 {
60   return lhs._major == rhs._major && lhs._minor == rhs._minor;
61 }
62 
63 inline bool
64 operator!=(VersionNumber const &lhs, VersionNumber const &rhs)
65 {
66   return !(lhs == rhs);
67 }
68 
69 inline bool
70 operator>(VersionNumber const &lhs, VersionNumber const &rhs)
71 {
72   return rhs < lhs;
73 }
74 
75 inline bool
76 operator<=(VersionNumber const &lhs, VersionNumber const &rhs)
77 {
78   return !(lhs > rhs);
79 }
80 
81 inline bool
82 operator>=(VersionNumber const &lhs, VersionNumber const &rhs)
83 {
84   return !(rhs > lhs);
85 }
86 
87 struct Version {
88   VersionNumber cacheDB;
89   VersionNumber cacheDir;
90 };
91 
92 /// Container for a module version.
93 struct ModuleVersion {
94   /// Type of module.
95   enum Type : unsigned char { PUBLIC, PRIVATE };
96 
97   constexpr ModuleVersion(unsigned char major, unsigned char minor, Type type = PUBLIC);
98   constexpr ModuleVersion(ModuleVersion const &base, Type type);
99 
100   /** Check if @a that is a version compatible with @a this.
101    *
102    * @param that Version to check against.
103    * @return @a true if @a that is compatible with @a this, @c false otherwise.
104    */
105   bool check(ModuleVersion const &that);
106 
107   Type _type           = PUBLIC; ///< The numeric value of the module version.
108   unsigned char _major = 0;      ///< Major version.
109   unsigned char _minor = 0;
110 };
111 
ModuleVersion(unsigned char major,unsigned char minor,ts::ModuleVersion::Type type)112 inline constexpr ModuleVersion::ModuleVersion(unsigned char major, unsigned char minor, ts::ModuleVersion::Type type)
113   : _type(type), _major(major), _minor(minor)
114 {
115 }
116 
ModuleVersion(ModuleVersion const & base,ts::ModuleVersion::Type type)117 inline constexpr ModuleVersion::ModuleVersion(ModuleVersion const &base, ts::ModuleVersion::Type type)
118   : _type(type), _major(base._major), _minor(base._minor)
119 {
120 }
121 
122 inline bool
check(ModuleVersion const & that)123 ModuleVersion::check(ModuleVersion const &that)
124 {
125   switch (_type) {
126   case PUBLIC:
127     return _major == that._major && _minor <= that._minor;
128   case PRIVATE:
129     return _major == that._major && _minor == that._minor;
130   }
131   return false;
132 };
133 
134 } // namespace ts
135 
136 class AppVersionInfo
137 {
138 public:
139   int defined;
140   char PkgStr[128];
141   char AppStr[128];
142   char VersionStr[128];
143   char BldNumStr[128];
144   char BldTimeStr[128];
145   char BldDateStr[128];
146   char BldMachineStr[128];
147   char BldPersonStr[128];
148   char BldCompileFlagsStr[128];
149   char FullVersionInfoStr[256];
150 
151   AppVersionInfo();
152   void setup(const char *pkg_name, const char *app_name, const char *app_version, const char *build_date, const char *build_time,
153              const char *build_machine, const char *build_person, const char *build_cflags);
154 };
155