-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyweightTypes.h
More file actions
37 lines (29 loc) · 1008 Bytes
/
Copy pathFlyweightTypes.h
File metadata and controls
37 lines (29 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef BaseLib_Templates_FlyweightTypes_h_Included
#define BaseLib_Templates_FlyweightTypes_h_Included
#include"BaseLib/CommonDefines.h"
#include"BaseLib/Templates/Synchronization.h"
#include"BaseLib/Templates/DoubleCheckedLocking.h"
namespace BaseLib { namespace Templates
{
/**
* Implements a flyweight approach, where the object maintains a map of weak-references to generic type DATA.
*/
template <typename DATA>
class FlyweightWeakReference
: public LockableType< FlyweightWeakReference<DATA> >
{
private:
CLASS_TRAITS(DATA)
public:
virtual ~FlyweightWeakReference() {}
/**
* Return existing flyweight instance, or creates a new if no such exists.
*/
template <typename MapCollection>
typename DATA::Ptr Unique(MapCollection uniqueData, typename DATA::Ptr state)
{
return DoubleCheckedLocking::UniqueWeakPtr<FlyweightWeakReference<DATA>, typename DATA::Ptr, typename DATA::WeakPtr, MapCollection>(this, uniqueData, state);
}
};
}}
#endif