<commit_before>/***************************************************************************
 *  include/stxxl/bits/common/shared_object.h
 *
 *  Part of the STXXL. See http://stxxl.sourceforge.net
 *
 *  Copyright (C) 2010-2011 <NAME> <<EMAIL>>
 *
 *  Distributed under the Boost Software License, Version 1.0.
 *  (See accompanying file LICENSE_1_0.txt or copy at
 *  http://www.boost.org/LICENSE_1_0.txt)
 **************************************************************************/

#ifndef STXXL_SHARED_OBJECT_HEADER
#define STXXL_SHARED_OBJECT_HEADER

//#include <cassert>
#include <stxxl/bits/namespace.h>

__STXXL_BEGIN_NAMESPACE

//! \brief Behaves much like a Pointer, plus deleteing the referred object with it's last reference
//!    and ability to unify, i.e. make and refer a copy if the original object was shared.
//!
//! Use with objects derived from shared_object.
//! Similar to boost/shared_ptr.
template <class C>
class shared_object_pointer
{
    C * ptr;

    void new_reference()
    { new_reference(ptr); }

    void new_reference(C * o)
    { if (o) o->new_reference(); }

    void delete_reference()
    { if (ptr && ptr->delete_reference()) delete ptr; }

public:
    shared_object_pointer()
        : ptr(0) {}<commit_msg>Make header compile on its own.<commit_after>/***************************************************************************
 *  include/stxxl/bits/common/shared_object.h
 *
 *  Part of the STXXL. See http://stxxl.sourceforge.net
 *
 *  Copyright (C) 2010-2011 <NAME> <<EMAIL>>
 *
 *  Distributed under the Boost Software License, Version 1.0.
 *  (See accompanying file LICENSE_1_0.txt or copy at
 *  http://www.boost.org/LICENSE_1_0.txt)
 **************************************************************************/

#ifndef STXXL_SHARED_OBJECT_HEADER
#define STXXL_SHARED_OBJECT_HEADER

#include <cassert>
#include <stxxl/bits/namespace.h>

__STXXL_BEGIN_NAMESPACE

//! \brief Behaves much like a Pointer, plus deleteing the referred object with it's last reference
//!    and ability to unify, i.e. make and refer a copy if the original object was shared.
//!
//! Use with objects derived from shared_object.
//! Similar to boost/shared_ptr.
template <class C>
class shared_object_pointer
{
    C * ptr;

    void new_reference()
    { new_reference(ptr); }

    void new_reference(C * o)
    { if (o) o->new_reference(); }

    void delete_reference()
    { if (ptr && ptr->delete_reference()) delete ptr; }

public:
    shared_object_pointer()
        : ptr(0) {}
{'fraction_non_alphanumeric': 0.22155926809864757, 'fraction_numerical': 0.011933174224343675, 'mean_word_length': 4.122199592668024, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4879937', 'n_tokens_mistral': 801, 'n_tokens_neox': 746, 'n_words': 213}