LibreOffice Module onlineupdate (master) 1
nsVersionComparator.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#ifndef nsVersionComparator_h__
8#define nsVersionComparator_h__
9
10#include <stdlib.h>
11#include <string.h>
12#include <assert.h>
13#if defined(_WIN32) && !defined(UPDATER_NO_STRING_GLUE_STL)
14#include <wchar.h>
15#include <stdint.h>
16
17#endif
18
44namespace mozilla {
45
46int32_t CompareVersions(const char* aStrA, const char* aStrB);
47
48#ifdef _WIN32
49int32_t CompareVersions(const wchar_t* aStrA, const wchar_t* aStrB);
50#endif
51
52struct Version
53{
54 explicit Version(const char* aVersionString)
55 {
56 versionContent = strdup(aVersionString);
57 }
58
59 const char* ReadContent() const
60 {
61 return versionContent;
62 }
63
65 {
66 free(versionContent);
67 }
68
69 bool operator<(const Version& aRhs) const
70 {
71 return CompareVersions(versionContent, aRhs.ReadContent()) == -1;
72 }
73 bool operator<=(const Version& aRhs) const
74 {
75 return CompareVersions(versionContent, aRhs.ReadContent()) < 1;
76 }
77 bool operator>(const Version& aRhs) const
78 {
79 return CompareVersions(versionContent, aRhs.ReadContent()) == 1;
80 }
81 bool operator>=(const Version& aRhs) const
82 {
83 return CompareVersions(versionContent, aRhs.ReadContent()) > -1;
84 }
85 bool operator==(const Version& aRhs) const
86 {
87 return CompareVersions(versionContent, aRhs.ReadContent()) == 0;
88 }
89 bool operator!=(const Version& aRhs) const
90 {
91 return CompareVersions(versionContent, aRhs.ReadContent()) != 0;
92 }
93 bool operator<(const char* aRhs) const
94 {
95 return CompareVersions(versionContent, aRhs) == -1;
96 }
97 bool operator<=(const char* aRhs) const
98 {
99 return CompareVersions(versionContent, aRhs) < 1;
100 }
101 bool operator>(const char* aRhs) const
102 {
103 return CompareVersions(versionContent, aRhs) == 1;
104 }
105 bool operator>=(const char* aRhs) const
106 {
107 return CompareVersions(versionContent, aRhs) > -1;
108 }
109 bool operator==(const char* aRhs) const
110 {
111 return CompareVersions(versionContent, aRhs) == 0;
112 }
113 bool operator!=(const char* aRhs) const
114 {
115 return CompareVersions(versionContent, aRhs) != 0;
116 }
117
118private:
120};
121
122#ifdef _WIN32
123struct VersionW
124{
125 explicit VersionW(const wchar_t* aVersionStringW)
126 {
127 versionContentW =
128 reinterpret_cast<wchar_t*>(wcsdup(aVersionStringW));
129 }
130
131 const wchar_t* ReadContentW() const
132 {
133 return versionContentW;
134 }
135
136 ~VersionW()
137 {
138 free(versionContentW);
139 }
140
141 bool operator<(const VersionW& aRhs) const
142 {
143 return CompareVersions(versionContentW, aRhs.ReadContentW()) == -1;
144 }
145 bool operator<=(const VersionW& aRhs) const
146 {
147 return CompareVersions(versionContentW, aRhs.ReadContentW()) < 1;
148 }
149 bool operator>(const VersionW& aRhs) const
150 {
151 return CompareVersions(versionContentW, aRhs.ReadContentW()) == 1;
152 }
153 bool operator>=(const VersionW& aRhs) const
154 {
155 return CompareVersions(versionContentW, aRhs.ReadContentW()) > -1;
156 }
157 bool operator==(const VersionW& aRhs) const
158 {
159 return CompareVersions(versionContentW, aRhs.ReadContentW()) == 0;
160 }
161 bool operator!=(const VersionW& aRhs) const
162 {
163 return CompareVersions(versionContentW, aRhs.ReadContentW()) != 0;
164 }
165
166private:
167 wchar_t* versionContentW;
168};
169#endif
170
171} // namespace mozilla
172
173#endif // nsVersionComparator_h__
174
bool operator<=(const BigInt &rVal1, const BigInt &rVal2)
bool operator>=(const BigInt &rVal1, const BigInt &rVal2)
Compares two VersionParts.
int32_t CompareVersions(const char *aStrA, const char *aStrB)
bool operator>(const Style &rL, const Style &rR)
bool operator>=(const Version &aRhs) const
bool operator!=(const char *aRhs) const
bool operator>(const Version &aRhs) const
bool operator==(const Version &aRhs) const
bool operator<=(const Version &aRhs) const
bool operator<(const Version &aRhs) const
const char * ReadContent() const
bool operator<=(const char *aRhs) const
Version(const char *aVersionString)
bool operator>=(const char *aRhs) const
bool operator>(const char *aRhs) const
bool operator!=(const Version &aRhs) const
bool operator==(const char *aRhs) const
bool operator<(const char *aRhs) const
bool operator<(const wwFont &r1, const wwFont &r2)
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)