Panda3D
 All Classes Functions Variables Enumerations
nodeReferenceCount.h
00001 // Filename: nodeReferenceCount.h
00002 // Created by:  drose (01May06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef NODEREFERENCECOUNT_H
00016 #define NODEREFERENCECOUNT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "referenceCount.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : NodeReferenceCount
00024 // Description : This class specializes ReferenceCount to add an
00025 //               additional counter, called node_ref_count, for the
00026 //               purposes of counting the number of times the object
00027 //               is referenced by a "node", whatever that may mean in
00028 //               context.
00029 //
00030 //               The new methods node_ref() and node_unref()
00031 //               automatically increment and decrement the primary
00032 //               reference count as well.  There also exists a
00033 //               NodePointerTo<> class to maintain the node_ref
00034 //               counters automatically.
00035 //
00036 //               See also CachedTypedWritableReferenceCount, which is
00037 //               similar in principle, as well as
00038 //               NodeCachedReferenceCount, which combines both of
00039 //               these.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDAEXPRESS NodeReferenceCount : public ReferenceCount {
00042 protected:
00043   INLINE NodeReferenceCount();
00044   INLINE NodeReferenceCount(const NodeReferenceCount &copy);
00045   INLINE void operator = (const NodeReferenceCount &copy);
00046   INLINE ~NodeReferenceCount();
00047 
00048 PUBLISHED:
00049   INLINE int get_node_ref_count() const;
00050   INLINE void node_ref() const;
00051   INLINE bool node_unref() const;
00052   INLINE bool test_ref_count_integrity() const;
00053 
00054 protected:
00055   INLINE void node_unref_only() const;
00056 
00057   bool do_test_ref_count_integrity() const;
00058   
00059 private:
00060   AtomicAdjust::Integer _node_ref_count;
00061 
00062 public:
00063   static TypeHandle get_class_type() {
00064     return _type_handle;
00065   }
00066 
00067   static void init_type() {
00068     ReferenceCount::init_type();
00069     register_type(_type_handle, "NodeReferenceCount",
00070                   ReferenceCount::get_class_type());
00071   }
00072 
00073 private:
00074   static TypeHandle _type_handle;
00075 };
00076 
00077 template<class RefCountType>
00078 INLINE void node_unref_delete(RefCountType *ptr);
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //       Class : NodeRefCountObj
00082 // Description : This works like RefCountObj, but it inherits from
00083 //               NodeReferenceCount instead of ReferenceCount.
00084 ////////////////////////////////////////////////////////////////////
00085 template<class Base>
00086 class NodeRefCountObj : public NodeReferenceCount, public Base {
00087 public:
00088   INLINE NodeRefCountObj();
00089   INLINE NodeRefCountObj(const Base &copy);
00090   ALLOC_DELETED_CHAIN(NodeRefCountObj<Base>);
00091 
00092   static TypeHandle get_class_type() {
00093     return _type_handle;
00094   }
00095   static void init_type();
00096 
00097 private:
00098   static TypeHandle _type_handle;
00099 };
00100 
00101 #include "nodeReferenceCount.I"
00102 
00103 #endif  
00104 
 All Classes Functions Variables Enumerations