Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / comphelper / enumhelper.hxx
blobe6d115eac9a5b9af4003adad5f95d8dffbc8b906
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_COMPHELPER_ENUMHELPER_HXX
21 #define INCLUDED_COMPHELPER_ENUMHELPER_HXX
23 #include <vector>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/container/XEnumeration.hpp>
26 #include <com/sun/star/container/XIndexAccess.hpp>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <cppuhelper/implbase.hxx>
29 #include <osl/mutex.hxx>
30 #include <comphelper/comphelperdllapi.h>
32 namespace comphelper
35 struct OEnumerationLock
37 public:
38 ::osl::Mutex m_aLock;
41 /** provides an com.sun.star.container::XEnumeration access based
42 on an object implementing the com.sun.star.container::XNameAccess interface
44 class COMPHELPER_DLLPUBLIC OEnumerationByName : private OEnumerationLock
45 , public ::cppu::WeakImplHelper< css::container::XEnumeration ,
46 css::lang::XEventListener >
48 css::uno::Sequence< OUString > m_aNames;
49 sal_Int32 m_nPos;
50 css::uno::Reference< css::container::XNameAccess > m_xAccess;
51 bool m_bListening;
53 public:
54 OEnumerationByName(const css::uno::Reference< css::container::XNameAccess >& _rxAccess);
55 OEnumerationByName(const css::uno::Reference< css::container::XNameAccess >& _rxAccess,
56 const css::uno::Sequence< OUString >& _aNames );
57 virtual ~OEnumerationByName();
59 virtual sal_Bool SAL_CALL hasMoreElements( ) throw(css::uno::RuntimeException, std::exception) override;
60 virtual css::uno::Any SAL_CALL nextElement( )
61 throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
63 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) throw(css::uno::RuntimeException, std::exception) override;
65 private:
66 COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
67 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
70 /** provides an com.sun.star.container::XEnumeration access based
71 on an object implementing the com.sun.star.container::XNameAccess interface
73 class COMPHELPER_DLLPUBLIC OEnumerationByIndex : private OEnumerationLock
74 , public ::cppu::WeakImplHelper< css::container::XEnumeration ,
75 css::lang::XEventListener >
77 sal_Int32 m_nPos;
78 css::uno::Reference< css::container::XIndexAccess > m_xAccess;
79 bool m_bListening;
81 public:
82 OEnumerationByIndex(const css::uno::Reference< css::container::XIndexAccess >& _rxAccess);
83 virtual ~OEnumerationByIndex();
85 virtual sal_Bool SAL_CALL hasMoreElements( ) throw(css::uno::RuntimeException, std::exception) override;
86 virtual css::uno::Any SAL_CALL nextElement( )
87 throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
89 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) throw(css::uno::RuntimeException, std::exception) override;
91 private:
92 COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
93 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
96 // this is the way that works for ENABLE_LTO with MSVC 2013
97 class SAL_DLLPUBLIC_TEMPLATE OAnyEnumeration_BASE
98 : public ::cppu::WeakImplHelper<css::container::XEnumeration> {};
100 /** provides an com.sun.star.container::XEnumeration
101 for an outside set vector of Any's.
104 class COMPHELPER_DLLPUBLIC OAnyEnumeration : private OEnumerationLock
105 , public OAnyEnumeration_BASE
107 sal_Int32 m_nPos;
108 css::uno::Sequence< css::uno::Any > m_lItems;
110 public:
111 OAnyEnumeration(const css::uno::Sequence< css::uno::Any >& lItems);
112 virtual ~OAnyEnumeration();
114 virtual sal_Bool SAL_CALL hasMoreElements( ) throw(css::uno::RuntimeException, std::exception) override;
115 virtual css::uno::Any SAL_CALL nextElement( )
116 throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
122 #endif // INCLUDED_COMPHELPER_ENUMHELPER_HXX
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */