1 // Copyright (c) 2007-2008 Joseph Gauterin 2 // 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 // Tests class used by the Boost.Swap tests 8 9 #ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP 10 #define BOOST_UTILITY_SWAP_TEST_CLASS_HPP 11 12 13 class swap_test_class 14 { 15 int m_data; 16 public: swap_test_class(int arg=0)17 explicit swap_test_class(int arg = 0) 18 : 19 m_data(arg) 20 { 21 ++constructCount(); 22 } 23 ~swap_test_class()24 ~swap_test_class() 25 { 26 ++destructCount(); 27 } 28 swap_test_class(const swap_test_class & arg)29 swap_test_class(const swap_test_class& arg) 30 : 31 m_data(arg.m_data) 32 { 33 ++copyCount(); 34 ++destructCount(); 35 } 36 operator =(const swap_test_class & arg)37 swap_test_class& operator=(const swap_test_class& arg) 38 { 39 m_data = arg.m_data; 40 ++copyCount(); 41 return *this; 42 } 43 swap(swap_test_class & other)44 void swap(swap_test_class& other) 45 { 46 const int temp = m_data; 47 m_data = other.m_data; 48 other.m_data = temp; 49 50 ++swapCount(); 51 } 52 get_data() const53 int get_data() const 54 { 55 return m_data; 56 } 57 set_data(int arg)58 void set_data(int arg) 59 { 60 m_data = arg; 61 } 62 swap_count()63 static unsigned int swap_count(){ return swapCount(); } copy_count()64 static unsigned int copy_count(){ return copyCount(); } construct_count()65 static unsigned int construct_count(){ return constructCount(); } destruct_count()66 static unsigned int destruct_count(){ return destructCount(); } 67 reset()68 static void reset() 69 { 70 swapCount() = 0; 71 copyCount() = 0; 72 constructCount() = 0; 73 destructCount() = 0; 74 } 75 76 private: swapCount()77 static unsigned int& swapCount() 78 { 79 static unsigned int value = 0; 80 return value; 81 } 82 copyCount()83 static unsigned int& copyCount() 84 { 85 static unsigned int value = 0; 86 return value; 87 } 88 constructCount()89 static unsigned int& constructCount() 90 { 91 static unsigned int value = 0; 92 return value; 93 } 94 destructCount()95 static unsigned int& destructCount() 96 { 97 static unsigned int value = 0; 98 return value; 99 } 100 101 }; 102 103 operator ==(const swap_test_class & lhs,const swap_test_class & rhs)104inline bool operator==(const swap_test_class & lhs, const swap_test_class & rhs) 105 { 106 return lhs.get_data() == rhs.get_data(); 107 } 108 operator !=(const swap_test_class & lhs,const swap_test_class & rhs)109inline bool operator!=(const swap_test_class & lhs, const swap_test_class & rhs) 110 { 111 return !(lhs == rhs); 112 } 113 114 #endif 115