summaryrefslogtreecommitdiffstats
path: root/comphelper/source/container
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper/source/container')
-rw-r--r--comphelper/source/container/IndexedPropertyValuesContainer.cxx56
-rw-r--r--comphelper/source/container/NamedPropertyValuesContainer.cxx8
-rw-r--r--comphelper/source/container/container.cxx5
-rw-r--r--comphelper/source/container/embeddedobjectcontainer.cxx110
-rw-r--r--comphelper/source/container/enumerablemap.cxx36
-rw-r--r--comphelper/source/container/enumhelper.cxx46
-rw-r--r--comphelper/source/container/interfacecontainer2.cxx16
-rw-r--r--comphelper/source/container/namecontainer.cxx5
8 files changed, 130 insertions, 152 deletions
diff --git a/comphelper/source/container/IndexedPropertyValuesContainer.cxx b/comphelper/source/container/IndexedPropertyValuesContainer.cxx
index c0086061b033..9642b5098aa9 100644
--- a/comphelper/source/container/IndexedPropertyValuesContainer.cxx
+++ b/comphelper/source/container/IndexedPropertyValuesContainer.cxx
@@ -17,55 +17,19 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <com/sun/star/container/XIndexContainer.hpp>
-#include <com/sun/star/uno/Sequence.h>
-#include <com/sun/star/beans/PropertyValue.hpp>
-#include <cppuhelper/implbase.hxx>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
-#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <comphelper/indexedpropertyvalues.hxx>
#include <cppuhelper/supportsservice.hxx>
-
-#include <vector>
+#include <o3tl/safeint.hxx>
namespace com::sun::star::uno { class XComponentContext; }
using namespace com::sun::star;
-typedef std::vector < uno::Sequence< beans::PropertyValue > > IndexedPropertyValues;
-
-namespace {
-
-class IndexedPropertyValuesContainer : public cppu::WeakImplHelper< container::XIndexContainer, lang::XServiceInfo >
-{
-public:
- IndexedPropertyValuesContainer() noexcept;
-
- // XIndexContainer
- virtual void SAL_CALL insertByIndex( sal_Int32 nIndex, const css::uno::Any& aElement ) override;
- virtual void SAL_CALL removeByIndex( sal_Int32 nIndex ) override;
-
- // XIndexReplace
- virtual void SAL_CALL replaceByIndex( sal_Int32 nIndex, const css::uno::Any& aElement ) override;
- // XIndexAccess
- virtual sal_Int32 SAL_CALL getCount( ) override;
- virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) override;
+namespace comphelper {
- // XElementAccess
- virtual css::uno::Type SAL_CALL getElementType( ) override;
- virtual sal_Bool SAL_CALL hasElements( ) override;
-
- //XServiceInfo
- virtual OUString SAL_CALL getImplementationName( ) override;
- virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
- virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
-
-private:
- IndexedPropertyValues maProperties;
-};
-
-}
IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() noexcept
{
@@ -80,7 +44,7 @@ void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, c
uno::Sequence<beans::PropertyValue> aProps;
if (!(aElement >>= aProps))
- throw lang::IllegalArgumentException("element is not beans::PropertyValue", static_cast<cppu::OWeakObject*>(this), 2);
+ throw lang::IllegalArgumentException(u"element is not beans::PropertyValue"_ustr, static_cast<cppu::OWeakObject*>(this), 2);
if (nSize == nIndex)
maProperties.push_back(aProps);
else
@@ -89,7 +53,7 @@ void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, c
void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
{
- if ((nIndex >= sal_Int32(maProperties.size())) || (nIndex < 0))
+ if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maProperties.size()))
throw lang::IndexOutOfBoundsException();
maProperties.erase(maProperties.begin() + nIndex);
@@ -104,7 +68,7 @@ void SAL_CALL IndexedPropertyValuesContainer::replaceByIndex( sal_Int32 nIndex,
uno::Sequence<beans::PropertyValue> aProps;
if (!(aElement >>= aProps))
- throw lang::IllegalArgumentException("element is not beans::PropertyValue", static_cast<cppu::OWeakObject*>(this), 2);
+ throw lang::IllegalArgumentException(u"element is not beans::PropertyValue"_ustr, static_cast<cppu::OWeakObject*>(this), 2);
maProperties[nIndex] = aProps;
}
@@ -137,7 +101,7 @@ sal_Bool SAL_CALL IndexedPropertyValuesContainer::hasElements( )
//XServiceInfo
OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName( )
{
- return "IndexedPropertyValuesContainer";
+ return u"IndexedPropertyValuesContainer"_ustr;
}
sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUString& ServiceName )
@@ -147,15 +111,17 @@ sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUStrin
css::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( )
{
- return { "com.sun.star.document.IndexedPropertyValues" };
+ return { u"com.sun.star.document.IndexedPropertyValues"_ustr };
}
+} // namespace comphelper
+
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
IndexedPropertyValuesContainer_get_implementation(
css::uno::XComponentContext *,
css::uno::Sequence<css::uno::Any> const &)
{
- return cppu::acquire(new IndexedPropertyValuesContainer());
+ return cppu::acquire(new comphelper::IndexedPropertyValuesContainer());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/comphelper/source/container/NamedPropertyValuesContainer.cxx b/comphelper/source/container/NamedPropertyValuesContainer.cxx
index a44837f11700..510931cf57dd 100644
--- a/comphelper/source/container/NamedPropertyValuesContainer.cxx
+++ b/comphelper/source/container/NamedPropertyValuesContainer.cxx
@@ -78,7 +78,7 @@ void SAL_CALL NamedPropertyValuesContainer::insertByName( const OUString& aName,
uno::Sequence<beans::PropertyValue> aProps;
if( !(aElement >>= aProps ) )
- throw lang::IllegalArgumentException("element is not beans::PropertyValue", static_cast<cppu::OWeakObject*>(this), 2);
+ throw lang::IllegalArgumentException(u"element is not beans::PropertyValue"_ustr, static_cast<cppu::OWeakObject*>(this), 2);
maProperties.emplace( aName, aProps );
}
@@ -101,7 +101,7 @@ void SAL_CALL NamedPropertyValuesContainer::replaceByName( const OUString& aName
uno::Sequence<beans::PropertyValue> aProps;
if( !(aElement >>= aProps) )
- throw lang::IllegalArgumentException("element is not beans::PropertyValue", static_cast<cppu::OWeakObject*>(this), 2);
+ throw lang::IllegalArgumentException(u"element is not beans::PropertyValue"_ustr, static_cast<cppu::OWeakObject*>(this), 2);
(*aIter).second = aProps;
}
@@ -145,7 +145,7 @@ sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements( )
//XServiceInfo
OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName( )
{
- return "NamedPropertyValuesContainer";
+ return u"NamedPropertyValuesContainer"_ustr;
}
sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString& ServiceName )
@@ -155,7 +155,7 @@ sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString&
css::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( )
{
- return { "com.sun.star.document.NamedPropertyValues" };
+ return { u"com.sun.star.document.NamedPropertyValues"_ustr };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
diff --git a/comphelper/source/container/container.cxx b/comphelper/source/container/container.cxx
index 1a6132e0d65a..7b2432723360 100644
--- a/comphelper/source/container/container.cxx
+++ b/comphelper/source/container/container.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/container/XChild.hpp>
#include <comphelper/container.hxx>
#include <o3tl/any.hxx>
+#include <utility>
#include <osl/diagnose.h>
@@ -29,8 +30,8 @@ namespace comphelper
{
-IndexAccessIterator::IndexAccessIterator(css::uno::Reference< css::uno::XInterface> const & xStartingPoint)
- :m_xStartingPoint(xStartingPoint)
+IndexAccessIterator::IndexAccessIterator(css::uno::Reference< css::uno::XInterface> xStartingPoint)
+ :m_xStartingPoint(std::move(xStartingPoint))
{
OSL_ENSURE(m_xStartingPoint.is(), "IndexAccessIterator::IndexAccessIterator : no starting point !");
}
diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx
index 2d85b73f44ba..1bbf7b847fe4 100644
--- a/comphelper/source/container/embeddedobjectcontainer.cxx
+++ b/comphelper/source/container/embeddedobjectcontainer.cxx
@@ -46,6 +46,8 @@
#include <cppuhelper/weakref.hxx>
#include <sal/log.hxx>
+#include <officecfg/Office/Common.hxx>
+
#include <algorithm>
#include <unordered_map>
@@ -79,17 +81,17 @@ const uno::Reference < embed::XStorage >& EmbedImpl::GetReplacements()
try
{
mxImageStorage = mxStorage->openStorageElement(
- "ObjectReplacements", embed::ElementModes::READWRITE );
+ u"ObjectReplacements"_ustr, embed::ElementModes::READWRITE );
}
catch (const uno::Exception&)
{
mxImageStorage = mxStorage->openStorageElement(
- "ObjectReplacements", embed::ElementModes::READ );
+ u"ObjectReplacements"_ustr, embed::ElementModes::READ );
}
}
if ( !mxImageStorage.is() )
- throw io::IOException("No ObjectReplacements");
+ throw io::IOException(u"No ObjectReplacements"_ustr);
return mxImageStorage;
}
@@ -146,7 +148,7 @@ bool EmbeddedObjectContainer::CommitImageSubStorage()
{
// get the open mode from the parent storage
sal_Int32 nMode = 0;
- uno::Any aAny = xSet->getPropertyValue("OpenMode");
+ uno::Any aAny = xSet->getPropertyValue(u"OpenMode"_ustr);
if ( aAny >>= nMode )
bReadOnlyMode = !(nMode & embed::ElementModes::WRITE );
} // if ( xSet.is() )
@@ -236,8 +238,7 @@ bool EmbeddedObjectContainer::HasEmbeddedObjects() const
bool EmbeddedObjectContainer::HasEmbeddedObject( const OUString& rName )
{
- auto aIt = pImpl->maNameToObjectMap.find( rName );
- if (aIt != pImpl->maNameToObjectMap.end())
+ if (pImpl->maNameToObjectMap.contains(rName))
return true;
if (!pImpl->mxStorage.is())
return false;
@@ -246,7 +247,7 @@ bool EmbeddedObjectContainer::HasEmbeddedObject( const OUString& rName )
bool EmbeddedObjectContainer::HasEmbeddedObject( const uno::Reference < embed::XEmbeddedObject >& xObj ) const
{
- return pImpl->maObjectToNameMap.find(xObj) != pImpl->maObjectToNameMap.end();
+ return pImpl->maObjectToNameMap.contains(xObj);
}
bool EmbeddedObjectContainer::HasInstantiatedEmbeddedObject( const OUString& rName )
@@ -254,8 +255,7 @@ bool EmbeddedObjectContainer::HasInstantiatedEmbeddedObject( const OUString& rNa
// allows to detect whether the object was already instantiated
// currently the filter instantiate it on loading, so this method allows
// to avoid objects pointing to the same persistence
- auto aIt = pImpl->maNameToObjectMap.find( rName );
- return ( aIt != pImpl->maNameToObjectMap.end() );
+ return pImpl->maNameToObjectMap.contains(rName);
}
OUString EmbeddedObjectContainer::GetEmbeddedObjectName( const css::uno::Reference < css::embed::XEmbeddedObject >& xObj ) const
@@ -314,7 +314,7 @@ uno::Reference<embed::XEmbeddedObject> EmbeddedObjectContainer::Get_Impl(
{
// get the open mode from the parent storage
sal_Int32 nMode = 0;
- uno::Any aAny = xSet->getPropertyValue("OpenMode");
+ uno::Any aAny = xSet->getPropertyValue(u"OpenMode"_ustr);
if ( aAny >>= nMode )
bReadOnlyMode = !(nMode & embed::ElementModes::WRITE );
}
@@ -340,7 +340,7 @@ uno::Reference<embed::XEmbeddedObject> EmbeddedObjectContainer::Get_Impl(
}
uno::Sequence< beans::PropertyValue > aMediaDescr{ comphelper::makePropertyValue(
- "ReadOnly", bReadOnlyMode) };
+ u"ReadOnly"_ustr, bReadOnlyMode) };
xObj.set( xFactory->createInstanceInitFromEntry(
pImpl->mxStorage, rName,
aMediaDescr, aObjDescr ), uno::UNO_QUERY );
@@ -557,8 +557,8 @@ uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::InsertEmbedde
// it is correct so for now, but what if somebody introduces a new stream based embedded object?
// Probably introducing of such an object must be restricted ( a storage must be used! ).
uno::Reference< beans::XPropertySet > xProps( xNewStream, uno::UNO_QUERY_THROW );
- xProps->setPropertyValue("MediaType",
- uno::Any( OUString( "application/vnd.sun.star.oleobject" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr,
+ uno::Any( u"application/vnd.sun.star.oleobject"_ustr ) );
}
catch (uno::Exception const& e)
{
@@ -631,7 +631,7 @@ uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::InsertEmbedde
{
uno::Reference < embed::XEmbeddedObjectCreator > xFactory = embed::EmbeddedObjectCreator::create(::comphelper::getProcessComponentContext());
uno::Sequence< beans::PropertyValue > aObjDescr{ comphelper::makePropertyValue(
- "Parent", pImpl->m_xModel.get()) };
+ u"Parent"_ustr, pImpl->m_xModel.get()) };
xObj.set( xFactory->createInstanceLink( pImpl->mxStorage, rNewName, aMedium, aObjDescr ), uno::UNO_QUERY );
uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
@@ -717,9 +717,9 @@ uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::CopyAndGetEmb
embed::EmbeddedObjectCreator::create( ::comphelper::getProcessComponentContext() );
uno::Sequence< beans::PropertyValue > aMediaDescr{ comphelper::makePropertyValue(
- "URL", aURL) };
+ u"URL"_ustr, aURL) };
uno::Sequence< beans::PropertyValue > aObjDescr{ comphelper::makePropertyValue(
- "Parent", pImpl->m_xModel.get()) };
+ u"Parent"_ustr, pImpl->m_xModel.get()) };
xResult.set(xCreator->createInstanceLink(
pImpl->mxStorage,
rName,
@@ -741,7 +741,7 @@ uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::CopyAndGetEmb
embed::EmbeddedObjectCreator::create( ::comphelper::getProcessComponentContext() );
uno::Sequence< beans::PropertyValue > aObjDescr{ comphelper::makePropertyValue(
- "Parent", pImpl->m_xModel.get()) };
+ u"Parent"_ustr, pImpl->m_xModel.get()) };
xResult.set(xCreator->createInstanceInitNew(
xObj->getClassID(),
xObj->getClassName(),
@@ -913,7 +913,7 @@ bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed
// the media type will be provided with object insertion
OUString aOrigStorMediaType;
uno::Reference< beans::XPropertySet > xStorProps( pImpl->mxStorage, uno::UNO_QUERY_THROW );
- static constexpr OUStringLiteral s_sMediaType(u"MediaType");
+ static constexpr OUString s_sMediaType(u"MediaType"_ustr);
xStorProps->getPropertyValue( s_sMediaType ) >>= aOrigStorMediaType;
SAL_WARN_IF( aOrigStorMediaType.isEmpty(), "comphelper.container", "No valuable media type in the storage!" );
@@ -1034,7 +1034,7 @@ uno::Reference < io::XInputStream > EmbeddedObjectContainer::GetGraphicStream( c
uno::Reference < beans::XPropertySet > xSet( xStream, uno::UNO_QUERY );
if ( xSet.is() )
{
- uno::Any aAny = xSet->getPropertyValue("MediaType");
+ uno::Any aAny = xSet->getPropertyValue(u"MediaType"_ustr);
aAny >>= *pMediaType;
}
}
@@ -1071,11 +1071,11 @@ bool EmbeddedObjectContainer::InsertGraphicStream( const css::uno::Reference < c
uno::Reference< beans::XPropertySet > xPropSet( xGraphicStream, uno::UNO_QUERY_THROW );
- xPropSet->setPropertyValue("UseCommonStoragePasswordEncryption",
+ xPropSet->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr,
uno::Any( true ) );
- xPropSet->setPropertyValue("MediaType", uno::Any(rMediaType) );
+ xPropSet->setPropertyValue(u"MediaType"_ustr, uno::Any(rMediaType) );
- xPropSet->setPropertyValue("Compressed",
+ xPropSet->setPropertyValue(u"Compressed"_ustr,
uno::Any( true ) );
}
catch (const uno::Exception&)
@@ -1095,9 +1095,9 @@ bool EmbeddedObjectContainer::InsertGraphicStreamDirectly( const css::uno::Refer
// store it into the subfolder
uno::Sequence< beans::PropertyValue > aProps{
- comphelper::makePropertyValue("MediaType", rMediaType),
- comphelper::makePropertyValue("UseCommonStoragePasswordEncryption", true),
- comphelper::makePropertyValue("Compressed", true)
+ comphelper::makePropertyValue(u"MediaType"_ustr, rMediaType),
+ comphelper::makePropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, true),
+ comphelper::makePropertyValue(u"Compressed"_ustr, true)
};
if ( xReplacement->hasByName( rObjectName ) )
@@ -1135,7 +1135,7 @@ namespace {
try
{
uno::Reference< embed::XStorage > xPictures = xDocStor->openStorageElement(
- "Pictures",
+ u"Pictures"_ustr,
embed::ElementModes::READWRITE );
uno::Reference< io::XStream > xObjReplStr = xPictures->openStreamElement(
aStreamName,
@@ -1158,18 +1158,16 @@ namespace {
}
-bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEmbedded,const uno::Reference < embed::XStorage >& _xStorage)
+bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEmbedded, bool _bAutoSaveEvent,
+ const uno::Reference < embed::XStorage >& _xStorage)
{
bool bResult = false;
try
{
comphelper::EmbeddedObjectContainer aCnt( _xStorage );
- const uno::Sequence < OUString > aNames = GetObjectNames();
- const OUString* pIter = aNames.getConstArray();
- const OUString* pEnd = pIter + aNames.getLength();
- for(;pIter != pEnd;++pIter)
+ for (auto& name : GetObjectNames())
{
- uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( *pIter );
+ uno::Reference<embed::XEmbeddedObject> xObj = GetEmbeddedObject(name);
SAL_WARN_IF( !xObj.is(), "comphelper.container", "An empty entry in the embedded objects list!" );
if ( xObj.is() )
{
@@ -1208,13 +1206,13 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm
{
// if it is an embedded object or the optimized inserting fails the normal inserting should be done
if ( _bCreateEmbedded
- || !aCnt.InsertGraphicStreamDirectly( xStream, *pIter, aMediaType ) )
- aCnt.InsertGraphicStream( xStream, *pIter, aMediaType );
+ || !aCnt.InsertGraphicStreamDirectly(xStream, name, aMediaType))
+ aCnt.InsertGraphicStream(xStream, name, aMediaType);
}
else
{
// it is a linked object exported into SO7 format
- InsertStreamIntoPicturesStorage_Impl( _xStorage, xStream, *pIter );
+ InsertStreamIntoPicturesStorage_Impl(_xStorage, xStream, name);
}
}
}
@@ -1222,7 +1220,7 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm
uno::Reference< embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
if ( xPersist.is() )
{
- uno::Sequence< beans::PropertyValue > aArgs( _bOasisFormat ? 2 : 3 );
+ uno::Sequence< beans::PropertyValue > aArgs( _bOasisFormat ? 3 : 4 );
auto pArgs = aArgs.getArray();
pArgs[0].Name = "StoreVisualReplacement";
pArgs[0].Value <<= !_bOasisFormat;
@@ -1230,11 +1228,15 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm
// if it is an embedded object or the optimized inserting fails the normal inserting should be done
pArgs[1].Name = "CanTryOptimization";
pArgs[1].Value <<= !_bCreateEmbedded;
+
+ pArgs[2].Name = "AutoSaveEvent";
+ pArgs[2].Value <<= _bAutoSaveEvent;
+
if ( !_bOasisFormat )
{
// if object has no cached replacement it will use this one
- pArgs[2].Name = "VisualReplacement";
- pArgs[2].Value <<= xStream;
+ pArgs[3].Name = "VisualReplacement";
+ pArgs[3].Value <<= xStream;
}
try
@@ -1243,7 +1245,7 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm
}
catch (const embed::WrongStateException&)
{
- SAL_WARN("comphelper.container", "failed to store '" << *pIter << "'");
+ SAL_WARN("comphelper.container", "failed to store '" << name << "'");
}
}
@@ -1269,7 +1271,7 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm
try
{
// the substorage still can not be locked by the embedded object container
- OUString aObjReplElement( "ObjectReplacements" );
+ OUString aObjReplElement( u"ObjectReplacements"_ustr );
if ( _xStorage->hasByName( aObjReplElement ) && _xStorage->isStorageElement( aObjReplElement ) )
_xStorage->removeElement( aObjReplElement );
}
@@ -1285,14 +1287,11 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm
bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnly)
{
bool bResult = true;
- const uno::Sequence < OUString > aNames = GetObjectNames();
- const OUString* pIter = aNames.getConstArray();
- const OUString* pEnd = pIter + aNames.getLength();
- for(;pIter != pEnd;++pIter)
+ for (auto& name : GetObjectNames())
{
try
{
- uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( *pIter );
+ uno::Reference<embed::XEmbeddedObject> xObj = GetEmbeddedObject(name);
SAL_WARN_IF( !xObj.is(), "comphelper.container", "An empty entry in the embedded objects list!" );
if ( xObj.is() )
{
@@ -1311,8 +1310,8 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl
&aMediaType );
if ( xStream.is() )
{
- if ( !InsertGraphicStreamDirectly( xStream, *pIter, aMediaType ) )
- InsertGraphicStream( xStream, *pIter, aMediaType );
+ if (!InsertGraphicStreamDirectly(xStream, name, aMediaType))
+ InsertGraphicStream(xStream, name, aMediaType);
}
}
@@ -1336,7 +1335,7 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl
// '_bObjectsOnly' mean we are storing to alien formats.
// 'isStorageElement' mean current object is NOT a MS OLE format. (may also include in future), i120168
if (_bObjectsOnly && (nCurState == embed::EmbedStates::LOADED || nCurState == embed::EmbedStates::RUNNING)
- && (pImpl->mxStorage->isStorageElement( *pIter ) ))
+ && (pImpl->mxStorage->isStorageElement(name)))
{
uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
if ( xModifiable.is() && xModifiable->isModified())
@@ -1373,7 +1372,7 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl
OUString aMediaType;
uno::Reference < io::XInputStream > xInStream = GetGraphicStream( xObj, &aMediaType );
if ( xInStream.is() )
- InsertStreamIntoPicturesStorage_Impl( pImpl->mxStorage, xInStream, *pIter );
+ InsertStreamIntoPicturesStorage_Impl( pImpl->mxStorage, xInStream, name );
}
}
catch (const uno::Exception&)
@@ -1396,7 +1395,7 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl
try
{
ReleaseImageSubStorage();
- OUString aObjReplElement( "ObjectReplacements" );
+ OUString aObjReplElement( u"ObjectReplacements"_ustr );
if ( !_bOasisFormat && pImpl->mxStorage->hasByName( aObjReplElement ) && pImpl->mxStorage->isStorageElement( aObjReplElement ) )
pImpl->mxStorage->removeElement( aObjReplElement );
}
@@ -1439,12 +1438,9 @@ uno::Reference< io::XInputStream > EmbeddedObjectContainer::GetGraphicReplacemen
bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed::XStorage >& _xStorage,bool _bClearModifiedFlag)
{
bool bError = false;
- const uno::Sequence < OUString > aNames = GetObjectNames();
- const OUString* pIter = aNames.getConstArray();
- const OUString* pEnd = pIter + aNames.getLength();
- for(;pIter != pEnd;++pIter)
+ for (auto& name : GetObjectNames())
{
- uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( *pIter );
+ uno::Reference<embed::XEmbeddedObject> xObj = GetEmbeddedObject(name);
SAL_WARN_IF( !xObj.is(), "comphelper.container", "An empty entry in the embedded objects list!" );
if ( xObj.is() )
{
@@ -1454,7 +1450,7 @@ bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed::
try
{
xPersist->setPersistentEntry( _xStorage,
- *pIter,
+ name,
embed::EntryInitModes::NO_INIT,
uno::Sequence< beans::PropertyValue >(),
uno::Sequence< beans::PropertyValue >() );
@@ -1487,6 +1483,8 @@ bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed::
bool EmbeddedObjectContainer::getUserAllowsLinkUpdate() const
{
+ if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get())
+ return false;
return pImpl->mbUserAllowsLinkUpdate;
}
diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx
index 6ca7c36d2d25..87192678fc20 100644
--- a/comphelper/source/container/enumerablemap.cxx
+++ b/comphelper/source/container/enumerablemap.cxx
@@ -31,7 +31,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
-#include <cppuhelper/compbase3.hxx>
+#include <cppuhelper/compbase.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <typelib/typedescription.hxx>
@@ -143,7 +143,7 @@ namespace comphelper
// EnumerableMap
- typedef ::cppu::WeakAggComponentImplHelper3 < XInitialization
+ typedef ::cppu::WeakComponentImplHelper < XInitialization
, XEnumerableMap
, XServiceInfo
> Map_IFace;
@@ -326,31 +326,31 @@ namespace comphelper
sal_Int32 nArgumentCount = _arguments.getLength();
if ( ( nArgumentCount != 2 ) && ( nArgumentCount != 3 ) )
- throw IllegalArgumentException("wrong number of args", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"wrong number of args"_ustr, static_cast<cppu::OWeakObject*>(this), 1);
Type aKeyType, aValueType;
if ( !( _arguments[0] >>= aKeyType ) )
- throw IllegalArgumentException("com.sun.star.uno.Type expected.", *this, 1 );
+ throw IllegalArgumentException(u"com.sun.star.uno.Type expected."_ustr, *this, 1 );
if ( !( _arguments[1] >>= aValueType ) )
- throw IllegalArgumentException("com.sun.star.uno.Type expected.", *this, 2 );
+ throw IllegalArgumentException(u"com.sun.star.uno.Type expected."_ustr, *this, 2 );
Sequence< Pair< Any, Any > > aInitialValues;
bool bMutable = true;
if ( nArgumentCount == 3 )
{
if ( !( _arguments[2] >>= aInitialValues ) )
- throw IllegalArgumentException("[]com.sun.star.beans.Pair<any,any> expected.", *this, 2 );
+ throw IllegalArgumentException(u"[]com.sun.star.beans.Pair<any,any> expected."_ustr, *this, 2 );
bMutable = false;
}
// for the value, anything is allowed, except VOID
if ( ( aValueType.getTypeClass() == TypeClass_VOID ) || ( aValueType.getTypeClass() == TypeClass_UNKNOWN ) )
- throw IllegalTypeException("Unsupported value type.", *this );
+ throw IllegalTypeException(u"Unsupported value type."_ustr, *this );
// create the comparator for the KeyType, and throw if the type is not supported
std::unique_ptr< IKeyPredicateLess > pComparator( getStandardLessPredicate( aKeyType, nullptr ) );
if (!pComparator)
- throw IllegalTypeException("Unsupported key type.", *this );
+ throw IllegalTypeException(u"Unsupported key type."_ustr, *this );
// init members
m_aData.m_aKeyType = aKeyType;
@@ -372,12 +372,10 @@ namespace comphelper
if (!m_aData.m_pValues || !m_aData.m_pValues->empty())
throw RuntimeException();
- const Pair< Any, Any >* mapping = _initialValues.getConstArray();
- const Pair< Any, Any >* mappingEnd = mapping + _initialValues.getLength();
- for ( ; mapping != mappingEnd; ++mapping )
+ for (auto& mapping : _initialValues)
{
- impl_checkValue_throw( mapping->Second );
- (*m_aData.m_pValues)[ mapping->First ] = mapping->Second;
+ impl_checkValue_throw(mapping.Second);
+ (*m_aData.m_pValues)[mapping.First] = mapping.Second;
}
}
@@ -467,7 +465,7 @@ namespace comphelper
if ( _keyOrValue >>= nValue )
if ( std::isnan( nValue ) )
throw IllegalArgumentException(
- "NaN (not-a-number) not supported by this implementation.",
+ u"NaN (not-a-number) not supported by this implementation."_ustr,
*const_cast< EnumerableMap* >( this ), 0 );
// (note that the case of _key not containing a float/double value is handled in the
// respective IKeyPredicateLess implementation, so there's no need to handle this here.)
@@ -479,7 +477,7 @@ namespace comphelper
{
if ( !_key.hasValue() )
throw IllegalArgumentException(
- "NULL keys not supported by this implementation.",
+ u"NULL keys not supported by this implementation."_ustr,
*const_cast< EnumerableMap* >( this ), 0 );
impl_checkNaN_throw( _key, m_aData.m_aKeyType );
@@ -490,7 +488,7 @@ namespace comphelper
{
if ( !m_aData.m_bMutable )
throw NoSupportException(
- "The map is immutable.",
+ u"The map is immutable."_ustr,
*const_cast< EnumerableMap* >( this ) );
}
@@ -639,7 +637,7 @@ namespace comphelper
OUString SAL_CALL EnumerableMap::getImplementationName( )
{
- return "org.openoffice.comp.comphelper.EnumerableMap";
+ return u"org.openoffice.comp.comphelper.EnumerableMap"_ustr;
}
sal_Bool SAL_CALL EnumerableMap::supportsService( const OUString& _serviceName )
@@ -650,7 +648,7 @@ namespace comphelper
Sequence< OUString > SAL_CALL EnumerableMap::getSupportedServiceNames( )
{
- return { "com.sun.star.container.EnumerableMap" };
+ return { u"com.sun.star.container.EnumerableMap"_ustr };
}
bool MapEnumerator::hasMoreElements()
@@ -666,7 +664,7 @@ namespace comphelper
if ( m_disposed )
throw DisposedException( OUString(), m_rParent );
if ( m_mapPos == m_rMapData.m_pValues->end() )
- throw NoSuchElementException("No more elements.", m_rParent );
+ throw NoSuchElementException(u"No more elements."_ustr, m_rParent );
Any aNextElement;
switch ( m_eType )
diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx
index 2487d3adf234..3390fef86444 100644
--- a/comphelper/source/container/enumhelper.cxx
+++ b/comphelper/source/container/enumhelper.cxx
@@ -21,13 +21,14 @@
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
+#include <utility>
namespace comphelper
{
-OEnumerationByName::OEnumerationByName(const css::uno::Reference<css::container::XNameAccess>& _rxAccess)
- :m_aNames(_rxAccess->getElementNames())
- ,m_xAccess(_rxAccess)
+OEnumerationByName::OEnumerationByName(css::uno::Reference<css::container::XNameAccess> _xAccess)
+ :m_aNames(_xAccess->getElementNames())
+ ,m_xAccess(_xAccess)
,m_nPos(0)
,m_bListening(false)
{
@@ -35,17 +36,16 @@ OEnumerationByName::OEnumerationByName(const css::uno::Reference<css::container:
}
-OEnumerationByName::OEnumerationByName(const css::uno::Reference<css::container::XNameAccess>& _rxAccess,
- const css::uno::Sequence< OUString >& _aNames )
- :m_aNames(_aNames)
- ,m_xAccess(_rxAccess)
+OEnumerationByName::OEnumerationByName(css::uno::Reference<css::container::XNameAccess> _xAccess,
+ std::vector<OUString> _aNames )
+ :m_aNames(std::move(_aNames))
+ ,m_xAccess(std::move(_xAccess))
,m_nPos(0)
,m_bListening(false)
{
impl_startDisposeListening();
}
-
OEnumerationByName::~OEnumerationByName()
{
std::lock_guard aLock(m_aLock);
@@ -58,7 +58,7 @@ sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( )
{
std::lock_guard aLock(m_aLock);
- if (m_xAccess.is() && m_aNames.getLength() > m_nPos)
+ if (m_xAccess.is() && getLength() > m_nPos)
return true;
if (m_xAccess.is())
@@ -76,10 +76,10 @@ css::uno::Any SAL_CALL OEnumerationByName::nextElement( )
std::lock_guard aLock(m_aLock);
css::uno::Any aRes;
- if (m_xAccess.is() && m_nPos < m_aNames.getLength())
- aRes = m_xAccess->getByName(m_aNames.getConstArray()[m_nPos++]);
+ if (m_xAccess.is() && m_nPos < getLength())
+ aRes = m_xAccess->getByName(getElement(m_nPos++));
- if (m_xAccess.is() && m_nPos >= m_aNames.getLength())
+ if (m_xAccess.is() && m_nPos >= getLength())
{
impl_stopDisposeListening();
m_xAccess.clear();
@@ -91,7 +91,6 @@ css::uno::Any SAL_CALL OEnumerationByName::nextElement( )
return aRes;
}
-
void SAL_CALL OEnumerationByName::disposing(const css::lang::EventObject& aEvent)
{
std::lock_guard aLock(m_aLock);
@@ -132,8 +131,25 @@ void OEnumerationByName::impl_stopDisposeListening()
osl_atomic_decrement(&m_refCount);
}
-OEnumerationByIndex::OEnumerationByIndex(const css::uno::Reference< css::container::XIndexAccess >& _rxAccess)
- :m_xAccess(_rxAccess)
+sal_Int32 OEnumerationByName::getLength() const
+{
+ if (m_aNames.index() == 0)
+ return std::get<css::uno::Sequence<OUString>>(m_aNames).getLength();
+ else
+ return std::get<std::vector<OUString>>(m_aNames).size();
+}
+
+const OUString& OEnumerationByName::getElement(sal_Int32 nIndex) const
+{
+ if (m_aNames.index() == 0)
+ return std::get<css::uno::Sequence<OUString>>(m_aNames)[nIndex];
+ else
+ return std::get<std::vector<OUString>>(m_aNames)[nIndex];
+}
+
+
+OEnumerationByIndex::OEnumerationByIndex(css::uno::Reference< css::container::XIndexAccess > _xAccess)
+ :m_xAccess(std::move(_xAccess))
,m_nPos(0)
,m_bListening(false)
{
diff --git a/comphelper/source/container/interfacecontainer2.cxx b/comphelper/source/container/interfacecontainer2.cxx
index 0881ccbe44cf..a2e2119be0d2 100644
--- a/comphelper/source/container/interfacecontainer2.cxx
+++ b/comphelper/source/container/interfacecontainer2.cxx
@@ -21,6 +21,7 @@
#include <comphelper/interfacecontainer2.hxx>
#include <comphelper/multicontainer2.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <osl/mutex.hxx>
@@ -103,7 +104,7 @@ void OInterfaceIteratorHelper2::remove()
if( bIsList )
{
OSL_ASSERT( nRemain >= 0 &&
- nRemain < static_cast<sal_Int32>(aData.pAsVector->size()) );
+ o3tl::make_unsigned(nRemain) < aData.pAsVector->size() );
rCont.removeInterface( (*aData.pAsVector)[nRemain] );
}
else
@@ -171,6 +172,9 @@ void OInterfaceContainerHelper2::copyAndResetInUse()
sal_Int32 OInterfaceContainerHelper2::addInterface( const Reference<XInterface> & rListener )
{
OSL_ASSERT( rListener.is() );
+ if ( !rListener.is() )
+ return 0;
+
MutexGuard aGuard( rMutex );
if( bInUse )
copyAndResetInUse();
@@ -244,14 +248,10 @@ Reference<XInterface> OInterfaceContainerHelper2::getInterface( sal_Int32 nIndex
{
MutexGuard aGuard( rMutex );
- if( bIsList )
+ if (bIsList)
return (*aData.pAsVector)[nIndex];
- else if( aData.pAsInterface )
- {
- if (nIndex == 0)
- return aData.pAsInterface;
- }
- throw std::out_of_range("index out of range");
+ assert(aData.pAsInterface && nIndex == 0);
+ return aData.pAsInterface;
}
void OInterfaceContainerHelper2::disposeAndClear( const EventObject & rEvt )
diff --git a/comphelper/source/container/namecontainer.cxx b/comphelper/source/container/namecontainer.cxx
index c13ee7486e80..7e70526ec053 100644
--- a/comphelper/source/container/namecontainer.cxx
+++ b/comphelper/source/container/namecontainer.cxx
@@ -66,7 +66,6 @@ namespace comphelper
}
using namespace ::comphelper;
-using namespace ::osl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
@@ -86,7 +85,7 @@ void SAL_CALL NameContainer::insertByName( const OUString& aName, const Any& aEl
throw ElementExistException();
if( aElement.getValueType() != maType )
- throw IllegalArgumentException("element is wrong type", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException(u"element is wrong type"_ustr, static_cast<cppu::OWeakObject*>(this), 2);
maProperties.emplace(aName,aElement);
}
@@ -113,7 +112,7 @@ void SAL_CALL NameContainer::replaceByName( const OUString& aName, const Any& aE
throw NoSuchElementException();
if( aElement.getValueType() != maType )
- throw IllegalArgumentException("element is wrong type", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException(u"element is wrong type"_ustr, static_cast<cppu::OWeakObject*>(this), 2);
(*aIter).second = aElement;
}