LibreOffice Module vcl (master)  1
UnoGraphicMapper.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
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>
17 
18 #include <memory>
19 #include <unordered_map>
20 
21 using namespace css;
22 
23 namespace
24 {
25 class GraphicMapper : public cppu::WeakImplHelper<graphic::XGraphicMapper, lang::XServiceInfo>
26 {
27 private:
28  std::unordered_map<OUString, uno::Reference<graphic::XGraphic>> maGraphicMap;
29 
30 public:
31  GraphicMapper() = default;
32 
33 protected:
34  // XServiceInfo
35  OUString SAL_CALL getImplementationName() override
36  {
37  return "com.sun.star.comp.graphic.GraphicMapper";
38  }
39  sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override
40  {
41  return cppu::supportsService(this, ServiceName);
42  }
43  css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
44  {
45  return { "com.sun.star.graphic.GraphicMapper" };
46  }
47 
48  // XTypeProvider
49  css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
50  {
51  static const uno::Sequence<uno::Type> aTypes{
54  };
55  return aTypes;
56  }
57  css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
58  {
59  return css::uno::Sequence<sal_Int8>();
60  }
61 
62  // XGraphicMapper
63  css::uno::Reference<css::graphic::XGraphic> SAL_CALL findGraphic(const OUString& rId) override
64  {
65  auto aIterator = maGraphicMap.find(rId);
66 
67  if (aIterator == maGraphicMap.end())
68  return css::uno::Reference<css::graphic::XGraphic>();
69 
70  return aIterator->second;
71  }
72  void SAL_CALL putGraphic(const OUString& rId,
73  css::uno::Reference<css::graphic::XGraphic> const& rGraphic) override
74  {
75  maGraphicMap.emplace(rId, rGraphic);
76  }
77 };
78 }
79 
80 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
82  css::uno::Sequence<css::uno::Any> const&)
83 {
84  return cppu::acquire(new GraphicMapper);
85 }
86 
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_graphic_GraphicMapper_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool
css::uno::Type const & get()
const SvXMLTokenMapEntry aTypes[]