1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_REF_AND_POINTER_HXX
21 #define INCLUDED_REF_AND_POINTER_HXX
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
26 namespace writerfilter
{
29 using namespace ::com::sun::star
;
30 using namespace ::std
;
32 template <class Interface
, class ChildClass
>
35 mutable ChildClass
* mpHandler
;
36 mutable uno::Reference
<Interface
> mRef
;
44 RefAndPointer(ChildClass
* pHandler
)
45 : mpHandler(pHandler
), mRef(pHandler
)
48 clog
<< "MEMORY:" << mpHandler
->getInstanceNumber() << ":RefAndPointer"
53 RefAndPointer(uno::Reference
<Interface
> xRef
)
56 mpHandler
= dynamic_cast<ChildClass
*>(xRef
.get());
58 if (mpHandler
!= NULL
)
59 clog
<< "MEMORY:" << mpHandler
->getInstanceNumber()
60 << ":RefAndPointer" << endl
;
64 virtual ~RefAndPointer()
67 if (mpHandler
!= NULL
)
68 clog
<< "MEMORY:" << mpHandler
->getInstanceNumber()
69 << ":~RefAndPointer" << endl
;
73 void set(ChildClass
* pHandler
)
79 void set(uno::Reference
<Interface
> xHandler
)
81 mpHandler
= dynamic_cast<ChildClass
*>(xHandler
.get());
85 ChildClass
* getPointer() const { return mpHandler
; }
86 const uno::Reference
<Interface
> getRef() const { return mRef
; }
88 RefAndPointer
& operator=
89 (const RefAndPointer
& rSrc
)
91 set(rSrc
.getHandler());
96 bool is() { return getRef().is(); }
98 operator ChildClass
* () { return getPointer(); }
99 operator uno::Reference
<Interface
> () { return getRef(); }
102 #endif // INCLUDED_REF_AND_POINTER_HXX
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */