tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / include / comphelper / enumhelper.hxx
blob05b5d32185035de76cd625b2d79541820a43e8ad
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 <config_options.h>
24 #include <com/sun/star/container/XEnumeration.hpp>
25 #include <com/sun/star/lang/XEventListener.hpp>
26 #include <comphelper/comphelperdllapi.h>
27 #include <cppuhelper/implbase.hxx>
28 #include <mutex>
29 #include <variant>
30 #include <vector>
32 namespace com::sun::star::container { class XIndexAccess; }
33 namespace com::sun::star::container { class XNameAccess; }
35 namespace comphelper
38 /** provides a com.sun.star.container::XEnumeration access based
39 on an object implementing the com.sun.star.container::XNameAccess interface
41 class UNLESS_MERGELIBS_MORE(COMPHELPER_DLLPUBLIC) OEnumerationByName final :
42 public ::cppu::WeakImplHelper< css::container::XEnumeration ,
43 css::lang::XEventListener >
45 std::variant<css::uno::Sequence< OUString >, std::vector<OUString>> m_aNames;
46 css::uno::Reference< css::container::XNameAccess > m_xAccess;
47 sal_Int32 m_nPos;
48 bool m_bListening;
49 std::mutex m_aLock;
51 public:
52 OEnumerationByName(css::uno::Reference< css::container::XNameAccess > _xAccess);
53 OEnumerationByName(css::uno::Reference< css::container::XNameAccess > _xAccess,
54 std::vector<OUString> _aNames );
55 virtual ~OEnumerationByName() override;
57 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
58 virtual css::uno::Any SAL_CALL nextElement( ) override;
60 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
62 private:
63 sal_Int32 getLength() const;
64 const OUString& getElement(sal_Int32 nIndex) const;
65 COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
66 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
69 /** provides a com.sun.star.container::XEnumeration access based
70 on an object implementing the com.sun.star.container::XNameAccess interface
72 class COMPHELPER_DLLPUBLIC OEnumerationByIndex final :
73 public ::cppu::WeakImplHelper< css::container::XEnumeration ,
74 css::lang::XEventListener >
76 css::uno::Reference< css::container::XIndexAccess > m_xAccess;
77 sal_Int32 m_nPos;
78 bool m_bListening;
79 std::mutex m_aLock;
81 public:
82 OEnumerationByIndex(css::uno::Reference< css::container::XIndexAccess > _xAccess);
83 virtual ~OEnumerationByIndex() override;
85 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
86 virtual css::uno::Any SAL_CALL nextElement( ) override;
88 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
90 private:
91 COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
92 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
95 // this is the way that works for ENABLE_LTO with MSVC 2013
96 class SAL_DLLPUBLIC_TEMPLATE OAnyEnumeration_BASE
97 : public ::cppu::WeakImplHelper<css::container::XEnumeration> {};
99 /** provides a com.sun.star.container::XEnumeration
100 for an outside set vector of Any's.
103 class UNLESS_MERGELIBS_MORE(COMPHELPER_DLLPUBLIC) OAnyEnumeration final :
104 public OAnyEnumeration_BASE
106 sal_Int32 m_nPos;
107 css::uno::Sequence< css::uno::Any > m_lItems;
108 std::mutex m_aLock;
110 public:
111 OAnyEnumeration(const css::uno::Sequence< css::uno::Any >& lItems);
112 virtual ~OAnyEnumeration() override;
114 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
115 virtual css::uno::Any SAL_CALL nextElement( ) override;
121 #endif // INCLUDED_COMPHELPER_ENUMHELPER_HXX
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */