2011-06-23 21:43:52 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-06-23 21:43:52 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2011-06-23 21:43:52 +00:00
|
|
|
#ifndef SkSkTScopedPtr_DEFINED
|
|
|
|
#define SkSkTScopedPtr_DEFINED
|
|
|
|
|
|
|
|
#include "SkTemplates.h"
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class SkTScopedComPtr : SkNoncopyable {
|
|
|
|
private:
|
|
|
|
T *fPtr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SkTScopedComPtr(T *ptr = NULL) : fPtr(ptr) { }
|
|
|
|
~SkTScopedComPtr() {
|
2011-08-09 19:25:05 +00:00
|
|
|
this->reset();
|
2011-06-23 21:43:52 +00:00
|
|
|
}
|
|
|
|
T &operator*() const { return *fPtr; }
|
|
|
|
T *operator->() const { return fPtr; }
|
|
|
|
/**
|
|
|
|
* Returns the address of the underlying pointer.
|
|
|
|
* This is dangerous -- it breaks encapsulation and the reference escapes.
|
|
|
|
* Must only be used on instances currently pointing to NULL,
|
|
|
|
* and only to initialize the instance.
|
|
|
|
*/
|
|
|
|
T **operator&() { SkASSERT(fPtr == NULL); return &fPtr; }
|
|
|
|
T *get() const { return fPtr; }
|
2011-08-09 19:25:05 +00:00
|
|
|
void reset() {
|
|
|
|
if (NULL != this->fPtr) {
|
|
|
|
this->fPtr->Release();
|
|
|
|
this->fPtr = NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 21:43:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|