1*635a8641SAndroid Build Coastguard Worker // Copyright 2017 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_TEST_COPY_ONLY_INT_H_ 6*635a8641SAndroid Build Coastguard Worker #define BASE_TEST_COPY_ONLY_INT_H_ 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker #include "base/macros.h" 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker namespace base { 11*635a8641SAndroid Build Coastguard Worker 12*635a8641SAndroid Build Coastguard Worker // A copy-only (not moveable) class that holds an integer. This is designed for 13*635a8641SAndroid Build Coastguard Worker // testing containers. See also MoveOnlyInt. 14*635a8641SAndroid Build Coastguard Worker class CopyOnlyInt { 15*635a8641SAndroid Build Coastguard Worker public: data_(data)16*635a8641SAndroid Build Coastguard Worker explicit CopyOnlyInt(int data = 1) : data_(data) {} 17*635a8641SAndroid Build Coastguard Worker CopyOnlyInt(const CopyOnlyInt& other) = default; ~CopyOnlyInt()18*635a8641SAndroid Build Coastguard Worker ~CopyOnlyInt() { data_ = 0; } 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard Worker friend bool operator==(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { 21*635a8641SAndroid Build Coastguard Worker return lhs.data_ == rhs.data_; 22*635a8641SAndroid Build Coastguard Worker } 23*635a8641SAndroid Build Coastguard Worker 24*635a8641SAndroid Build Coastguard Worker friend bool operator!=(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { 25*635a8641SAndroid Build Coastguard Worker return !operator==(lhs, rhs); 26*635a8641SAndroid Build Coastguard Worker } 27*635a8641SAndroid Build Coastguard Worker 28*635a8641SAndroid Build Coastguard Worker friend bool operator<(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { 29*635a8641SAndroid Build Coastguard Worker return lhs.data_ < rhs.data_; 30*635a8641SAndroid Build Coastguard Worker } 31*635a8641SAndroid Build Coastguard Worker 32*635a8641SAndroid Build Coastguard Worker friend bool operator>(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { 33*635a8641SAndroid Build Coastguard Worker return rhs < lhs; 34*635a8641SAndroid Build Coastguard Worker } 35*635a8641SAndroid Build Coastguard Worker 36*635a8641SAndroid Build Coastguard Worker friend bool operator<=(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { 37*635a8641SAndroid Build Coastguard Worker return !(rhs < lhs); 38*635a8641SAndroid Build Coastguard Worker } 39*635a8641SAndroid Build Coastguard Worker 40*635a8641SAndroid Build Coastguard Worker friend bool operator>=(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { 41*635a8641SAndroid Build Coastguard Worker return !(lhs < rhs); 42*635a8641SAndroid Build Coastguard Worker } 43*635a8641SAndroid Build Coastguard Worker data()44*635a8641SAndroid Build Coastguard Worker int data() const { return data_; } 45*635a8641SAndroid Build Coastguard Worker 46*635a8641SAndroid Build Coastguard Worker private: 47*635a8641SAndroid Build Coastguard Worker volatile int data_; 48*635a8641SAndroid Build Coastguard Worker 49*635a8641SAndroid Build Coastguard Worker CopyOnlyInt(CopyOnlyInt&&) = delete; 50*635a8641SAndroid Build Coastguard Worker CopyOnlyInt& operator=(CopyOnlyInt&) = delete; 51*635a8641SAndroid Build Coastguard Worker }; 52*635a8641SAndroid Build Coastguard Worker 53*635a8641SAndroid Build Coastguard Worker } // namespace base 54*635a8641SAndroid Build Coastguard Worker 55*635a8641SAndroid Build Coastguard Worker #endif // BASE_TEST_COPY_ONLY_INT_H_ 56