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