1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_COW_WRAPPER_CLIENTS_HXX 29 #define INCLUDED_COW_WRAPPER_CLIENTS_HXX 30 31 #include "o3tl/cow_wrapper.hxx" 32 33 /* Definition of Cow_Wrapper_Clients classes */ 34 35 namespace o3tltests { 36 37 /** This is a header and a separate compilation unit on purpose - 38 cow_wrapper needs destructor, copy constructor and assignment 39 operator to be outline, when pimpl idiom is used 40 */ 41 42 /// test non-opaque impl type 43 class cow_wrapper_client1 44 { 45 public: 46 cow_wrapper_client1() : maImpl() {} 47 explicit cow_wrapper_client1( int nVal ) : maImpl(nVal) {} 48 49 void modify( int nVal ) { *maImpl = nVal; } 50 int queryUnmodified() const { return *maImpl; } 51 52 void makeUnique() { maImpl.make_unique(); } 53 bool is_unique() const { return maImpl.is_unique(); } 54 oslInterlockedCount use_count() const { return maImpl.use_count(); } 55 void swap( cow_wrapper_client1& r ) { o3tl::swap(maImpl, r.maImpl); } 56 57 bool operator==( const cow_wrapper_client1& rRHS ) const { return maImpl == rRHS.maImpl; } 58 bool operator!=( const cow_wrapper_client1& rRHS ) const { return maImpl != rRHS.maImpl; } 59 bool operator<( const cow_wrapper_client1& rRHS ) const { return maImpl < rRHS.maImpl; } 60 61 private: 62 o3tl::cow_wrapper< int > maImpl; 63 }; 64 65 66 class cow_wrapper_client2_impl; 67 68 /** test opaque impl type - need to explicitely declare lifetime 69 methods 70 */ 71 class cow_wrapper_client2 72 { 73 public: 74 cow_wrapper_client2(); 75 explicit cow_wrapper_client2( int nVal ); 76 ~cow_wrapper_client2(); 77 78 cow_wrapper_client2( const cow_wrapper_client2& ); 79 cow_wrapper_client2& operator=( const cow_wrapper_client2& ); 80 81 void modify( int nVal ); 82 int queryUnmodified() const; 83 84 void makeUnique(); 85 bool is_unique() const; 86 oslInterlockedCount use_count() const; 87 void swap( cow_wrapper_client2& r ); 88 89 bool operator==( const cow_wrapper_client2& rRHS ) const; 90 bool operator!=( const cow_wrapper_client2& rRHS ) const; 91 bool operator<( const cow_wrapper_client2& rRHS ) const; 92 93 private: 94 o3tl::cow_wrapper< cow_wrapper_client2_impl > maImpl; 95 }; 96 97 /** test MT-safe cow_wrapper - basically the same as 98 cow_wrapper_client2, only with different refcounting policy 99 */ 100 class cow_wrapper_client3 101 { 102 public: 103 cow_wrapper_client3(); 104 explicit cow_wrapper_client3( int nVal ); 105 ~cow_wrapper_client3(); 106 107 cow_wrapper_client3( const cow_wrapper_client3& ); 108 cow_wrapper_client3& operator=( const cow_wrapper_client3& ); 109 110 void modify( int nVal ); 111 int queryUnmodified() const; 112 113 void makeUnique(); 114 bool is_unique() const; 115 oslInterlockedCount use_count() const; 116 void swap( cow_wrapper_client3& r ); 117 118 bool operator==( const cow_wrapper_client3& rRHS ) const; 119 bool operator!=( const cow_wrapper_client3& rRHS ) const; 120 bool operator<( const cow_wrapper_client3& rRHS ) const; 121 122 private: 123 o3tl::cow_wrapper< cow_wrapper_client2_impl, o3tl::ThreadSafeRefCountingPolicy > maImpl; 124 }; 125 126 } // namespace o3tltests 127 128 #endif /* INCLUDED_COW_WRAPPER_CLIENTS_HXX */ 129