LibreOffice Module framework (master) 1
propertysetcontainer.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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <vcl/svapp.hxx>
25
26constexpr OUStringLiteral WRONG_TYPE_EXCEPTION = u"Only XPropertSet allowed!";
27
28using namespace cppu;
29using namespace com::sun::star::uno;
30using namespace com::sun::star::container;
31using namespace com::sun::star::lang;
32using namespace com::sun::star::beans;
33
34namespace framework
35{
36
38{
39}
40
42{
43}
44
45// XInterface
46void SAL_CALL PropertySetContainer::acquire() noexcept
47{
48 OWeakObject::acquire();
49}
50
51void SAL_CALL PropertySetContainer::release() noexcept
52{
53 OWeakObject::release();
54}
55
57{
58 Any a = ::cppu::queryInterface(
59 rType ,
60 static_cast< XIndexContainer* >(this),
61 static_cast< XIndexReplace* >(this),
62 static_cast< XIndexAccess* >(this),
63 static_cast< XElementAccess* >(this) );
64
65 if( a.hasValue() )
66 {
67 return a;
68 }
69
70 return OWeakObject::queryInterface( rType );
71}
72
73// XIndexContainer
74void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const css::uno::Any& Element )
75{
76 std::unique_lock g(m_aMutex);
77
78 sal_Int32 nSize = m_aPropertySetVector.size();
79
80 if ( nSize < Index )
81 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
82
83 Reference< XPropertySet > aPropertySetElement;
84
85 if ( !(Element >>= aPropertySetElement) )
86 {
87 throw IllegalArgumentException(
89 static_cast<OWeakObject *>(this), 2 );
90 }
91
92 if ( nSize == Index )
93 m_aPropertySetVector.push_back( aPropertySetElement );
94 else
95 {
96 PropertySetVector::iterator aIter = m_aPropertySetVector.begin();
97 aIter += Index;
98 m_aPropertySetVector.insert( aIter, aPropertySetElement );
99 }
100}
101
102void SAL_CALL PropertySetContainer::removeByIndex( sal_Int32 nIndex )
103{
104 std::unique_lock g(m_aMutex);
105
106 if ( static_cast<sal_Int32>(m_aPropertySetVector.size()) <= nIndex )
107 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
108
110}
111
112// XIndexReplace
113void SAL_CALL PropertySetContainer::replaceByIndex( sal_Int32 Index, const css::uno::Any& Element )
114{
115 std::unique_lock g(m_aMutex);
116
117 if ( static_cast<sal_Int32>(m_aPropertySetVector.size()) <= Index )
118 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
119
120 Reference< XPropertySet > aPropertySetElement;
121
122 if ( !(Element >>= aPropertySetElement) )
123 {
124 throw IllegalArgumentException(
126 static_cast<OWeakObject *>(this), 2 );
127 }
128
129 m_aPropertySetVector[ Index ] = aPropertySetElement;
130}
131
132// XIndexAccess
134{
135 std::unique_lock g(m_aMutex);
136
137 return m_aPropertySetVector.size();
138}
139
141{
142 std::unique_lock g(m_aMutex);
143
144 if ( static_cast<sal_Int32>(m_aPropertySetVector.size()) <= Index )
145 throw IndexOutOfBoundsException( OUString(), static_cast<OWeakObject *>(this) );
146
147 return Any(m_aPropertySetVector[ Index ]);
148}
149
150// XElementAccess
152{
153 std::unique_lock g(m_aMutex);
154
155 return !( m_aPropertySetVector.empty() );
156}
157
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
virtual void SAL_CALL insertByIndex(sal_Int32 Index, const css::uno::Any &Element) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual void SAL_CALL release() noexcept override
virtual sal_Int32 SAL_CALL getCount() override
virtual void SAL_CALL removeByIndex(sal_Int32 Index) override
virtual void SAL_CALL replaceByIndex(sal_Int32 Index, const css::uno::Any &Element) override
float u
sal_Int32 nIndex
uno_Any a
Type
constexpr OUStringLiteral WRONG_TYPE_EXCEPTION
unsigned char sal_Bool