Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

scopeptr.h

00001 //
00002 // OpenVRML
00003 //
00004 // Copyright (C) 2000  Braden McDaniel
00005 // 
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 // 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 // 
00020 
00021 # ifndef OPENVRML_SCOPEPTR_H
00022 #   define OPENVRML_SCOPEPTR_H
00023 
00024 #   include <stddef.h>
00025 #   include <assert.h>
00026 #   include "common.h"
00027 
00028 namespace OpenVRML {
00029 
00030     class Scope;
00031 
00032     class OPENVRML_SCOPE ScopePtr {
00033         Scope * scope;
00034         size_t * count;
00035 
00036     public:
00037         explicit ScopePtr(Scope * scope = 0);
00038         ScopePtr(const ScopePtr & scopePtr);
00039         ~ScopePtr();
00040 
00041         operator bool() const;
00042 
00043         ScopePtr & operator=(const ScopePtr & scopePtr);
00044 
00045         bool operator==(const ScopePtr & scopePtr) const;
00046 
00047         Scope & operator*() const;
00048         Scope * operator->() const;
00049         Scope * get() const;
00050 
00051         void reset(Scope * scope = 0);
00052 
00053     private:
00054         void dispose();
00055     };
00056 
00057     inline ScopePtr::~ScopePtr() {
00058         this->dispose();
00059     }
00060 
00061     inline ScopePtr::operator bool() const {
00062         return this->scope;
00063     }
00064 
00065     inline bool ScopePtr::operator==(const ScopePtr & scopePtr) const {
00066         return (this->scope == scopePtr.scope);
00067     }
00068 
00069     inline Scope & ScopePtr::operator*() const {
00070         assert(this->scope);
00071         return *this->scope;
00072     }
00073 
00074     inline Scope * ScopePtr::operator->() const {
00075         assert(this->scope);
00076         return this->scope;
00077     }
00078 
00079     inline Scope * ScopePtr::get() const {
00080         assert(this->scope);
00081         return this->scope;
00082     }
00083 }
00084 
00085 # endif