<commit_before>
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#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() {
        if (NULL != fPtr) {
            fPtr->Release();
            fPtr = NULL;
        }
    }
    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; }
};

#endif
<commit_msg>Add means to release object from ScopedComPtr. http://codereview.appspot.com/4801088/<commit_after>
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#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() {
        this->reset();
    }
    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; }
    void reset() {
        if (NULL != this->fPtr) {
            this->fPtr->Release();
            this->fPtr = NULL;
        }
    }
};

#endif

{'fraction_non_alphanumeric': 0.11357210179076344, 'fraction_numerical': 0.00706880301602262, 'mean_word_length': 2.685763888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3728315', 'n_tokens_mistral': 691, 'n_tokens_neox': 669, 'n_words': 222}