Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / ooxml / RefAndPointer.hxx
blob8329e2afeea006b8b50f64f0b28f5718c6245ecf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <iostream>
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
26 namespace writerfilter {
27 namespace ooxml
29 using namespace ::com::sun::star;
30 using namespace ::std;
32 template <class Interface, class ChildClass>
33 class RefAndPointer
35 mutable ChildClass * mpHandler;
36 mutable uno::Reference<Interface> mRef;
38 public:
39 RefAndPointer()
40 : mpHandler(NULL)
44 RefAndPointer(ChildClass * pHandler)
45 : mpHandler(pHandler), mRef(pHandler)
47 #ifdef DEBUG_MEMORY
48 clog << "MEMORY:" << mpHandler->getInstanceNumber() << ":RefAndPointer"
49 << endl;
50 #endif
53 RefAndPointer(uno::Reference<Interface> xRef)
54 : mRef(xRef)
56 mpHandler = dynamic_cast<ChildClass *>(xRef.get());
57 #ifdef DEBUG_MEMORY
58 if (mpHandler != NULL)
59 clog << "MEMORY:" << mpHandler->getInstanceNumber()
60 << ":RefAndPointer" << endl;
61 #endif
64 virtual ~RefAndPointer()
66 #ifdef DEBUG_MEMORY
67 if (mpHandler != NULL)
68 clog << "MEMORY:" << mpHandler->getInstanceNumber()
69 << ":~RefAndPointer" << endl;
70 #endif
73 void set(ChildClass * pHandler)
75 mpHandler = pHandler;
76 mRef = pHandler;
79 void set(uno::Reference<Interface> xHandler)
81 mpHandler = dynamic_cast<ChildClass*>(xHandler.get());
82 mRef = xHandler;
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());
93 return *this;
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: */