LibreOffice Module framework (master) 1
ocomponentenumeration.cxx
Go to the documentation of this file.
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
21
22#include <vcl/svapp.hxx>
23#include <sal/log.hxx>
24
25namespace framework{
26
27using namespace ::com::sun::star::container;
28using namespace ::com::sun::star::lang;
29using namespace ::com::sun::star::uno;
30using namespace ::cppu;
31using namespace ::osl;
32
33// constructor
34
35OComponentEnumeration::OComponentEnumeration( std::vector< css::uno::Reference< XComponent > >&& seqComponents )
36 : m_nPosition ( 0 ) // 0 is the first position for a valid list and the right value for an invalid list to!
37 , m_seqComponents ( std::move(seqComponents) )
38{}
39
40// destructor
41
43{
44 // Reset instance, free memory...
46}
47
48// XEventListener
49void SAL_CALL OComponentEnumeration::disposing( const EventObject& aEvent )
50{
52
53 // Safe impossible cases
54 // This method is not specified for all incoming parameters.
55 SAL_WARN_IF( !aEvent.Source.is(), "fwk", "OComponentEnumeration::disposing(): Invalid parameter detected!" );
56
57 // Reset instance to defaults, release references and free memory.
59}
60
61// XEnumeration
63{
65
66 // First position in a valid list is 0.
67 // => The last one is getLength() - 1!
68 // m_nPosition's current value is the position for the next element, which will be return, if user call "nextElement()"
69 // => We have more elements if current position less than the length of the list!
70 return ( m_nPosition < static_cast<sal_uInt32>(m_seqComponents.size()) );
71}
72
73// XEnumeration
74
76{
78
79 // If we have no elements or end of enumeration is arrived ...
80 if ( !hasMoreElements() )
81 {
82 // .. throw an exception!
83 throw NoSuchElementException();
84 }
85
86 // Else; Get next element from list ...
87 Any aComponent;
88 aComponent <<= m_seqComponents[m_nPosition];
89 // ... and step to next element!
91
92 // Return listitem.
93 return aComponent;
94}
95
96// protected method
97
99{
100 // Attention:
101 // Write this for multiple calls - NOT AT THE SAME TIME - but for more than one call again)!
102 // It exist two ways to call this method. From destructor and from disposing().
103 // I can't say, which one is the first. Normally the disposing-call - but other way...
104
105 // Delete list of components.
106 m_seqComponents.clear();
107 // Reset position in list.
108 // The list has no elements anymore. m_nPosition is normally the current position in list for nextElement!
109 // But a position of 0 in a list of 0 items is an invalid state. This constellation can't work in future.
110 // End of enumeration is arrived!
111 // (see hasMoreElements() for more details...)
112 m_nPosition = 0;
113}
114
115} // namespace framework
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nPosition
AnyEventRef aEvent
virtual sal_Bool SAL_CALL hasMoreElements() override
std::vector< css::uno::Reference< css::lang::XComponent > > m_seqComponents
current position in enumeration
OComponentEnumeration(std::vector< css::uno::Reference< css::lang::XComponent > > &&seqComponents)
virtual css::uno::Any SAL_CALL nextElement() override
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
#define SAL_WARN_IF(condition, area, stream)
unsigned char sal_Bool