From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- .../container/NamedPropertyValuesContainer.cxx | 169 +++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 comphelper/source/container/NamedPropertyValuesContainer.cxx (limited to 'comphelper/source/container/NamedPropertyValuesContainer.cxx') diff --git a/comphelper/source/container/NamedPropertyValuesContainer.cxx b/comphelper/source/container/NamedPropertyValuesContainer.cxx new file mode 100644 index 000000000..79a7d714b --- /dev/null +++ b/comphelper/source/container/NamedPropertyValuesContainer.cxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace com::sun::star::uno { class XComponentContext; } +using namespace com::sun::star; + +typedef std::map< OUString, uno::Sequence > NamedPropertyValues; + +namespace { + +class NamedPropertyValuesContainer : public cppu::WeakImplHelper< container::XNameContainer, lang::XServiceInfo > +{ +public: + NamedPropertyValuesContainer() throw(); + + // XNameContainer + virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override; + virtual void SAL_CALL removeByName( const OUString& Name ) override; + + // XNameReplace + virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override; + + // XNameAccess + virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override; + virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override; + + // 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: + NamedPropertyValues maProperties; +}; + +} + +NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw() +{ +} + +// XNameContainer +void SAL_CALL NamedPropertyValuesContainer::insertByName( const OUString& aName, const uno::Any& aElement ) +{ + if( maProperties.find( aName ) != maProperties.end() ) + throw container::ElementExistException(); + + uno::Sequence aProps; + if( !(aElement >>= aProps ) ) + throw lang::IllegalArgumentException(); + + maProperties.emplace( aName, aProps ); +} + +void SAL_CALL NamedPropertyValuesContainer::removeByName( const OUString& Name ) +{ + NamedPropertyValues::iterator aIter = maProperties.find( Name ); + if( aIter == maProperties.end() ) + throw container::NoSuchElementException(); + + maProperties.erase( aIter ); +} + +// XNameReplace +void SAL_CALL NamedPropertyValuesContainer::replaceByName( const OUString& aName, const css::uno::Any& aElement ) +{ + NamedPropertyValues::iterator aIter = maProperties.find( aName ); + if( aIter == maProperties.end() ) + throw container::NoSuchElementException(); + + uno::Sequence aProps; + if( !(aElement >>= aProps) ) + throw lang::IllegalArgumentException(); + + (*aIter).second = aProps; +} + +// XNameAccess +css::uno::Any SAL_CALL NamedPropertyValuesContainer::getByName( const OUString& aName ) +{ + NamedPropertyValues::iterator aIter = maProperties.find( aName ); + if( aIter == maProperties.end() ) + throw container::NoSuchElementException(); + + uno::Any aElement; + + aElement <<= (*aIter).second; + + return aElement; +} + +css::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames( ) +{ + return comphelper::mapKeysToSequence(maProperties); +} + +sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const OUString& aName ) +{ + NamedPropertyValues::iterator aIter = maProperties.find( aName ); + return aIter != maProperties.end(); +} + +// XElementAccess +css::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType( ) +{ + return cppu::UnoType>::get(); +} + +sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements( ) +{ + return !maProperties.empty(); +} + +//XServiceInfo +OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName( ) +{ + return "NamedPropertyValuesContainer"; +} + +sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) +{ + return { "com.sun.star.document.NamedPropertyValues" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +NamedPropertyValuesContainer_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new NamedPropertyValuesContainer()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3