1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include <sal/types.h>
13 #include <basegfx/basegfxdllapi.h>
19 class SystemDependentData
;
20 typedef std::shared_ptr
<SystemDependentData
> SystemDependentData_SharedPtr
;
21 typedef std::weak_ptr
<SystemDependentData
> SystemDependentData_WeakPtr
;
23 class BASEGFX_DLLPUBLIC SystemDependentDataManager
27 SystemDependentDataManager(const SystemDependentDataManager
&) = delete;
28 SystemDependentDataManager
& operator=(const SystemDependentDataManager
&) = delete;
31 SystemDependentDataManager();
32 virtual ~SystemDependentDataManager();
34 // call from (and with) SystemDependentData objects when start/end/touch
36 virtual void startUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
37 virtual void endUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
38 virtual void touchUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
40 // flush all buffered data (e.g. cleanup/shutdown)
41 virtual void flushAll() = 0;
44 class BASEGFX_DLLPUBLIC SystemDependentData
48 SystemDependentData(const SystemDependentData
&) = delete;
49 SystemDependentData
& operator=(const SystemDependentData
&) = delete;
51 // reference to a SystemDependentDataManager, probably
52 // a single, globally used one, but not necessarily
53 SystemDependentDataManager
& mrSystemDependentDataManager
;
55 // Buffered CalculatedCycles, result of estimations using
56 // getHoldCyclesInSeconds and estimateUsageInBytes, executed
57 // using getHoldCyclesInSeconds. StartValue is 0 to detect
58 // not-yet-calculated state
59 sal_uInt32 mnCalculatedCycles
;
63 SystemDependentDataManager
& rSystemDependentDataManager
);
65 // CAUTION! It is VERY important to keep this base class
66 // virtual, else typeid(class).hash_code() from derived classes
67 // will NOT work what is ESSENTIAL for the SystemDependentData
68 // mechanism to work properly. So DO NOT REMOVE virtual here, please.
69 virtual ~SystemDependentData();
71 // allow access to call startUsage/endUsage/touchUsage
72 // using getSystemDependentDataManager()
73 SystemDependentDataManager
& getSystemDependentDataManager() { return mrSystemDependentDataManager
; }
75 // Calculate HoldCyclesInSeconds based on using
76 // getHoldCyclesInSeconds and estimateUsageInBytes, the
77 // result is created once on-demand and buffered in
79 sal_uInt32
calculateCombinedHoldCyclesInSeconds() const;
81 // Allow read access to the calculated cycles in seconds, this
82 // can be e.g. used to determine if this instance got added
83 sal_uInt32
getCombinedHoldCyclesInSeconds() const { return mnCalculatedCycles
; }
85 // Size estimation of the entry in bytes - does not have to
86 // be used, but should be. Default returns zero what
87 // means there is no size estimation available. Override to
88 // offer useful data if you want to have better caching.
89 virtual sal_Int64
estimateUsageInBytes() const;
92 class BASEGFX_DLLPUBLIC SystemDependentDataHolder
95 // Possibility to hold System-Dependent B2DPolygon-Representations
96 std::map
< size_t, SystemDependentData_WeakPtr
> maSystemDependentReferences
;
99 SystemDependentDataHolder(const SystemDependentDataHolder
&) = delete;
100 SystemDependentDataHolder
& operator=(const SystemDependentDataHolder
&) = delete;
103 SystemDependentDataHolder();
104 virtual ~SystemDependentDataHolder();
106 void addOrReplaceSystemDependentData(SystemDependentData_SharedPtr
& rData
);
107 SystemDependentData_SharedPtr
getSystemDependentData(size_t hash_code
) const;
109 } // end of namespace basegfx
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */