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 _OHIERARCHYHOLDER_HXX_
21 : #define _OHIERARCHYHOLDER_HXX_
22 :
23 : #include <com/sun/star/embed/XStorage.hpp>
24 : #include <com/sun/star/embed/XTransactionListener.hpp>
25 : #include <com/sun/star/embed/XExtendedStorageStream.hpp>
26 : #include <cppuhelper/implbase1.hxx>
27 :
28 : #include <comphelper/sequenceashashmap.hxx>
29 :
30 : #include <rtl/ref.hxx>
31 :
32 : #include <boost/unordered_map.hpp>
33 : #include <list>
34 : #include <vector>
35 :
36 : struct OHierarchyElement_Impl;
37 :
38 : struct eqFunc
39 : {
40 0 : sal_Bool operator()( const OUString &r1,
41 : const OUString &r2) const
42 : {
43 0 : return r1 == r2;
44 : }
45 : };
46 : typedef ::boost::unordered_map< OUString,
47 : ::rtl::Reference< OHierarchyElement_Impl >,
48 : OUStringHash,
49 : eqFunc > OHierarchyElementList_Impl;
50 :
51 : typedef ::std::vector< OUString > OStringList_Impl;
52 : typedef ::std::list< ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XExtendedStorageStream > >
53 : OWeakStorRefList_Impl;
54 :
55 0 : struct OHierarchyElement_Impl : public cppu::WeakImplHelper1< ::com::sun::star::embed::XTransactionListener >
56 : {
57 : ::osl::Mutex m_aMutex;
58 :
59 : ::rtl::Reference< OHierarchyElement_Impl > m_rParent;
60 : ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xOwnStorage;
61 : ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage;
62 :
63 : OHierarchyElementList_Impl m_aChildren;
64 :
65 : OWeakStorRefList_Impl m_aOpenStreams;
66 :
67 : public:
68 0 : OHierarchyElement_Impl( OHierarchyElement_Impl* pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
69 : : m_rParent( pParent )
70 0 : , m_xOwnStorage( xStorage )
71 0 : {}
72 :
73 0 : OHierarchyElement_Impl( const ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >& xWeakStorage )
74 : : m_rParent( NULL )
75 0 : , m_xWeakOwnStorage( xWeakStorage )
76 0 : {}
77 :
78 : void Commit();
79 :
80 0 : void SetParent( const ::rtl::Reference< OHierarchyElement_Impl >& rParent ) { m_rParent = rParent; }
81 :
82 : void TestForClosing();
83 :
84 : void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef );
85 :
86 : ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream >
87 : GetStreamHierarchically( sal_Int32 nStorageMode,
88 : OStringList_Impl& aPath,
89 : sal_Int32 nStreamMode,
90 : const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() );
91 :
92 : void RemoveStreamHierarchically( OStringList_Impl& aListPath );
93 :
94 : // XEventListener
95 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
96 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
97 :
98 : // XTransactionListener
99 : virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent )
100 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
101 : virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent )
102 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 : virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent )
104 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 : virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent )
106 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 :
108 : };
109 :
110 0 : class OHierarchyHolder_Impl : public ::cppu::OWeakObject
111 : {
112 : ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage;
113 : ::rtl::Reference< OHierarchyElement_Impl > m_xChild;
114 : public:
115 0 : OHierarchyHolder_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xOwnStorage )
116 : : m_xWeakOwnStorage( xOwnStorage )
117 0 : , m_xChild( new OHierarchyElement_Impl( ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >( xOwnStorage ) ) )
118 0 : {}
119 :
120 : static OStringList_Impl GetListPathFromString( const OUString& aPath );
121 :
122 : ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream >
123 : GetStreamHierarchically( sal_Int32 nStorageMode,
124 : OStringList_Impl& aListPath,
125 : sal_Int32 nStreamMode,
126 : const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() );
127 :
128 : void RemoveStreamHierarchically( OStringList_Impl& aListPath );
129 : };
130 :
131 : #endif // _OHIERARCHYHOLDER
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|