cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / inc / tools / IconCache.hxx
blobfef994764f880cf607ac9117255fd3e1c1ef435e
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 #pragma once
22 #include <memory>
23 #include <tools/SdGlobalResourceContainer.hxx>
24 #include <vcl/image.hxx>
26 namespace sd
28 /** This simple class stores frequently used icons so that the classes that
29 use the icons do not have to store them in every one of their
30 instances.
32 Icons are addressed over their resource id and are loaded on demand.
34 This cache acts like a singleton with a lifetime equal to that of the sd
35 module.
37 class IconCache final : public SdGlobalResource
39 public:
40 /** The lifetime of the returned reference is limited to that of the sd
41 module.
43 static IconCache& Instance();
45 /** Return the icon with the given resource id.
46 @return
47 The returned Image may be empty when there is no icon for the
48 given id or an error occurred. Should not happen under normal
49 circumstances.
51 Image GetIcon(const OUString& rResourceId);
53 private:
54 class Implementation;
55 ::std::unique_ptr<Implementation> mpImpl;
57 /** The constructor creates the one instance of the cache and registers
58 it at the SdGlobalResourceContainer to limit is lifetime to that of
59 the sd module.
61 IconCache();
63 /** This destructor is called by SdGlobalResourceContainer.
65 virtual ~IconCache() override;
68 } // end of namespace sd
70 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */