LibreOffice Module reportdesign (master) 1
Functions.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#include <Functions.hxx>
20#include <Function.hxx>
21#include <core_resource.hxx>
22#include <strings.hrc>
23#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <com/sun/star/lang/NoSupportException.hpp>
25#include <o3tl/safeint.hxx>
26#include <utility>
27
28namespace reportdesign
29{
30
31 using namespace com::sun::star;
32
33OFunctions::OFunctions(const uno::Reference< report::XFunctionsSupplier >& _xParent,uno::Reference< uno::XComponentContext > context)
35,m_aContainerListeners(m_aMutex)
36,m_xContext(std::move(context))
37,m_xParent(_xParent)
38{
39}
40
41// TODO: VirtualFunctionFinder: This is virtual function!
42
43OFunctions::~OFunctions()
44{
45}
46
47void SAL_CALL OFunctions::dispose()
48{
49 cppu::WeakComponentImplHelperBase::dispose();
50}
51
52// TODO: VirtualFunctionFinder: This is virtual function!
53
54void SAL_CALL OFunctions::disposing()
55{
56 for (auto& rFunction : m_aFunctions)
57 rFunction->dispose();
58 m_aFunctions.clear();
59 lang::EventObject aDisposeEvent( getXWeak() );
60 m_aContainerListeners.disposeAndClear( aDisposeEvent );
61 m_xContext.clear();
62}
63
64// XFunctionsSupplier
65
66uno::Reference< report::XFunction > SAL_CALL OFunctions::createFunction( )
67{
68 return new OFunction(m_xContext);
69}
70
71// XIndexContainer
72void SAL_CALL OFunctions::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement )
73{
74 {
75 ::osl::MutexGuard aGuard(m_aMutex);
76 bool bAdd = (Index == static_cast<sal_Int32>(m_aFunctions.size()));
77 if ( !bAdd )
78 checkIndex(Index);
79 uno::Reference< report::XFunction > xFunction(aElement,uno::UNO_QUERY);
80 if ( !xFunction.is() )
81 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
82
83 if ( bAdd )
84 m_aFunctions.push_back(xFunction);
85 else
86 {
87 TFunctions::iterator aPos = m_aFunctions.begin();
88 ::std::advance(aPos,Index);
89 m_aFunctions.insert(aPos, xFunction);
90 }
91 xFunction->setParent(*this);
92 }
93 // notify our container listeners
94 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), aElement, uno::Any());
95 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
96}
97
98
99void SAL_CALL OFunctions::removeByIndex( ::sal_Int32 Index )
100{
101 uno::Reference< report::XFunction > xFunction;
102 {
103 ::osl::MutexGuard aGuard(m_aMutex);
104 checkIndex(Index);
105 TFunctions::iterator aPos = m_aFunctions.begin();
106 ::std::advance(aPos,Index);
107 xFunction = *aPos;
108 m_aFunctions.erase(aPos);
109 xFunction->setParent(nullptr);
110 }
111 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), uno::Any(xFunction), uno::Any());
112 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
113}
114
115// XIndexReplace
116void SAL_CALL OFunctions::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
117{
118 uno::Any aOldElement;
119 {
120 ::osl::MutexGuard aGuard(m_aMutex);
121 checkIndex(Index);
122 uno::Reference< report::XFunction > xFunction(Element,uno::UNO_QUERY);
123 if ( !xFunction.is() )
124 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
125 TFunctions::iterator aPos = m_aFunctions.begin();
126 ::std::advance(aPos,Index);
127 aOldElement <<= *aPos;
128 *aPos = xFunction;
129 }
130
131 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), Element, aOldElement);
132 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
133}
134
135// XIndexAccess
136::sal_Int32 SAL_CALL OFunctions::getCount( )
137{
138 ::osl::MutexGuard aGuard(m_aMutex);
139 return m_aFunctions.size();
140}
141
142uno::Any SAL_CALL OFunctions::getByIndex( ::sal_Int32 Index )
143{
144 ::osl::MutexGuard aGuard(m_aMutex);
145 checkIndex(Index);
146 TFunctions::const_iterator aPos = m_aFunctions.begin();
147 ::std::advance(aPos,Index);
148 return uno::Any(*aPos);
149}
150
151// XElementAccess
152uno::Type SAL_CALL OFunctions::getElementType( )
153{
155}
156
157sal_Bool SAL_CALL OFunctions::hasElements( )
158{
159 ::osl::MutexGuard aGuard(m_aMutex);
160 return !m_aFunctions.empty();
161}
162
163// XChild
164uno::Reference< uno::XInterface > SAL_CALL OFunctions::getParent( )
165{
166 return m_xParent;
167}
168
169void SAL_CALL OFunctions::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
170{
171 throw lang::NoSupportException();
172}
173
174// XContainer
175void SAL_CALL OFunctions::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
176{
177 m_aContainerListeners.addInterface(xListener);
178}
179
180void SAL_CALL OFunctions::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
181{
182 m_aContainerListeners.removeInterface(xListener);
183}
184
185void OFunctions::checkIndex(sal_Int32 _nIndex)
186{
187 if ( _nIndex < 0 || m_aFunctions.size() <= o3tl::make_unsigned(_nIndex) )
188 throw lang::IndexOutOfBoundsException();
189}
190
191}
192
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
Reference< XComponentContext > m_xContext
AnyEventRef aEvent
css::uno::Type const & get()
implementation of a
Definition: Function.hxx:43
OFunctions(const OFunctions &)=delete
OUString RptResId(TranslateId aId)
std::mutex m_aMutex
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
::cppu::WeakComponentImplHelper< css::report::XFunctions > FunctionsBase
Definition: Functions.hxx:33
unsigned char sal_Bool