Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | List of all members
SkPtrSet Class Reference

#include <SkPtrRecorder.h>

Inheritance diagram for SkPtrSet:
SkRefCnt SkRefCntBase SkTPtrSet< SkFlattenable::Factory > SkTPtrSet< SkRefCnt * > SkTPtrSet< T > SkFactorySet SkRefCntSet

Classes

class  Iter
 

Public Member Functions

uint32_t find (void *) const
 
uint32_t add (void *)
 
int count () const
 
void copyToArray (void *array[]) const
 
void reset ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

virtual void incPtr (void *)
 
virtual void decPtr (void *)
 

Detailed Description

Maintains a set of ptrs, assigning each a unique ID [1...N]. Duplicate ptrs return the same ID (since its a set). Subclasses can override inPtr() and decPtr(). incPtr() is called each time a unique ptr is added ot the set. decPtr() is called on each ptr when the set is destroyed or reset.

Definition at line 24 of file SkPtrRecorder.h.

Member Function Documentation

◆ add()

uint32_t SkPtrSet::add ( void *  ptr)

Add the specified ptr to the set, returning a unique 32bit ID for it [1...N]. Duplicate ptrs will return the same ID.

If the ptr is nullptr, it is not added, and 0 is returned.

Definition at line 42 of file SkPtrRecorder.cpp.

42 {
43 if (nullptr == ptr) {
44 return 0;
45 }
46
47 int count = fList.size();
48 Pair pair;
49 pair.fPtr = ptr;
50
51 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair));
52 if (index < 0) {
53 index = ~index; // turn it back into an index for insertion
54 this->incPtr(ptr);
55 pair.fIndex = count + 1;
56 *fList.insert(index) = pair;
57 return count + 1;
58 } else {
59 return fList[index].fIndex;
60 }
61}
virtual void incPtr(void *)
int count() const
int size() const
Definition SkTDArray.h:138
T * begin()
Definition SkTDArray.h:150
T * insert(int index)
Definition SkTDArray.h:203

◆ copyToArray()

void SkPtrSet::copyToArray ( void *  array[]) const

Copy the ptrs in the set into the specified array (allocated by the caller). The ptrs are assgined to the array based on their corresponding ID. e.g. array[ptr.ID - 1] = ptr.

incPtr() and decPtr() are not called during this operation.

Definition at line 63 of file SkPtrRecorder.cpp.

63 {
64 int count = fList.size();
65 if (count > 0) {
66 SkASSERT(array);
67 const Pair* p = fList.begin();
68 // p->fIndex is base-1, so we need to subtract to find its slot
69 for (int i = 0; i < count; i++) {
70 int index = p[i].fIndex - 1;
71 SkASSERT((unsigned)index < (unsigned)count);
72 array[index] = p[i].fPtr;
73 }
74 }
75}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ count()

int SkPtrSet::count ( ) const
inline

Return the number of (non-null) ptrs in the set.

Definition at line 45 of file SkPtrRecorder.h.

45{ return fList.size(); }

◆ decPtr()

virtual void SkPtrSet::decPtr ( void *  )
inlineprotectedvirtual

Reimplemented in SkRefCntSet.

Definition at line 85 of file SkPtrRecorder.h.

85{}

◆ find()

uint32_t SkPtrSet::find ( void *  ptr) const

Search for the specified ptr in the set. If it is found, return its 32bit ID [1..N], or if not found, return 0. Always returns 0 for nullptr.

Definition at line 26 of file SkPtrRecorder.cpp.

26 {
27 if (nullptr == ptr) {
28 return 0;
29 }
30
31 int count = fList.size();
32 Pair pair;
33 pair.fPtr = ptr;
34
35 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair));
36 if (index < 0) {
37 return 0;
38 }
39 return fList[index].fIndex;
40}

◆ incPtr()

virtual void SkPtrSet::incPtr ( void *  )
inlineprotectedvirtual

Reimplemented in SkRefCntSet.

Definition at line 84 of file SkPtrRecorder.h.

84{}

◆ reset()

void SkPtrSet::reset ( )

Call decPtr() on each ptr in the set, and the reset the size of the set to 0.

Definition at line 12 of file SkPtrRecorder.cpp.

12 {
13 Pair* p = fList.begin();
14 Pair* stop = fList.end();
15 while (p < stop) {
16 this->decPtr(p->fPtr);
17 p += 1;
18 }
19 fList.reset();
20}
virtual void decPtr(void *)
T * end()
Definition SkTDArray.h:152
void reset()
Definition SkTDArray.h:171

The documentation for this class was generated from the following files: