Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_O3TL_QA_COW_WRAPPER_CLIENTS_HXX
21 : #define INCLUDED_O3TL_QA_COW_WRAPPER_CLIENTS_HXX
22 :
23 : #include "o3tl/cow_wrapper.hxx"
24 :
25 : /* Definition of Cow_Wrapper_Clients classes */
26 :
27 : namespace o3tltests {
28 :
29 : /** This is a header and a separate compilation unit on purpose -
30 : cow_wrapper needs destructor, copy constructor and assignment
31 : operator to be outline, when pimpl idiom is used
32 : */
33 :
34 : /// test non-opaque impl type
35 7 : class cow_wrapper_client1
36 : {
37 : public:
38 3 : cow_wrapper_client1() : maImpl() {}
39 1 : explicit cow_wrapper_client1( int nVal ) : maImpl(nVal) {}
40 :
41 2 : void modify( int nVal ) { *maImpl = nVal; }
42 3 : int queryUnmodified() const { return *maImpl; }
43 :
44 1 : void makeUnique() { maImpl.make_unique(); }
45 5 : bool is_unique() const { return maImpl.is_unique(); }
46 9 : oslInterlockedCount use_count() const { return maImpl.use_count(); }
47 1 : void swap( cow_wrapper_client1& r ) { o3tl::swap(maImpl, r.maImpl); }
48 :
49 6 : bool operator==( const cow_wrapper_client1& rRHS ) const { return maImpl == rRHS.maImpl; }
50 3 : bool operator!=( const cow_wrapper_client1& rRHS ) const { return maImpl != rRHS.maImpl; }
51 2 : bool operator<( const cow_wrapper_client1& rRHS ) const { return maImpl < rRHS.maImpl; }
52 :
53 : private:
54 : o3tl::cow_wrapper< int > maImpl;
55 : };
56 :
57 :
58 : class cow_wrapper_client2_impl;
59 :
60 : /** test opaque impl type - need to explicitly declare lifetime
61 : methods
62 : */
63 : class cow_wrapper_client2
64 : {
65 : public:
66 : cow_wrapper_client2();
67 : explicit cow_wrapper_client2( int nVal );
68 : ~cow_wrapper_client2();
69 :
70 : cow_wrapper_client2( const cow_wrapper_client2& );
71 : cow_wrapper_client2& operator=( const cow_wrapper_client2& );
72 :
73 : void modify( int nVal );
74 : int queryUnmodified() const;
75 :
76 : void makeUnique();
77 : bool is_unique() const;
78 : oslInterlockedCount use_count() const;
79 : void swap( cow_wrapper_client2& r );
80 :
81 : bool operator==( const cow_wrapper_client2& rRHS ) const;
82 : bool operator!=( const cow_wrapper_client2& rRHS ) const;
83 : bool operator<( const cow_wrapper_client2& rRHS ) const;
84 :
85 : private:
86 : o3tl::cow_wrapper< cow_wrapper_client2_impl > maImpl;
87 : };
88 :
89 : /** test MT-safe cow_wrapper - basically the same as
90 : cow_wrapper_client2, only with different refcounting policy
91 : */
92 : class cow_wrapper_client3
93 : {
94 : public:
95 : cow_wrapper_client3();
96 : explicit cow_wrapper_client3( int nVal );
97 : ~cow_wrapper_client3();
98 :
99 : cow_wrapper_client3( const cow_wrapper_client3& );
100 : cow_wrapper_client3& operator=( const cow_wrapper_client3& );
101 :
102 : void modify( int nVal );
103 : int queryUnmodified() const;
104 :
105 : void makeUnique();
106 : bool is_unique() const;
107 : oslInterlockedCount use_count() const;
108 : void swap( cow_wrapper_client3& r );
109 :
110 : bool operator==( const cow_wrapper_client3& rRHS ) const;
111 : bool operator!=( const cow_wrapper_client3& rRHS ) const;
112 : bool operator<( const cow_wrapper_client3& rRHS ) const;
113 :
114 : private:
115 : o3tl::cow_wrapper< cow_wrapper_client2_impl, o3tl::ThreadSafeRefCountingPolicy > maImpl;
116 : };
117 :
118 : /** test default-object comparison - have default-ctored-client4 share
119 : the same static impl instance, check if isDefault does the right
120 : thing
121 : */
122 : class cow_wrapper_client4
123 : {
124 : public:
125 : cow_wrapper_client4();
126 : explicit cow_wrapper_client4(int);
127 : ~cow_wrapper_client4();
128 :
129 : cow_wrapper_client4( const cow_wrapper_client4& );
130 : cow_wrapper_client4& operator=( const cow_wrapper_client4& );
131 :
132 : bool is_default() const;
133 :
134 : bool operator==( const cow_wrapper_client4& rRHS ) const;
135 : bool operator!=( const cow_wrapper_client4& rRHS ) const;
136 : bool operator<( const cow_wrapper_client4& rRHS ) const;
137 :
138 : private:
139 : o3tl::cow_wrapper< int > maImpl;
140 : };
141 :
142 : } // namespace o3tltests
143 :
144 : #endif // INCLUDED_O3TL_QA_COW_WRAPPER_CLIENTS_HXX
145 :
146 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|