Avoid potential negative array index access to cached text.
[LibreOffice.git] / framework / source / uiconfiguration / graphicnameaccess.cxx
blob6812f5604c263815c9244a1dea9e467f7a9e2feb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <uiconfiguration/graphicnameaccess.hxx>
22 #include <comphelper/sequence.hxx>
24 using namespace ::com::sun::star;
26 namespace framework
29 GraphicNameAccess::GraphicNameAccess()
33 GraphicNameAccess::~GraphicNameAccess()
37 void GraphicNameAccess::addElement( const OUString& rName, const uno::Reference< graphic::XGraphic >& rElement )
39 m_aNameToElementMap.emplace( rName, rElement );
42 // XNameAccess
43 uno::Any SAL_CALL GraphicNameAccess::getByName( const OUString& aName )
45 NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.find( aName );
46 if ( pIter == m_aNameToElementMap.end() )
47 throw container::NoSuchElementException();
48 return uno::Any( pIter->second );
51 uno::Sequence< OUString > SAL_CALL GraphicNameAccess::getElementNames()
53 if ( !m_aSeq.hasElements() )
55 m_aSeq = comphelper::mapKeysToSequence(m_aNameToElementMap);
58 return m_aSeq;
61 sal_Bool SAL_CALL GraphicNameAccess::hasByName( const OUString& aName )
63 NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.find( aName );
64 return ( pIter != m_aNameToElementMap.end() );
67 // XElementAccess
68 sal_Bool SAL_CALL GraphicNameAccess::hasElements()
70 return ( !m_aNameToElementMap.empty() );
73 uno::Type SAL_CALL GraphicNameAccess::getElementType()
75 return cppu::UnoType<graphic::XGraphic>::get();
78 } // namespace framework
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */