LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / include / comphelper / enumhelper.hxx
blob52f3aa743adefca083b1abc941ae76581c419fe7
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 <com/sun/star/container/XEnumeration.hpp>
24 #include <com/sun/star/lang/XEventListener.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <mutex>
27 #include <comphelper/comphelperdllapi.h>
29 namespace com::sun::star::container { class XIndexAccess; }
30 namespace com::sun::star::container { class XNameAccess; }
32 namespace comphelper
35 /** provides a com.sun.star.container::XEnumeration access based
36 on an object implementing the com.sun.star.container::XNameAccess interface
38 class COMPHELPER_DLLPUBLIC OEnumerationByName final :
39 public ::cppu::WeakImplHelper< css::container::XEnumeration ,
40 css::lang::XEventListener >
42 css::uno::Sequence< OUString > const m_aNames;
43 css::uno::Reference< css::container::XNameAccess > m_xAccess;
44 sal_Int32 m_nPos;
45 bool m_bListening;
46 std::mutex m_aLock;
48 public:
49 OEnumerationByName(const css::uno::Reference< css::container::XNameAccess >& _rxAccess);
50 OEnumerationByName(const css::uno::Reference< css::container::XNameAccess >& _rxAccess,
51 const css::uno::Sequence< OUString >& _aNames );
52 virtual ~OEnumerationByName() override;
54 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
55 virtual css::uno::Any SAL_CALL nextElement( ) override;
57 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
59 private:
60 COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
61 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
64 /** provides a com.sun.star.container::XEnumeration access based
65 on an object implementing the com.sun.star.container::XNameAccess interface
67 class COMPHELPER_DLLPUBLIC OEnumerationByIndex final :
68 public ::cppu::WeakImplHelper< css::container::XEnumeration ,
69 css::lang::XEventListener >
71 css::uno::Reference< css::container::XIndexAccess > m_xAccess;
72 sal_Int32 m_nPos;
73 bool m_bListening;
74 std::mutex m_aLock;
76 public:
77 OEnumerationByIndex(const css::uno::Reference< css::container::XIndexAccess >& _rxAccess);
78 virtual ~OEnumerationByIndex() override;
80 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
81 virtual css::uno::Any SAL_CALL nextElement( ) override;
83 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
85 private:
86 COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
87 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
90 // this is the way that works for ENABLE_LTO with MSVC 2013
91 class SAL_DLLPUBLIC_TEMPLATE OAnyEnumeration_BASE
92 : public ::cppu::WeakImplHelper<css::container::XEnumeration> {};
94 /** provides a com.sun.star.container::XEnumeration
95 for an outside set vector of Any's.
98 class COMPHELPER_DLLPUBLIC OAnyEnumeration final :
99 public OAnyEnumeration_BASE
101 sal_Int32 m_nPos;
102 css::uno::Sequence< css::uno::Any > m_lItems;
103 std::mutex m_aLock;
105 public:
106 OAnyEnumeration(const css::uno::Sequence< css::uno::Any >& lItems);
107 virtual ~OAnyEnumeration() override;
109 virtual sal_Bool SAL_CALL hasMoreElements( ) override;
110 virtual css::uno::Any SAL_CALL nextElement( ) override;
116 #endif // INCLUDED_COMPHELPER_ENUMHELPER_HXX
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */