crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / vcl / source / graphic / UnoGraphicMapper.cxx
blob6a2e48552c1a5e819c1a6a6fde5be650fe4713d6
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/.
8 */
10 #include <com/sun/star/uno/XComponentContext.hpp>
11 #include <com/sun/star/lang/XServiceInfo.hpp>
12 #include <com/sun/star/graphic/XGraphicMapper.hpp>
13 #include <com/sun/star/graphic/XGraphic.hpp>
14 #include <cppuhelper/implbase.hxx>
15 #include <cppuhelper/supportsservice.hxx>
16 #include <comphelper/unique_disposing_ptr.hxx>
18 #include <memory>
19 #include <unordered_map>
21 using namespace css;
23 namespace
25 class GraphicMapper : public cppu::WeakImplHelper<graphic::XGraphicMapper, lang::XServiceInfo>
27 private:
28 std::unordered_map<OUString, uno::Reference<graphic::XGraphic>> maGraphicMap;
30 public:
31 GraphicMapper() = default;
33 protected:
34 // XServiceInfo
35 OUString SAL_CALL getImplementationName() override
37 return u"com.sun.star.comp.graphic.GraphicMapper"_ustr;
39 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override
41 return cppu::supportsService(this, ServiceName);
43 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
45 return { u"com.sun.star.graphic.GraphicMapper"_ustr };
48 // XTypeProvider
49 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
51 static const uno::Sequence<uno::Type> aTypes{
52 cppu::UnoType<lang::XServiceInfo>::get(), cppu::UnoType<lang::XTypeProvider>::get(),
53 cppu::UnoType<graphic::XGraphicMapper>::get()
55 return aTypes;
57 css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
59 return css::uno::Sequence<sal_Int8>();
62 // XGraphicMapper
63 css::uno::Reference<css::graphic::XGraphic> SAL_CALL findGraphic(const OUString& rId) override
65 auto aIterator = maGraphicMap.find(rId);
67 if (aIterator == maGraphicMap.end())
68 return css::uno::Reference<css::graphic::XGraphic>();
70 return aIterator->second;
72 void SAL_CALL putGraphic(const OUString& rId,
73 css::uno::Reference<css::graphic::XGraphic> const& rGraphic) override
75 maGraphicMap.emplace(rId, rGraphic);
80 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
81 com_sun_star_comp_graphic_GraphicMapper_get_implementation(css::uno::XComponentContext*,
82 css::uno::Sequence<css::uno::Any> const&)
84 return cppu::acquire(new GraphicMapper);
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */