mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
110 lines
3.4 KiB
C++
110 lines
3.4 KiB
C++
// Filename: nodeReferenceCount.h
|
|
// Created by: drose (01May06)
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
//
|
|
// PANDA 3D SOFTWARE
|
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
//
|
|
// All use of this software is subject to the terms of the Panda 3d
|
|
// Software license. You should have received a copy of this license
|
|
// along with this source code; you will also find a current copy of
|
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
//
|
|
// To contact the maintainers of this program write to
|
|
// panda3d-general@lists.sourceforge.net .
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef NODEREFERENCECOUNT_H
|
|
#define NODEREFERENCECOUNT_H
|
|
|
|
#include "pandabase.h"
|
|
|
|
#include "referenceCount.h"
|
|
#include "objectDeletor.h"
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Class : NodeReferenceCount
|
|
// Description : This class specializes ReferenceCount to add an
|
|
// additional counter, called node_ref_count, for the
|
|
// purposes of counting the number of times the object
|
|
// is referenced by a "node", whatever that may mean in
|
|
// context.
|
|
//
|
|
// The new methods node_ref() and node_unref()
|
|
// automatically increment and decrement the primary
|
|
// reference count as well. There also exists a
|
|
// NodePointerTo<> class to maintain the node_ref
|
|
// counters automatically.
|
|
//
|
|
// See also CachedTypedWritableReferenceCount, which is
|
|
// similar in principle, as well as
|
|
// NodeCachedReferenceCount, which combines both of
|
|
// these.
|
|
////////////////////////////////////////////////////////////////////
|
|
class EXPCL_PANDAEXPRESS NodeReferenceCount : public ReferenceCount {
|
|
protected:
|
|
INLINE NodeReferenceCount();
|
|
INLINE NodeReferenceCount(const NodeReferenceCount ©);
|
|
INLINE void operator = (const NodeReferenceCount ©);
|
|
INLINE ~NodeReferenceCount();
|
|
|
|
PUBLISHED:
|
|
INLINE int get_node_ref_count() const;
|
|
INLINE void node_ref() const;
|
|
INLINE bool node_unref() const;
|
|
INLINE bool test_ref_count_integrity() const;
|
|
|
|
protected:
|
|
INLINE void node_unref_only() const;
|
|
|
|
bool do_test_ref_count_integrity() const;
|
|
|
|
private:
|
|
PN_int32 _node_ref_count;
|
|
|
|
public:
|
|
static TypeHandle get_class_type() {
|
|
return _type_handle;
|
|
}
|
|
|
|
static void init_type() {
|
|
ReferenceCount::init_type();
|
|
register_type(_type_handle, "NodeReferenceCount",
|
|
ReferenceCount::get_class_type());
|
|
}
|
|
|
|
private:
|
|
static TypeHandle _type_handle;
|
|
};
|
|
|
|
template<class RefCountType>
|
|
INLINE void node_unref_delete(RefCountType *ptr);
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Class : NodeRefCountObj
|
|
// Description : This works like RefCountObj, but it inherits from
|
|
// NodeReferenceCount instead of ReferenceCount.
|
|
////////////////////////////////////////////////////////////////////
|
|
template<class Base>
|
|
class NodeRefCountObj : public NodeReferenceCount, public Base {
|
|
public:
|
|
INLINE NodeRefCountObj();
|
|
INLINE NodeRefCountObj(const Base ©);
|
|
ALLOC_DELETED_CHAIN(NodeRefCountObj<Base>);
|
|
|
|
static TypeHandle get_class_type() {
|
|
return _type_handle;
|
|
}
|
|
static void init_type();
|
|
|
|
private:
|
|
static TypeHandle _type_handle;
|
|
};
|
|
|
|
#include "nodeReferenceCount.I"
|
|
|
|
#endif
|
|
|