1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef INCLUDED_COW_WRAPPER_CLIENTS_HXX
29 #define INCLUDED_COW_WRAPPER_CLIENTS_HXX
31 #include "o3tl/cow_wrapper.hxx"
33 /* Definition of Cow_Wrapper_Clients classes */
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
42 /// test non-opaque impl type
43 class cow_wrapper_client1
46 cow_wrapper_client1() : maImpl() {}
47 explicit cow_wrapper_client1( int nVal
) : maImpl(nVal
) {}
49 void modify( int nVal
) { *maImpl
= nVal
; }
50 int queryUnmodified() const { return *maImpl
; }
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
); }
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
; }
62 o3tl::cow_wrapper
< int > maImpl
;
66 class cow_wrapper_client2_impl
;
68 /** test opaque impl type - need to explicitely declare lifetime
71 class cow_wrapper_client2
74 cow_wrapper_client2();
75 explicit cow_wrapper_client2( int nVal
);
76 ~cow_wrapper_client2();
78 cow_wrapper_client2( const cow_wrapper_client2
& );
79 cow_wrapper_client2
& operator=( const cow_wrapper_client2
& );
81 void modify( int nVal
);
82 int queryUnmodified() const;
85 bool is_unique() const;
86 oslInterlockedCount
use_count() const;
87 void swap( cow_wrapper_client2
& r
);
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;
94 o3tl::cow_wrapper
< cow_wrapper_client2_impl
> maImpl
;
97 /** test MT-safe cow_wrapper - basically the same as
98 cow_wrapper_client2, only with different refcounting policy
100 class cow_wrapper_client3
103 cow_wrapper_client3();
104 explicit cow_wrapper_client3( int nVal
);
105 ~cow_wrapper_client3();
107 cow_wrapper_client3( const cow_wrapper_client3
& );
108 cow_wrapper_client3
& operator=( const cow_wrapper_client3
& );
110 void modify( int nVal
);
111 int queryUnmodified() const;
114 bool is_unique() const;
115 oslInterlockedCount
use_count() const;
116 void swap( cow_wrapper_client3
& r
);
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;
123 o3tl::cow_wrapper
< cow_wrapper_client2_impl
, o3tl::ThreadSafeRefCountingPolicy
> maImpl
;
126 } // namespace o3tltests
128 #endif /* INCLUDED_COW_WRAPPER_CLIENTS_HXX */