Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages
nodeptr.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 # ifndef OPENVRML_NODEPTR_H
00022 # define OPENVRML_NODEPTR_H
00023
00024 # include <assert.h>
00025 # include <map>
00026 # include "common.h"
00027
00028 namespace OpenVRML {
00029
00030 class Node;
00031
00032 class OPENVRML_SCOPE NodePtr {
00033
00034 friend class ScriptNode;
00035
00036 std::map<Node *, size_t>::value_type * countPtr;
00037
00038 public:
00039 explicit NodePtr(Node * node = 0);
00040 NodePtr(const NodePtr & nodePtr);
00041 ~NodePtr();
00042
00043 operator bool() const;
00044
00045 NodePtr & operator=(const NodePtr & nodePtr);
00046
00047 bool operator==(const NodePtr & nodePtr) const;
00048
00049 Node & operator*() const;
00050 Node * operator->() const;
00051 Node * get() const;
00052
00053 void reset(Node * node = 0);
00054 void swap(NodePtr & nodePtr) throw ();
00055
00056 private:
00057 void dispose() throw ();
00058 void share(std::map<Node *, size_t>::value_type * countPtr) throw ();
00059 };
00060
00061
00062 inline NodePtr::~NodePtr()
00063 {
00064 this->dispose();
00065 }
00066
00067 inline NodePtr::operator bool() const
00068 {
00069 return this->countPtr;
00070 }
00071
00072 inline NodePtr & NodePtr::operator=(const NodePtr & nodePtr)
00073 {
00074 this->share(nodePtr.countPtr);
00075 return *this;
00076 }
00077
00078 inline Node & NodePtr::operator*() const
00079 {
00080 assert(this->countPtr);
00081 assert(this->countPtr->first);
00082 return *this->countPtr->first;
00083 }
00084
00085 inline Node * NodePtr::operator->() const
00086 {
00087 assert(this->countPtr);
00088 assert(this->countPtr->first);
00089 return this->countPtr->first;
00090 }
00091
00092 inline Node * NodePtr::get() const
00093 {
00094 return this->countPtr ? this->countPtr->first : 0;
00095 }
00096
00097 inline void NodePtr::swap(NodePtr & nodePtr) throw ()
00098 {
00099 std::swap(this->countPtr, nodePtr.countPtr);
00100 }
00101
00102 inline bool NodePtr::operator==(const NodePtr & nodePtr) const
00103 {
00104 return (this->countPtr == nodePtr.countPtr);
00105 }
00106 }
00107
00108 # endif