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