2011-11-17 21:29:14 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-08-02 16:10:00 +02:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* Effective License of whole file:
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* the GNU Lesser General Public License Version 2.1
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Contributor(s): Joerg Budischewski
|
|
|
|
*
|
|
|
|
* All parts contributed on or after August 2011:
|
|
|
|
*
|
2013-04-24 17:14:03 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2017-02-06 17:08:38 +01:00
|
|
|
#include <com/sun/star/container/ElementExistException.hpp>
|
|
|
|
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
|
2015-07-13 11:21:57 +09:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
#include "pq_xcontainer.hxx"
|
|
|
|
#include "pq_statics.hxx"
|
|
|
|
#include "pq_tools.hxx"
|
|
|
|
|
|
|
|
using osl::MutexGuard;
|
|
|
|
|
|
|
|
using com::sun::star::beans::XPropertySet;
|
|
|
|
|
|
|
|
using com::sun::star::uno::Any;
|
|
|
|
using com::sun::star::uno::makeAny;
|
|
|
|
using com::sun::star::uno::Type;
|
|
|
|
using com::sun::star::uno::XInterface;
|
|
|
|
using com::sun::star::uno::Reference;
|
|
|
|
using com::sun::star::uno::Sequence;
|
|
|
|
using com::sun::star::uno::RuntimeException;
|
|
|
|
|
|
|
|
using com::sun::star::container::NoSuchElementException;
|
|
|
|
using com::sun::star::container::XEnumeration;
|
|
|
|
using com::sun::star::container::XContainerListener;
|
|
|
|
using com::sun::star::container::ContainerEvent;
|
|
|
|
using com::sun::star::lang::IndexOutOfBoundsException;
|
|
|
|
using com::sun::star::lang::XEventListener;
|
|
|
|
|
|
|
|
|
|
|
|
namespace pq_sdbc_driver
|
|
|
|
{
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2011-08-02 16:10:00 +02:00
|
|
|
class ReplacedBroadcaster : public EventBroadcastHelper
|
|
|
|
{
|
|
|
|
ContainerEvent m_event;
|
|
|
|
public:
|
|
|
|
ReplacedBroadcaster(
|
|
|
|
const Reference< XInterface > & source,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString & name,
|
2011-08-02 16:10:00 +02:00
|
|
|
const Any & newElement,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString & oldElement ) :
|
2011-08-02 16:10:00 +02:00
|
|
|
m_event( source, makeAny( name ), newElement, makeAny(oldElement) )
|
|
|
|
{}
|
|
|
|
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void fire( XEventListener * listener ) const override
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-10-02 08:40:50 +02:00
|
|
|
static_cast<XContainerListener*>(listener)->elementReplaced( m_event );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual Type getType() const override
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-05-22 23:19:05 +02:00
|
|
|
return cppu::UnoType<XContainerListener>::get();
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class InsertedBroadcaster : public EventBroadcastHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContainerEvent m_event;
|
|
|
|
InsertedBroadcaster(
|
|
|
|
const Reference< XInterface > & source,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString & name,
|
2011-08-02 16:10:00 +02:00
|
|
|
const Any & newElement ) :
|
|
|
|
m_event( source, makeAny( name ), newElement, Any() )
|
|
|
|
{}
|
|
|
|
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void fire( XEventListener * listener ) const override
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-10-02 08:40:50 +02:00
|
|
|
static_cast<XContainerListener*>(listener)->elementInserted( m_event );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual Type getType() const override
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-05-22 23:19:05 +02:00
|
|
|
return cppu::UnoType<XContainerListener>::get();
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class RemovedBroadcaster : public EventBroadcastHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContainerEvent m_event;
|
|
|
|
RemovedBroadcaster(
|
|
|
|
const Reference< XInterface > & source,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString & name) :
|
2011-08-02 16:10:00 +02:00
|
|
|
m_event( source, makeAny( name ), Any(), Any() )
|
|
|
|
{}
|
|
|
|
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void fire( XEventListener * listener ) const override
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-10-02 08:40:50 +02:00
|
|
|
static_cast<XContainerListener*>(listener)->elementRemoved( m_event );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual Type getType() const override
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-05-22 23:19:05 +02:00
|
|
|
return cppu::UnoType<XContainerListener>::get();
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2011-08-02 16:10:00 +02:00
|
|
|
Container::Container(
|
2017-06-19 17:06:34 +02:00
|
|
|
const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::sdbc::XConnection > & origin,
|
2011-08-02 16:10:00 +02:00
|
|
|
ConnectionSettings *pSettings,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString &type)
|
2017-06-19 17:06:34 +02:00
|
|
|
: ContainerBase( refMutex->GetMutex() ),
|
|
|
|
m_xMutex( refMutex ),
|
2011-08-02 16:10:00 +02:00
|
|
|
m_pSettings( pSettings ),
|
|
|
|
m_origin( origin ),
|
|
|
|
m_type( type )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
Any Container::getByName( const OUString& aName )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
String2IntMap::const_iterator ii = m_name2index.find( aName );
|
|
|
|
if( ii == m_name2index.end() )
|
|
|
|
{
|
2017-02-01 12:24:07 +02:00
|
|
|
throw NoSuchElementException(
|
|
|
|
"Element " + aName + " unknown in " + m_type + "-Container",
|
|
|
|
*this );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
2018-01-12 20:27:27 +01:00
|
|
|
OSL_ASSERT( ii->second >= 0 && ii->second < static_cast<int>(m_values.size()) );
|
2011-08-02 16:10:00 +02:00
|
|
|
return m_values[ ii->second ];
|
|
|
|
}
|
|
|
|
|
|
|
|
Sequence< OUString > Container::getElementNames( )
|
|
|
|
{
|
2016-02-07 12:04:02 +02:00
|
|
|
Sequence< OUString > ret( m_values.size() );
|
2019-03-09 15:54:13 +03:00
|
|
|
for( const auto& [rName, rIndex] : m_name2index )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
// give element names in index order !
|
2019-03-09 15:54:13 +03:00
|
|
|
ret[rIndex] = rName;
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
sal_Bool Container::hasByName( const OUString& aName )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
return m_name2index.find( aName ) != m_name2index.end();
|
|
|
|
}
|
|
|
|
// Methods
|
|
|
|
Type Container::getElementType( )
|
|
|
|
{
|
|
|
|
return Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool Container::hasElements( )
|
|
|
|
{
|
|
|
|
return ! m_name2index.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
Any Container::getByIndex( sal_Int32 Index )
|
|
|
|
{
|
2018-01-12 20:27:27 +01:00
|
|
|
if( Index < 0 || Index >= static_cast<sal_Int32>(m_values.size()) )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2017-02-01 12:24:07 +02:00
|
|
|
throw IndexOutOfBoundsException(
|
|
|
|
"Index " + OUString::number( Index )
|
|
|
|
+ " out of range for " + m_type + "-Container, expected 0 <= x <= "
|
|
|
|
+ OUString::number(m_values.size() -1),
|
|
|
|
*this );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
return m_values[Index];
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 Container::getCount()
|
|
|
|
{
|
2016-02-07 12:04:02 +02:00
|
|
|
return m_values.size();
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
2011-08-02 16:10:00 +02:00
|
|
|
|
2015-07-13 11:21:57 +09:00
|
|
|
class ContainerEnumeration : public ::cppu::WeakImplHelper< XEnumeration >
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2016-05-27 12:31:29 +02:00
|
|
|
std::vector< css::uno::Any > m_vec;
|
2011-08-02 16:10:00 +02:00
|
|
|
sal_Int32 m_index;
|
|
|
|
public:
|
2016-05-27 12:31:29 +02:00
|
|
|
explicit ContainerEnumeration( const std::vector< css::uno::Any > &vec )
|
2011-08-02 16:10:00 +02:00
|
|
|
: m_vec( vec ),
|
|
|
|
m_index( -1 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// XEnumeration
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Bool SAL_CALL hasMoreElements( ) override;
|
|
|
|
virtual css::uno::Any SAL_CALL nextElement( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2011-08-02 16:10:00 +02:00
|
|
|
sal_Bool ContainerEnumeration::hasMoreElements()
|
|
|
|
{
|
2018-01-12 20:27:27 +01:00
|
|
|
return static_cast<int>(m_vec.size()) > m_index +1;
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
2016-05-27 12:31:29 +02:00
|
|
|
css::uno::Any ContainerEnumeration::nextElement()
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
if( ! hasMoreElements() )
|
|
|
|
{
|
|
|
|
throw NoSuchElementException(
|
2013-02-01 09:33:19 +01:00
|
|
|
"NoSuchElementException during enumeration", *this );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
m_index ++;
|
|
|
|
return m_vec[m_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XEnumeration > Container::createEnumeration( )
|
|
|
|
{
|
|
|
|
return new ContainerEnumeration( m_values );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Container::addRefreshListener(
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::util::XRefreshListener >& l )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2015-04-01 08:36:20 +02:00
|
|
|
rBHelper.addListener( cppu::UnoType<decltype(l)>::get() , l );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Container::removeRefreshListener(
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::util::XRefreshListener >& l )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2015-04-01 08:36:20 +02:00
|
|
|
rBHelper.removeListener( cppu::UnoType<decltype(l)>::get() , l );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Container::disposing()
|
|
|
|
{
|
|
|
|
m_origin.clear();
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void Container::rename( const OUString &oldName, const OUString &newName )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
Any newValue;
|
|
|
|
{
|
2017-06-19 17:06:34 +02:00
|
|
|
osl::MutexGuard guard ( m_xMutex->GetMutex() );
|
2011-08-02 16:10:00 +02:00
|
|
|
String2IntMap::iterator ii = m_name2index.find( oldName );
|
|
|
|
if( ii != m_name2index.end() )
|
|
|
|
{
|
|
|
|
sal_Int32 nIndex = ii->second;
|
|
|
|
newValue = m_values[nIndex];
|
|
|
|
m_name2index.erase( ii );
|
|
|
|
m_name2index[ newName ] = nIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fire( ReplacedBroadcaster( *this, newName, newValue, oldName ) );
|
|
|
|
fire( RefreshedBroadcaster( *this ) );
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void Container::dropByName( const OUString& elementName )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2017-06-19 17:06:34 +02:00
|
|
|
osl::MutexGuard guard( m_xMutex->GetMutex() );
|
2011-08-02 16:10:00 +02:00
|
|
|
String2IntMap::const_iterator ii = m_name2index.find( elementName );
|
|
|
|
if( ii == m_name2index.end() )
|
|
|
|
{
|
2016-05-27 12:31:29 +02:00
|
|
|
throw css::container::NoSuchElementException(
|
2017-02-01 12:24:07 +02:00
|
|
|
"Column " + elementName + " is unknown in "
|
|
|
|
+ m_type + " container, so it can't be dropped",
|
|
|
|
*this );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
dropByIndex( ii->second );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Container::dropByIndex( sal_Int32 index )
|
|
|
|
{
|
2017-06-19 17:06:34 +02:00
|
|
|
osl::MutexGuard guard( m_xMutex->GetMutex() );
|
2018-01-12 20:27:27 +01:00
|
|
|
if( index < 0 || index >=static_cast<sal_Int32>(m_values.size()) )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2016-05-27 12:31:29 +02:00
|
|
|
throw css::lang::IndexOutOfBoundsException(
|
2017-02-01 12:24:07 +02:00
|
|
|
"Index out of range (allowed 0 to "
|
|
|
|
+ OUString::number(m_values.size() -1)
|
|
|
|
+ ", got " + OUString::number( index )
|
|
|
|
+ ") in " + m_type,
|
|
|
|
*this );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString name;
|
2019-03-09 15:54:13 +03:00
|
|
|
String2IntMap::iterator ii = std::find_if(m_name2index.begin(), m_name2index.end(),
|
|
|
|
[&index](const String2IntMap::value_type& rEntry) { return rEntry.second == index; });
|
|
|
|
if (ii != m_name2index.end())
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2019-03-09 15:54:13 +03:00
|
|
|
name = ii->first;
|
|
|
|
m_name2index.erase( ii );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
2018-01-12 20:27:27 +01:00
|
|
|
for( int i = index +1 ; i < static_cast<int>(m_values.size()) ; i ++ )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
m_values[i-1] = m_values[i];
|
|
|
|
|
|
|
|
// I know, this is expensive, but don't want to maintain another map ...
|
2019-03-09 15:54:13 +03:00
|
|
|
ii = std::find_if(m_name2index.begin(), m_name2index.end(),
|
|
|
|
[&i](const String2IntMap::value_type& rEntry) { return rEntry.second == i; });
|
|
|
|
if (ii != m_name2index.end())
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2019-03-09 15:54:13 +03:00
|
|
|
ii->second = i-1;
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
}
|
2016-02-07 12:04:02 +02:00
|
|
|
m_values.resize( m_values.size() - 1 );
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
fire( RemovedBroadcaster( *this, name ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Container::append(
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString & name,
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::beans::XPropertySet >& descriptor )
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
{
|
2017-06-19 17:06:34 +02:00
|
|
|
osl::MutexGuard guard( m_xMutex->GetMutex() );
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
if( hasByName( name ) )
|
|
|
|
{
|
2016-05-27 12:31:29 +02:00
|
|
|
throw css::container::ElementExistException(
|
2017-02-01 12:24:07 +02:00
|
|
|
"a " + m_type + " with name " + name + " already exists in this container",
|
|
|
|
*this );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 12:04:02 +02:00
|
|
|
int index = m_values.size();
|
|
|
|
m_values.push_back( makeAny( descriptor ) );
|
2011-08-02 16:10:00 +02:00
|
|
|
m_name2index[name] = index;
|
|
|
|
|
|
|
|
fire( InsertedBroadcaster( *this, name, makeAny( descriptor ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Container::appendByDescriptor(
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::beans::XPropertySet >& descriptor)
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
|
|
|
append( extractStringProperty( descriptor, getStatics().NAME ), descriptor );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Container::addContainerListener(
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::container::XContainerListener >& l )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2015-04-01 08:36:20 +02:00
|
|
|
rBHelper.addListener( cppu::UnoType<decltype(l)>::get() , l );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Container::removeContainerListener(
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::container::XContainerListener >& l )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2015-04-01 08:36:20 +02:00
|
|
|
rBHelper.removeListener( cppu::UnoType<decltype(l)>::get() , l );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Container::fire( const EventBroadcastHelper &helper )
|
|
|
|
{
|
|
|
|
cppu::OInterfaceContainerHelper *container = rBHelper.getContainer( helper.getType() );
|
|
|
|
if( container )
|
|
|
|
{
|
|
|
|
cppu::OInterfaceIteratorHelper iterator( * container );
|
|
|
|
while( iterator.hasMoreElements() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-10-02 08:40:50 +02:00
|
|
|
helper.fire( static_cast<XEventListener *>(iterator.next()) );
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
2016-05-27 12:31:29 +02:00
|
|
|
catch ( css::uno::RuntimeException & )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2017-06-23 12:47:20 +02:00
|
|
|
OSL_ENSURE( false, "exception caught" );
|
2011-08-02 16:10:00 +02:00
|
|
|
// loose coupling, a runtime exception shall not break anything
|
|
|
|
// TODO: log away as warning !
|
|
|
|
}
|
2016-05-27 12:31:29 +02:00
|
|
|
catch( css::uno::Exception & )
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2014-01-28 19:56:39 +01:00
|
|
|
OSL_ENSURE( false, "exception from listener flying through" );
|
2011-08-02 16:10:00 +02:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-18 12:11:15 +00:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|