1 : // Copyright 2011 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/version/syzygy_version.h"
16 :
17 : #include "base/strings/stringprintf.h"
18 :
19 : namespace version {
20 :
21 : const SyzygyVersion kSyzygyVersion(SYZYGY_MAJOR, SYZYGY_MINOR, SYZYGY_BUILD,
22 E : SYZYGY_PATCH, SYZYGY_LASTCHANGE_FULL);
23 :
24 : SyzygyVersion::SyzygyVersion()
25 : : major_(0),
26 : minor_(0),
27 : build_(0),
28 E : patch_(0) {
29 E : }
30 :
31 : SyzygyVersion::SyzygyVersion(uint16 major, uint16 minor, uint16 build,
32 : uint16 patch, const char* last_change)
33 : : major_(major),
34 : minor_(minor),
35 : build_(build),
36 : patch_(patch),
37 E : last_change_(last_change) {
38 E : DCHECK(last_change != NULL);
39 E : }
40 :
41 E : int SyzygyVersion::CompareOctet(const SyzygyVersion& rhs) const {
42 E : int c = static_cast<int>(major_) - rhs.major_;
43 E : if (c != 0)
44 E : return c;
45 :
46 E : c = static_cast<int>(minor_) - rhs.minor_;
47 E : if (c != 0)
48 E : return c;
49 :
50 E : c = static_cast<int>(build_) - rhs.build_;
51 E : if (c != 0)
52 E : return c;
53 :
54 E : return static_cast<int>(patch_) - rhs.patch_;
55 E : }
56 :
57 E : bool SyzygyVersion::operator==(const SyzygyVersion& rhs) const {
58 : return major_ == rhs.major_ && minor_ == rhs.minor_ &&
59 : build_ == rhs.build_ && patch_ == rhs.patch_ &&
60 E : last_change_ == rhs.last_change_;
61 E : }
62 :
63 E : bool SyzygyVersion::IsCompatible(const SyzygyVersion& rhs) const {
64 : // Eventually, we may have reason to be less strict here.
65 E : return *this == rhs;
66 E : }
67 :
68 E : std::string SyzygyVersion::GetVersionString() const {
69 : std::string version =
70 E : base::StringPrintf("%d.%d.%d.%d", major_, minor_, build_, patch_);
71 : // Only append the last-change string if it is not empty.
72 E : if (!last_change_.empty()) {
73 E : version += base::StringPrintf(" (%.7s)", last_change_.c_str());
74 : }
75 E : return version;
76 E : }
77 :
78 : } // namespace version
|