michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkRefDict_DEFINED michael@0: #define SkRefDict_DEFINED michael@0: michael@0: #include "SkRefCnt.h" michael@0: michael@0: /** michael@0: * A dictionary of string,refcnt pairs. The dictionary is also an owner of the michael@0: * refcnt objects while they are contained. michael@0: */ michael@0: class SK_API SkRefDict : SkNoncopyable { michael@0: public: michael@0: SkRefDict(); michael@0: ~SkRefDict(); michael@0: michael@0: /** michael@0: * Return the data associated with name[], or NULL if no matching entry michael@0: * is found. The reference-count of the entry is not affected. michael@0: */ michael@0: SkRefCnt* find(const char name[]) const; michael@0: michael@0: /** michael@0: * If data is NULL, remove (if present) the entry matching name and call michael@0: * prev_data->unref() on the data for the matching entry. michael@0: * If data is not-NULL, replace the existing entry matching name and michael@0: * call (prev_data->unref()), or add a new one. In either case, michael@0: * data->ref() is called. michael@0: */ michael@0: void set(const char name[], SkRefCnt* data); michael@0: michael@0: /** michael@0: * Remove the matching entry (if found) and unref its data. michael@0: */ michael@0: void remove(const char name[]) { this->set(name, NULL); } michael@0: michael@0: /** michael@0: * Remove all entries, and unref() their associated data. michael@0: */ michael@0: void removeAll(); michael@0: michael@0: private: michael@0: struct Impl; michael@0: Impl* fImpl; michael@0: }; michael@0: michael@0: #endif