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