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/.
10 #ifndef INCLUDED_BASEGFX_SYSTEMDEPENDENTDATA_HXX
11 #define INCLUDED_BASEGFX_SYSTEMDEPENDENTDATA_HXX
13 #include <sal/types.h>
14 #include <basegfx/basegfxdllapi.h>
21 class SystemDependentData
;
22 typedef std::shared_ptr
<SystemDependentData
> SystemDependentData_SharedPtr
;
23 typedef std::weak_ptr
<SystemDependentData
> SystemDependentData_WeakPtr
;
24 } // end of namespace basegfx
28 class BASEGFX_DLLPUBLIC SystemDependentDataManager
32 SystemDependentDataManager(const SystemDependentDataManager
&) = delete;
33 SystemDependentDataManager
& operator=(const SystemDependentDataManager
&) = delete;
36 SystemDependentDataManager();
37 virtual ~SystemDependentDataManager();
39 // call from (and with) SystemDependentData objects when start/end/touch
41 virtual void startUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
42 virtual void endUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
43 virtual void touchUsage(basegfx::SystemDependentData_SharedPtr
& rData
) = 0;
45 // flush all buffered data (e.g. cleanup/shutdown)
46 virtual void flushAll() = 0;
48 } // end of namespace basegfx
52 class BASEGFX_DLLPUBLIC MinimalSystemDependentDataManager final
: public SystemDependentDataManager
55 // example of a minimal SystemDependentDataManager. It *needs to hold*
56 // a SystemDependentData_SharedPtr while SystemDependentDataHolder's will
57 // use a SystemDependentData_WeakPtr. When the held SystemDependentData_SharedPtr
58 // is deleted, the corresponding SystemDependentData_WeakPtr will get void.
59 // To make this work, a minimal SystemDependentDataManager *has* to hold at
60 // least that one SystemDependentData_SharedPtr.
61 // That SystemDependentData_SharedPtr may be (e.g. Timer-based or resource-based)
62 // be freed then. This minimal implementation does never free it, so all stay valid.
63 // The instances may still be removed by endUsage calls, but there is no
64 // caching/buffering mechanism involved here at all. It's an example, but
65 // not used - better use an advanced derivation of SystemDependentDataManager
66 std::set
< SystemDependentData_SharedPtr
> maSystemDependentDataReferences
;
69 MinimalSystemDependentDataManager();
70 virtual ~MinimalSystemDependentDataManager() override
;
72 virtual void startUsage(basegfx::SystemDependentData_SharedPtr
& rData
) override
;
73 virtual void endUsage(basegfx::SystemDependentData_SharedPtr
& rData
) override
;
74 virtual void touchUsage(basegfx::SystemDependentData_SharedPtr
& rData
) override
;
75 virtual void flushAll() override
;
77 } // end of namespace basegfx
81 class BASEGFX_DLLPUBLIC SystemDependentData
85 SystemDependentData(const SystemDependentData
&) = delete;
86 SystemDependentData
& operator=(const SystemDependentData
&) = delete;
88 // reference to a SystemDependentDataManager, probably
89 // a single, globally used one, but not necessarily
90 SystemDependentDataManager
& mrSystemDependentDataManager
;
92 // Buffered CalculatedCycles, result of estimations using
93 // getHoldCyclesInSeconds and estimateUsageInBytes, executed
94 // using getHoldCyclesInSeconds. StartValue is 0 to detect
95 // not-yet-calculated state
96 sal_uInt32 mnCalculatedCycles
;
100 SystemDependentDataManager
& rSystemDependentDataManager
);
102 // CAUTION! It is VERY important to keep this base class
103 // virtual, else typeid(class).hash_code() from derived classes
104 // will NOT work what is ESSENTIAL for the SystemDependentData
105 // mechanism to work properly. So DO NOT REMOVE virtual here, please.
106 virtual ~SystemDependentData();
108 // allow access to call startUsage/endUsage/touchUsage
109 // using getSystemDependentDataManager()
110 SystemDependentDataManager
& getSystemDependentDataManager() { return mrSystemDependentDataManager
; }
112 // Calculate HoldCyclesInSeconds based on using
113 // getHoldCyclesInSeconds and estimateUsageInBytes, the
114 // result is created once on-demand and buffered in
115 // mnCalculatedCycles
116 sal_uInt32
calculateCombinedHoldCyclesInSeconds() const;
118 // Size estimation of the entry in bytes - does not have to
119 // be used, but should be. Default returns zero what
120 // means there is no size estimation available. Override to
121 // offer useful data if you want to have better caching.
122 virtual sal_Int64
estimateUsageInBytes() const;
124 } // end of namespace basegfx
128 class BASEGFX_DLLPUBLIC SystemDependentDataHolder
131 // Possibility to hold System-Dependent B2DPolygon-Representations
132 std::map
< size_t, SystemDependentData_WeakPtr
> maSystemDependentReferences
;
135 SystemDependentDataHolder(const SystemDependentDataHolder
&) = delete;
136 SystemDependentDataHolder
& operator=(const SystemDependentDataHolder
&) = delete;
139 SystemDependentDataHolder();
140 virtual ~SystemDependentDataHolder();
142 void addOrReplaceSystemDependentData(SystemDependentData_SharedPtr
& rData
);
143 SystemDependentData_SharedPtr
getSystemDependentData(size_t hash_code
) const;
145 } // end of namespace basegfx
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */