blob: 55b9bfe0cf4f6563ca37ec8aeedc95efb9ab96b9 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.com3636ed52011-01-25 23:50:57 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.com3636ed52011-01-25 23:50:57 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@google.com0e190d02011-01-25 23:36:05 +000010#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.org7ffb1b22011-03-15 21:27:08 +000019class SK_API SkRefDict : SkNoncopyable {
reed@google.com0e190d02011-01-25 23:36:05 +000020public:
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.comfbfcd562012-08-23 18:09:54 +000029
reed@google.com0e190d02011-01-25 23:36:05 +000030 /**
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
49private:
50 struct Impl;
51 Impl* fImpl;
52};
53
54#endif