blob: 0c4b02507d5704c550853e3fe7ac58a8b06da17b [file] [log] [blame]
reed@google.com3636ed52011-01-25 23:50:57 +00001/*
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.com0e190d02011-01-25 23:36:05 +000017#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.org7ffb1b22011-03-15 21:27:08 +000026class SK_API SkRefDict : SkNoncopyable {
reed@google.com0e190d02011-01-25 23:36:05 +000027public:
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
56private:
57 struct Impl;
58 Impl* fImpl;
59};
60
61#endif