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
12 #if defined(XP_DARWIN)
13 // An internal representation of the Mac memory-pressure level constants.
14 class MacMemoryPressureLevel
{
16 // Order enum values so that higher integer values represent higher
17 // memory pressure levels allowing comparison operators to be used.
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 {
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() {
59 case Value::eUnexpected
:
65 case Value::eCritical
:
75 } // namespace mozilla
77 #endif // mozilla_MemoryPressureLevelMac_h