LibreOffice Module tools (master) 1
weakbase.h
Go to the documentation of this file.
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#ifndef INCLUDED_TOOLS_WEAKBASE_H
20#define INCLUDED_TOOLS_WEAKBASE_H
21
22#include <sal/types.h>
23#include <rtl/ref.hxx>
24#include <tools/toolsdllapi.h>
25
55namespace tools
56{
57class WeakBase;
58
61{
62 sal_Int32 mnRefCount;
64
65 WeakConnection() : mnRefCount( 0 ), mpReference( nullptr ) {};
66 WeakConnection( WeakBase* pReference ) : mnRefCount( 0 ), mpReference( pReference ) {};
67 void acquire() { mnRefCount++; }
68 void release() { mnRefCount--; if( mnRefCount == 0 ) delete this; }
69};
70
72template <class reference_type>
74{
75public:
77 inline WeakReference();
78
80 inline WeakReference( reference_type* pReference );
81
83 inline WeakReference( const WeakReference< reference_type >& rWeakRef );
84
87
89 inline bool is() const;
90
92 operator bool() const { return is(); }
93
95 inline reference_type * get() const;
96
98 inline void reset( reference_type* pReference );
99
101 inline void reset();
102
104 inline reference_type * operator->() const;
105
107 inline reference_type& operator*() const;
108
110 inline bool operator== (const reference_type * pReferenceObject) const;
111
113 inline bool operator== (const WeakReference<reference_type> & handle) const;
114
116 inline bool operator!= (const WeakReference<reference_type> & handle) const;
117
119 inline bool operator< (const WeakReference<reference_type> & handle) const;
120
122 inline bool operator> (const WeakReference<reference_type> & handle) const;
123
125 inline WeakReference<reference_type>& operator= (const WeakReference<reference_type> & handle);
126
129
130private:
132};
133
136{
137 template<typename T> friend class WeakReference;
138
139public:
141 virtual ~WeakBase();
148 inline void clearWeak();
149
150private:
151 inline WeakConnection* getWeakConnection();
153};
154
155}
156
157#endif
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const BigInt &rVal1, const BigInt &rVal2)
Definition: bigint.cxx:806
bool operator<(const BigInt &rVal1, const BigInt &rVal2)
Definition: bigint.cxx:818
derive your implementation classes from this class if you want them to support weak references
Definition: weakbase.h:136
rtl::Reference< WeakConnection > mpWeakConnection
Definition: weakbase.h:152
template implementation to hold a weak reference to an instance of type reference_type
Definition: weakbase.h:74
rtl::Reference< WeakConnection > mpWeakConnection
Definition: weakbase.h:131
bool operator>(const Fraction &rVal1, const Fraction &rVal2)
Definition: fract.cxx:377
Fraction operator*(const Fraction &rVal1, const Fraction &rVal2)
Definition: fract.cxx:326
bool operator!=(const Fraction &rVal1, const Fraction &rVal2)
Definition: fract.cxx:340
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Note: this class is a true marvel of engineering: because the author could not decide whether it's be...
private connection helper, do not use directly
Definition: weakbase.h:61
sal_Int32 mnRefCount
Definition: weakbase.h:62
WeakConnection(WeakBase *pReference)
Definition: weakbase.h:66
WeakBase * mpReference
Definition: weakbase.h:63
#define TOOLS_DLLPUBLIC
Definition: toolsdllapi.h:28
#define SAL_WARN_UNUSED