Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / base / MemoryPressureLevelMac.h
blob38cb49a4fd9171b5180b146c5709144a3e683db4
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/. */
7 #ifndef mozilla_MemoryPressureLevelMac_h
8 #define mozilla_MemoryPressureLevelMac_h
10 namespace mozilla {
12 #if defined(XP_DARWIN)
13 // An internal representation of the Mac memory-pressure level constants.
14 class MacMemoryPressureLevel {
15 public:
16 // Order enum values so that higher integer values represent higher
17 // memory pressure levels allowing comparison operators to be used.
18 enum class Value {
19 eUnset,
20 eUnexpected,
21 eNormal,
22 eWarning,
23 eCritical,
26 MacMemoryPressureLevel() : mValue(Value::eUnset) {}
27 MOZ_IMPLICIT MacMemoryPressureLevel(Value aValue) : mValue(aValue) {}
29 bool operator==(const Value& aRhsValue) const { return mValue == aRhsValue; }
30 bool operator==(const MacMemoryPressureLevel& aRhs) const {
31 return mValue == aRhs.mValue;
34 // Implement '<' and derive the other comparators from it.
35 bool operator<(const MacMemoryPressureLevel& aRhs) const {
36 return mValue < aRhs.mValue;
38 bool operator>(const MacMemoryPressureLevel& aRhs) const {
39 return aRhs < *this;
41 bool operator<=(const MacMemoryPressureLevel& aRhs) const {
42 return !(aRhs < *this);
44 bool operator>=(const MacMemoryPressureLevel& aRhs) const {
45 return !(*this < aRhs);
48 Value GetValue() { return mValue; }
49 bool IsNormal() { return mValue == Value::eNormal; }
50 bool IsUnsetOrNormal() { return IsNormal() || (mValue == Value::eUnset); }
51 bool IsWarningOrAbove() {
52 return (mValue == Value::eWarning) || (mValue == Value::eCritical);
55 const char* ToString() {
56 switch (mValue) {
57 case Value::eUnset:
58 return "Unset";
59 case Value::eUnexpected:
60 return "Unexpected";
61 case Value::eNormal:
62 return "Normal";
63 case Value::eWarning:
64 return "Warning";
65 case Value::eCritical:
66 return "Critical";
70 private:
71 Value mValue;
73 #endif
75 } // namespace mozilla
77 #endif // mozilla_MemoryPressureLevelMac_h