|
1 | | -/* |
2 | | - * Copyright (C) 2016-2017, Egor Pugin |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - */ |
16 | | - |
17 | | -#pragma once |
18 | | - |
19 | | -#include "cppan_string.h" |
20 | | -#include "filesystem.h" |
21 | | - |
22 | | -#include <primitives/hash.h> |
23 | | - |
24 | | -#define LOCAL_VERSION_NAME "local" |
25 | | - |
26 | | -using ProjectId = uint64_t; |
27 | | -using ProjectVersionId = uint64_t; |
28 | | -using ProjectVersionNumber = int32_t; |
29 | | - |
30 | | -enum class VersionType |
31 | | -{ |
32 | | - Any, |
33 | | - Equal, |
34 | | - Version, |
35 | | - Branch, |
36 | | -}; |
37 | | - |
38 | | -struct Version |
39 | | -{ |
40 | | - // undef gcc symbols |
41 | | -#ifdef major |
42 | | -#undef major |
43 | | -#endif |
44 | | -#ifdef minor |
45 | | -#undef minor |
46 | | -#endif |
47 | | -#ifdef patch |
48 | | -#undef patch |
49 | | -#endif |
50 | | - |
51 | | - ProjectVersionNumber major = -1; |
52 | | - ProjectVersionNumber minor = -1; |
53 | | - ProjectVersionNumber patch = -1; |
54 | | - String branch; |
55 | | - VersionType type{ VersionType::Any }; |
56 | | - |
57 | | - Version(ProjectVersionNumber ma = -1, ProjectVersionNumber mi = -1, ProjectVersionNumber pa = -1); |
58 | | - Version(const String &s); |
59 | | - |
60 | | - String toAnyVersion() const; |
61 | | - String toString() const; |
62 | | - path toPath() const; |
63 | | - |
64 | | - bool isValid() const; |
65 | | - bool isBranch() const; |
66 | | - bool isVersion() const; |
67 | | - |
68 | | - // checks if this version can be rhs using upgrade rules |
69 | | - // does not check branches! |
70 | | - // rhs should be exact version |
71 | | - bool canBe(const Version &rhs) const; |
72 | | - |
73 | | - bool operator<(const Version &rhs) const; |
74 | | - bool operator==(const Version &rhs) const; |
75 | | - bool operator!=(const Version &rhs) const; |
76 | | - |
77 | | - static bool check_branch_name(const String &n, String *error = nullptr); |
78 | | -}; |
79 | | - |
80 | | -namespace std |
81 | | -{ |
82 | | - |
83 | | -template<> struct hash<Version> |
84 | | -{ |
85 | | - size_t operator()(const Version& v) const |
86 | | - { |
87 | | - if (!v.branch.empty()) |
88 | | - return std::hash<String>()(v.branch); |
89 | | - size_t h = 0; |
90 | | - hash_combine(h, v.major); |
91 | | - hash_combine(h, v.minor); |
92 | | - hash_combine(h, v.patch); |
93 | | - return h; |
94 | | - } |
95 | | -}; |
96 | | - |
97 | | -} |
| 1 | +/* |
| 2 | + * Copyright (C) 2016-2017, Egor Pugin |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#pragma once |
| 18 | + |
| 19 | +#include "cppan_string.h" |
| 20 | +#include "filesystem.h" |
| 21 | + |
| 22 | +#include <primitives/hash_combine.h> |
| 23 | + |
| 24 | +#define LOCAL_VERSION_NAME "local" |
| 25 | + |
| 26 | +using ProjectId = uint64_t; |
| 27 | +using ProjectVersionId = uint64_t; |
| 28 | +using ProjectVersionNumber = int32_t; |
| 29 | + |
| 30 | +enum class VersionType |
| 31 | +{ |
| 32 | + Any, |
| 33 | + Equal, |
| 34 | + Version, |
| 35 | + Branch, |
| 36 | +}; |
| 37 | + |
| 38 | +struct Version |
| 39 | +{ |
| 40 | + // undef gcc symbols |
| 41 | +#ifdef major |
| 42 | +#undef major |
| 43 | +#endif |
| 44 | +#ifdef minor |
| 45 | +#undef minor |
| 46 | +#endif |
| 47 | +#ifdef patch |
| 48 | +#undef patch |
| 49 | +#endif |
| 50 | + |
| 51 | + ProjectVersionNumber major = -1; |
| 52 | + ProjectVersionNumber minor = -1; |
| 53 | + ProjectVersionNumber patch = -1; |
| 54 | + String branch; |
| 55 | + VersionType type{ VersionType::Any }; |
| 56 | + |
| 57 | + Version(ProjectVersionNumber ma = -1, ProjectVersionNumber mi = -1, ProjectVersionNumber pa = -1); |
| 58 | + Version(const String &s); |
| 59 | + |
| 60 | + String toAnyVersion() const; |
| 61 | + String toString() const; |
| 62 | + path toPath() const; |
| 63 | + |
| 64 | + bool isValid() const; |
| 65 | + bool isBranch() const; |
| 66 | + bool isVersion() const; |
| 67 | + |
| 68 | + // checks if this version can be rhs using upgrade rules |
| 69 | + // does not check branches! |
| 70 | + // rhs should be exact version |
| 71 | + bool canBe(const Version &rhs) const; |
| 72 | + |
| 73 | + bool operator<(const Version &rhs) const; |
| 74 | + bool operator==(const Version &rhs) const; |
| 75 | + bool operator!=(const Version &rhs) const; |
| 76 | + |
| 77 | + static bool check_branch_name(const String &n, String *error = nullptr); |
| 78 | +}; |
| 79 | + |
| 80 | +namespace std |
| 81 | +{ |
| 82 | + |
| 83 | +template<> struct hash<Version> |
| 84 | +{ |
| 85 | + size_t operator()(const Version& v) const |
| 86 | + { |
| 87 | + if (!v.branch.empty()) |
| 88 | + return std::hash<String>()(v.branch); |
| 89 | + size_t h = 0; |
| 90 | + hash_combine(h, v.major); |
| 91 | + hash_combine(h, v.minor); |
| 92 | + hash_combine(h, v.patch); |
| 93 | + return h; |
| 94 | + } |
| 95 | +}; |
| 96 | + |
| 97 | +} |
0 commit comments