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