1 : // Copyright 2011 Google Inc.
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 : // Version defines.
16 : #ifndef SYZYGY_COMMON_SYZYGY_VERSION_H_
17 : #define SYZYGY_COMMON_SYZYGY_VERSION_H_
18 :
19 : #include <string>
20 : #include "base/basictypes.h"
21 : #include "base/logging.h"
22 : #include "syzygy/common/version.gen"
23 :
24 : namespace common {
25 :
26 : class SyzygyVersion {
27 : public:
28 : SyzygyVersion();
29 :
30 : SyzygyVersion(uint16 major, uint16 minor, uint16 build, uint16 patch,
31 : const char* last_change);
32 :
33 : // A comparison operator. If this version is less than @p rhs, returns a value
34 : // less than zero. If identical, returns 0. If greater than @p rhs, returns a
35 : // value greater than 0. This only compares the version octet, ignoring the
36 : // last-change string.
37 : int CompareOctet(const SyzygyVersion& rhs) const;
38 :
39 : // We need an equality operator for serialization testing. This uses strict
40 : // equality, including a comparison of the last change string.
41 : bool operator==(const SyzygyVersion& rhs) const;
42 : bool operator!=(const SyzygyVersion& rhs) const { return !(*this == rhs); }
43 :
44 : // This returns true if the data/modules created by the given version of the
45 : // toolchain are compatible with this version of the toolchain. For now, this
46 : // returns true iff the two versions are completely identical, including the
47 : // last-change string.
48 : bool IsCompatible(const SyzygyVersion& rhs) const;
49 :
50 : // Returns the whole version as a version string.
51 : std::string GetVersionString() const;
52 :
53 E : uint16 major() const { return major_; }
54 E : uint16 minor() const { return minor_; }
55 E : uint16 build() const { return build_; }
56 E : uint16 patch() const { return patch_; }
57 E : const std::string& last_change() const { return last_change_; }
58 :
59 E : void set_major(uint16 major) { major_ = major; }
60 E : void set_minor(uint16 minor) { minor_ = minor; }
61 E : void set_build(uint16 build) { build_ = build; }
62 E : void set_patch(uint16 patch) { patch_ = patch; }
63 E : void set_last_change(const char* last_change) {
64 E : DCHECK(last_change != NULL);
65 E : last_change_ = last_change;
66 E : }
67 :
68 : // For serialization. These are kept templated to remove any dependency
69 : // on core_lib, where serialization lives.
70 E : template<class OutArchive> bool Save(OutArchive* out_archive) const {
71 E : DCHECK(out_archive != NULL);
72 : return out_archive->Save(major_) && out_archive->Save(minor_) &&
73 : out_archive->Save(build_) && out_archive->Save(patch_) &&
74 E : out_archive->Save(last_change_);
75 E : }
76 E : template<class InArchive> bool Load(InArchive* in_archive) {
77 E : DCHECK(in_archive != NULL);
78 : return in_archive->Load(&major_) && in_archive->Load(&minor_) &&
79 : in_archive->Load(&build_) && in_archive->Load(&patch_) &&
80 E : in_archive->Load(&last_change_);
81 E : }
82 :
83 : private:
84 : uint16 major_;
85 : uint16 minor_;
86 : uint16 build_;
87 : uint16 patch_;
88 : std::string last_change_;
89 : };
90 :
91 : extern const SyzygyVersion kSyzygyVersion;
92 :
93 : } // namespace common
94 :
95 : #endif // SYZYGY_COMMON_SYZYGY_VERSION_H_
|