@@ -12,7 +12,7 @@ namespace sd
12
12
13
13
struct ICacheItem
14
14
{
15
- using Ptr = std::unique_ptr<ICacheItem>;
15
+ using UPtr = std::unique_ptr<ICacheItem>;
16
16
17
17
template <class T > const CacheItem<T> *Upcast () const { return dynamic_cast <const CacheItem<T> *>(this ); }
18
18
@@ -21,17 +21,17 @@ namespace sd
21
21
template <class T > const T *As () const
22
22
{
23
23
auto casted = Upcast<T>();
24
- return casted ? casted->Typed () : nullptr ;
24
+ return casted ? casted->Ptr () : nullptr ;
25
25
}
26
26
27
27
template <class T > T *As ()
28
28
{
29
29
auto casted = Upcast<T>();
30
- return casted ? casted->Typed () : nullptr ;
30
+ return casted ? casted->Ptr () : nullptr ;
31
31
}
32
32
33
- virtual const void *Raw () const = 0;
34
- virtual void *Raw () = 0;
33
+ virtual const void *RawPtr () const = 0;
34
+ virtual void *RawPtr () = 0;
35
35
36
36
virtual ~ICacheItem (){};
37
37
};
@@ -42,32 +42,32 @@ namespace sd
42
42
T _value;
43
43
44
44
public:
45
- using Ptr = std::unique_ptr<CacheItem<T>>;
45
+ using UPtr = std::unique_ptr<CacheItem<T>>;
46
46
47
- static Ptr Make (T &&value) { return Ptr (new CacheItem<T>(std::move (value))); }
47
+ static UPtr Make (T &&value) { return UPtr (new CacheItem<T>(std::move (value))); }
48
48
49
49
CacheItem (T &&value) : _value(std::move(value)) {}
50
50
51
- const void *Raw () const { return &_value; }
51
+ const void *RawPtr () const { return &_value; }
52
52
53
- void *Raw () { return &_value; }
53
+ void *RawPtr () { return &_value; }
54
54
55
- const T *Typed () const { return &_value; }
55
+ const T *Ptr () const { return &_value; }
56
56
57
- T *Typed () { return &_value; }
57
+ T *Ptr () { return &_value; }
58
58
59
- const T & operator ->() const { return _value; }
59
+ const T * operator ->() const { return & _value; }
60
60
61
61
const T &operator *() const { return _value; }
62
62
63
- T & operator ->() { return _value; }
63
+ T * operator ->() { return & _value; }
64
64
65
65
T &operator *() { return _value; }
66
66
};
67
67
68
68
struct ICachePolicy
69
69
{
70
- using Ptr = std::unique_ptr<ICachePolicy>;
70
+ using UPtr = std::unique_ptr<ICachePolicy>;
71
71
72
72
virtual void CallOnRemove (const ICacheItem *value) const = 0;
73
73
virtual void CallOnUpdate (const ICacheItem *oldValue, const ICacheItem *newValue) const = 0;
@@ -86,11 +86,11 @@ namespace sd
86
86
RemoveCallback _removeCallback;
87
87
88
88
public:
89
- using Ptr = std::unique_ptr<CachePolicy<TValue>>;
89
+ using UPtr = std::unique_ptr<CachePolicy<TValue>>;
90
90
91
- Ptr static Make (UpdateCallback updateCallback = nullptr , RemoveCallback removeCallback = nullptr )
91
+ UPtr static Make (UpdateCallback updateCallback = nullptr , RemoveCallback removeCallback = nullptr )
92
92
{
93
- return Ptr (new CachePolicy<TValue>(updateCallback, removeCallback));
93
+ return UPtr (new CachePolicy<TValue>(updateCallback, removeCallback));
94
94
}
95
95
96
96
CachePolicy (UpdateCallback updateCallback = nullptr , RemoveCallback removeCallback = nullptr )
@@ -121,9 +121,9 @@ namespace sd
121
121
122
122
struct ICache
123
123
{
124
- virtual bool Add (const std::string &key, ICacheItem::Ptr value, ICachePolicy::Ptr policy = nullptr ) = 0;
124
+ virtual bool Add (const std::string &key, ICacheItem::UPtr value, ICachePolicy::UPtr policy = nullptr ) = 0;
125
125
126
- virtual bool Set (const std::string &key, ICacheItem::Ptr value, ICachePolicy::Ptr policy = nullptr ) = 0;
126
+ virtual bool Set (const std::string &key, ICacheItem::UPtr value, ICachePolicy::UPtr policy = nullptr ) = 0;
127
127
128
128
virtual const void *Get (const std::string &key) const = 0;
129
129
@@ -143,8 +143,8 @@ namespace sd
143
143
private:
144
144
struct Data
145
145
{
146
- ICacheItem::Ptr item;
147
- ICachePolicy::Ptr policy;
146
+ ICacheItem::UPtr item;
147
+ ICachePolicy::UPtr policy;
148
148
};
149
149
150
150
std::unordered_map<std::string, Data> _items;
@@ -157,35 +157,35 @@ namespace sd
157
157
Cache &operator =(const Cache &) = delete ;
158
158
Cache &operator =(Cache &&) = delete ;
159
159
160
- template <class T > bool Add (const std::string &key, T &&value, typename CachePolicy<T>::Ptr policy = nullptr )
160
+ template <class T > bool Add (const std::string &key, T &&value, typename CachePolicy<T>::UPtr policy = nullptr )
161
161
{
162
162
return Add<T>(key, CacheItem<T>::Make (std::move (value)), std::move (policy));
163
163
}
164
164
165
165
template <class T >
166
- bool Add (const std::string &key, typename CacheItem<T>::Ptr itemPtr,
167
- typename CachePolicy<T>::Ptr policy = nullptr )
166
+ bool Add (const std::string &key, typename CacheItem<T>::UPtr itemPtr,
167
+ typename CachePolicy<T>::UPtr policy = nullptr )
168
168
{
169
- ICacheItem::Ptr itemPtrCasted = std::move (itemPtr);
169
+ ICacheItem::UPtr itemPtrCasted = std::move (itemPtr);
170
170
return Add (key, std::move (itemPtrCasted), std::move (policy));
171
171
}
172
172
173
- bool Add (const std::string &key, ICacheItem::Ptr itemPtr, ICachePolicy::Ptr policy = nullptr ) final ;
173
+ bool Add (const std::string &key, ICacheItem::UPtr itemPtr, ICachePolicy::UPtr policy = nullptr ) final ;
174
174
175
- template <class T > bool Set (const std::string &key, T &&value, typename CachePolicy<T>::Ptr policy = nullptr )
175
+ template <class T > bool Set (const std::string &key, T &&value, typename CachePolicy<T>::UPtr policy = nullptr )
176
176
{
177
177
return Set<T>(key, CacheItem<T>::Make (std::move (value)), std::move (policy));
178
178
}
179
179
180
180
template <class T >
181
- bool Set (const std::string &key, typename CacheItem<T>::Ptr itemPtr,
182
- typename CachePolicy<T>::Ptr policy = nullptr )
181
+ bool Set (const std::string &key, typename CacheItem<T>::UPtr itemPtr,
182
+ typename CachePolicy<T>::UPtr policy = nullptr )
183
183
{
184
- ICacheItem::Ptr itemPtrCasted = std::move (itemPtr);
184
+ ICacheItem::UPtr itemPtrCasted = std::move (itemPtr);
185
185
return Set (key, std::move (itemPtrCasted), std::move (policy));
186
186
}
187
187
188
- bool Set (const std::string &key, ICacheItem::Ptr itemPtr, ICachePolicy::Ptr policy = nullptr ) final ;
188
+ bool Set (const std::string &key, ICacheItem::UPtr itemPtr, ICachePolicy::UPtr policy = nullptr ) final ;
189
189
190
190
template <class TValue > const TValue *Get (const std::string &key) const
191
191
{
@@ -238,13 +238,13 @@ namespace sd
238
238
CacheWrapper &operator =(CacheWrapper &&) = delete ;
239
239
240
240
template <class TValue >
241
- bool Add (const std::string &key, TValue &&value, typename CachePolicy<TValue>::Ptr policy = nullptr )
241
+ bool Add (const std::string &key, TValue &&value, typename CachePolicy<TValue>::UPtr policy = nullptr )
242
242
{
243
243
return _cache.Add <TValue>(BuildKey<TValue>(key), std::move (value), std::move (policy));
244
244
}
245
245
246
246
template <class TValue >
247
- bool Set (const std::string &key, TValue &&value, typename CachePolicy<TValue>::Ptr policy = nullptr )
247
+ bool Set (const std::string &key, TValue &&value, typename CachePolicy<TValue>::UPtr policy = nullptr )
248
248
{
249
249
return _cache.Set <TValue>(BuildKey<TValue>(key), std::move (value), std::move (policy));
250
250
}
0 commit comments