|
1 |
|
2 /* |
|
3 * Copyright 2011 Google Inc. |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 |
|
10 #ifndef SkRefDict_DEFINED |
|
11 #define SkRefDict_DEFINED |
|
12 |
|
13 #include "SkRefCnt.h" |
|
14 |
|
15 /** |
|
16 * A dictionary of string,refcnt pairs. The dictionary is also an owner of the |
|
17 * refcnt objects while they are contained. |
|
18 */ |
|
19 class SK_API SkRefDict : SkNoncopyable { |
|
20 public: |
|
21 SkRefDict(); |
|
22 ~SkRefDict(); |
|
23 |
|
24 /** |
|
25 * Return the data associated with name[], or NULL if no matching entry |
|
26 * is found. The reference-count of the entry is not affected. |
|
27 */ |
|
28 SkRefCnt* find(const char name[]) const; |
|
29 |
|
30 /** |
|
31 * If data is NULL, remove (if present) the entry matching name and call |
|
32 * prev_data->unref() on the data for the matching entry. |
|
33 * If data is not-NULL, replace the existing entry matching name and |
|
34 * call (prev_data->unref()), or add a new one. In either case, |
|
35 * data->ref() is called. |
|
36 */ |
|
37 void set(const char name[], SkRefCnt* data); |
|
38 |
|
39 /** |
|
40 * Remove the matching entry (if found) and unref its data. |
|
41 */ |
|
42 void remove(const char name[]) { this->set(name, NULL); } |
|
43 |
|
44 /** |
|
45 * Remove all entries, and unref() their associated data. |
|
46 */ |
|
47 void removeAll(); |
|
48 |
|
49 private: |
|
50 struct Impl; |
|
51 Impl* fImpl; |
|
52 }; |
|
53 |
|
54 #endif |