reed@google.com | 3636ed5 | 2011-01-25 23:50:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2011 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
reed@google.com | 0e190d0 | 2011-01-25 23:36:05 +0000 | [diff] [blame] | 17 | #ifndef SkRefDict_DEFINED |
| 18 | #define SkRefDict_DEFINED |
| 19 | |
| 20 | #include "SkRefCnt.h" |
| 21 | |
| 22 | /** |
| 23 | * A dictionary of string,refcnt pairs. The dictionary is also an owner of the |
| 24 | * refcnt objects while they are contained. |
| 25 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame^] | 26 | class SK_API SkRefDict : SkNoncopyable { |
reed@google.com | 0e190d0 | 2011-01-25 23:36:05 +0000 | [diff] [blame] | 27 | public: |
| 28 | SkRefDict(); |
| 29 | ~SkRefDict(); |
| 30 | |
| 31 | /** |
| 32 | * Return the data associated with name[], or NULL if no matching entry |
| 33 | * is found. The reference-count of the entry is not affected. |
| 34 | */ |
| 35 | SkRefCnt* find(const char name[]) const; |
| 36 | |
| 37 | /** |
| 38 | * If data is NULL, remove (if present) the entry matching name and call |
| 39 | * prev_data->unref() on the data for the matching entry. |
| 40 | * If data is not-NULL, replace the existing entry matching name and |
| 41 | * call (prev_data->unref()), or add a new one. In either case, |
| 42 | * data->ref() is called. |
| 43 | */ |
| 44 | void set(const char name[], SkRefCnt* data); |
| 45 | |
| 46 | /** |
| 47 | * Remove the matching entry (if found) and unref its data. |
| 48 | */ |
| 49 | void remove(const char name[]) { this->set(name, NULL); } |
| 50 | |
| 51 | /** |
| 52 | * Remove all entries, and unref() their associated data. |
| 53 | */ |
| 54 | void removeAll(); |
| 55 | |
| 56 | private: |
| 57 | struct Impl; |
| 58 | Impl* fImpl; |
| 59 | }; |
| 60 | |
| 61 | #endif |