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_REF_AND_POINTER_HXX
21 : #define INCLUDED_REF_AND_POINTER_HXX
22 :
23 : #include <iostream>
24 : #include <com/sun/star/lang/XUnoTunnel.hpp>
25 :
26 : namespace writerfilter {
27 : namespace ooxml
28 : {
29 : using namespace ::com::sun::star;
30 : using namespace ::std;
31 :
32 : template <class Interface, class ChildClass>
33 : class RefAndPointer
34 : {
35 : mutable ChildClass * mpHandler;
36 : mutable uno::Reference<Interface> mRef;
37 :
38 : public:
39 415 : RefAndPointer()
40 415 : : mpHandler(NULL)
41 : {
42 415 : }
43 :
44 : RefAndPointer(ChildClass * pHandler)
45 : : mpHandler(pHandler), mRef(pHandler)
46 : {
47 : #ifdef DEBUG_MEMORY
48 : clog << "MEMORY:" << mpHandler->getInstanceNumber() << ":RefAndPointer"
49 : << endl;
50 : #endif
51 : }
52 :
53 : RefAndPointer(uno::Reference<Interface> xRef)
54 : : mRef(xRef)
55 : {
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
62 : }
63 :
64 415 : virtual ~RefAndPointer()
65 : {
66 : #ifdef DEBUG_MEMORY
67 : if (mpHandler != NULL)
68 : clog << "MEMORY:" << mpHandler->getInstanceNumber()
69 : << ":~RefAndPointer" << endl;
70 : #endif
71 415 : }
72 :
73 : void set(ChildClass * pHandler)
74 : {
75 : mpHandler = pHandler;
76 : mRef = pHandler;
77 : }
78 :
79 2855 : void set(uno::Reference<Interface> xHandler)
80 : {
81 2855 : mpHandler = dynamic_cast<ChildClass*>(xHandler.get());
82 2855 : mRef = xHandler;
83 2855 : }
84 :
85 3270 : ChildClass * getPointer() const { return mpHandler; }
86 2855 : const uno::Reference<Interface> getRef() const { return mRef; }
87 :
88 : RefAndPointer & operator=
89 : (const RefAndPointer & rSrc)
90 : {
91 : set(rSrc.getHandler());
92 :
93 : return *this;
94 : }
95 :
96 : bool is() { return getRef().is(); }
97 :
98 : operator ChildClass* () { return getPointer(); }
99 2855 : operator uno::Reference<Interface> () { return getRef(); }
100 : };
101 : }}
102 : #endif // INCLUDED_REF_AND_POINTER_HXX
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|