epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | 3636ed5 | 2011-01-25 23:50:57 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | 3636ed5 | 2011-01-25 23:50:57 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | 0e190d0 | 2011-01-25 23:36:05 +0000 | [diff] [blame] | 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 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 19 | class SK_API SkRefDict : SkNoncopyable { |
reed@google.com | 0e190d0 | 2011-01-25 23:36:05 +0000 | [diff] [blame] | 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; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 29 | |
reed@google.com | 0e190d0 | 2011-01-25 23:36:05 +0000 | [diff] [blame] | 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 |