1*b0075c8bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0075c8bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0075c8bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0075c8bSAndrew Rist * distributed with this work for additional information 6*b0075c8bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0075c8bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0075c8bSAndrew Rist * "License"); you may not use this file except in compliance 9*b0075c8bSAndrew Rist * with the License. You may obtain a copy of the License at 10*b0075c8bSAndrew Rist * 11*b0075c8bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*b0075c8bSAndrew Rist * 13*b0075c8bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0075c8bSAndrew Rist * software distributed under the License is distributed on an 15*b0075c8bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0075c8bSAndrew Rist * KIND, either express or implied. See the License for the 17*b0075c8bSAndrew Rist * specific language governing permissions and limitations 18*b0075c8bSAndrew Rist * under the License. 19*b0075c8bSAndrew Rist * 20*b0075c8bSAndrew Rist *************************************************************/ 21*b0075c8bSAndrew Rist 22*b0075c8bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_COW_WRAPPER_CLIENTS_HXX 25cdf0e10cSrcweir #define INCLUDED_COW_WRAPPER_CLIENTS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "o3tl/cow_wrapper.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir /* Definition of Cow_Wrapper_Clients classes */ 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace o3tltests { 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** This is a header and a separate compilation unit on purpose - 34cdf0e10cSrcweir cow_wrapper needs destructor, copy constructor and assignment 35cdf0e10cSrcweir operator to be outline, when pimpl idiom is used 36cdf0e10cSrcweir */ 37cdf0e10cSrcweir 38cdf0e10cSrcweir /// test non-opaque impl type 39cdf0e10cSrcweir class cow_wrapper_client1 40cdf0e10cSrcweir { 41cdf0e10cSrcweir public: cow_wrapper_client1()42cdf0e10cSrcweir cow_wrapper_client1() : maImpl() {} cow_wrapper_client1(int nVal)43cdf0e10cSrcweir explicit cow_wrapper_client1( int nVal ) : maImpl(nVal) {} 44cdf0e10cSrcweir modify(int nVal)45cdf0e10cSrcweir void modify( int nVal ) { *maImpl = nVal; } queryUnmodified() const46cdf0e10cSrcweir int queryUnmodified() const { return *maImpl; } 47cdf0e10cSrcweir makeUnique()48cdf0e10cSrcweir void makeUnique() { maImpl.make_unique(); } is_unique() const49cdf0e10cSrcweir bool is_unique() const { return maImpl.is_unique(); } use_count() const50cdf0e10cSrcweir oslInterlockedCount use_count() const { return maImpl.use_count(); } swap(cow_wrapper_client1 & r)51cdf0e10cSrcweir void swap( cow_wrapper_client1& r ) { o3tl::swap(maImpl, r.maImpl); } 52cdf0e10cSrcweir operator ==(const cow_wrapper_client1 & rRHS) const53cdf0e10cSrcweir bool operator==( const cow_wrapper_client1& rRHS ) const { return maImpl == rRHS.maImpl; } operator !=(const cow_wrapper_client1 & rRHS) const54cdf0e10cSrcweir bool operator!=( const cow_wrapper_client1& rRHS ) const { return maImpl != rRHS.maImpl; } operator <(const cow_wrapper_client1 & rRHS) const55cdf0e10cSrcweir bool operator<( const cow_wrapper_client1& rRHS ) const { return maImpl < rRHS.maImpl; } 56cdf0e10cSrcweir 57cdf0e10cSrcweir private: 58cdf0e10cSrcweir o3tl::cow_wrapper< int > maImpl; 59cdf0e10cSrcweir }; 60cdf0e10cSrcweir 61cdf0e10cSrcweir 62cdf0e10cSrcweir class cow_wrapper_client2_impl; 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** test opaque impl type - need to explicitely declare lifetime 65cdf0e10cSrcweir methods 66cdf0e10cSrcweir */ 67cdf0e10cSrcweir class cow_wrapper_client2 68cdf0e10cSrcweir { 69cdf0e10cSrcweir public: 70cdf0e10cSrcweir cow_wrapper_client2(); 71cdf0e10cSrcweir explicit cow_wrapper_client2( int nVal ); 72cdf0e10cSrcweir ~cow_wrapper_client2(); 73cdf0e10cSrcweir 74cdf0e10cSrcweir cow_wrapper_client2( const cow_wrapper_client2& ); 75cdf0e10cSrcweir cow_wrapper_client2& operator=( const cow_wrapper_client2& ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir void modify( int nVal ); 78cdf0e10cSrcweir int queryUnmodified() const; 79cdf0e10cSrcweir 80cdf0e10cSrcweir void makeUnique(); 81cdf0e10cSrcweir bool is_unique() const; 82cdf0e10cSrcweir oslInterlockedCount use_count() const; 83cdf0e10cSrcweir void swap( cow_wrapper_client2& r ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir bool operator==( const cow_wrapper_client2& rRHS ) const; 86cdf0e10cSrcweir bool operator!=( const cow_wrapper_client2& rRHS ) const; 87cdf0e10cSrcweir bool operator<( const cow_wrapper_client2& rRHS ) const; 88cdf0e10cSrcweir 89cdf0e10cSrcweir private: 90cdf0e10cSrcweir o3tl::cow_wrapper< cow_wrapper_client2_impl > maImpl; 91cdf0e10cSrcweir }; 92cdf0e10cSrcweir 93cdf0e10cSrcweir /** test MT-safe cow_wrapper - basically the same as 94cdf0e10cSrcweir cow_wrapper_client2, only with different refcounting policy 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir class cow_wrapper_client3 97cdf0e10cSrcweir { 98cdf0e10cSrcweir public: 99cdf0e10cSrcweir cow_wrapper_client3(); 100cdf0e10cSrcweir explicit cow_wrapper_client3( int nVal ); 101cdf0e10cSrcweir ~cow_wrapper_client3(); 102cdf0e10cSrcweir 103cdf0e10cSrcweir cow_wrapper_client3( const cow_wrapper_client3& ); 104cdf0e10cSrcweir cow_wrapper_client3& operator=( const cow_wrapper_client3& ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir void modify( int nVal ); 107cdf0e10cSrcweir int queryUnmodified() const; 108cdf0e10cSrcweir 109cdf0e10cSrcweir void makeUnique(); 110cdf0e10cSrcweir bool is_unique() const; 111cdf0e10cSrcweir oslInterlockedCount use_count() const; 112cdf0e10cSrcweir void swap( cow_wrapper_client3& r ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir bool operator==( const cow_wrapper_client3& rRHS ) const; 115cdf0e10cSrcweir bool operator!=( const cow_wrapper_client3& rRHS ) const; 116cdf0e10cSrcweir bool operator<( const cow_wrapper_client3& rRHS ) const; 117cdf0e10cSrcweir 118cdf0e10cSrcweir private: 119cdf0e10cSrcweir o3tl::cow_wrapper< cow_wrapper_client2_impl, o3tl::ThreadSafeRefCountingPolicy > maImpl; 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir } // namespace o3tltests 123cdf0e10cSrcweir 124cdf0e10cSrcweir #endif /* INCLUDED_COW_WRAPPER_CLIENTS_HXX */ 125