• Main Page
  • Related Pages
  • Classes
  • Files
  • File List

src/SceneTreePtr.hh

00001 /*
00002  * This file is part of peekabot.
00003  *
00004  * peekabot is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * peekabot is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __PEEKABOT_SCENE_TREE_PTR_HH
00019 #define __PEEKABOT_SCENE_TREE_PTR_HH
00020 
00021 
00022 #include "SceneTree.hh"
00023 
00024 
00025 namespace peekabot
00026 {
00027 
00028 
00029     class TheSceneTree;
00030 
00031 
00032     class SceneTreePtr
00033     {
00034         friend class TheSceneTree;
00035 
00036         SceneTree *m_scene_tree;
00037 
00038         SceneTree::SceneTreeMutex::scoped_lock *m_lock;
00039 
00040         explicit SceneTreePtr(SceneTree *scene_tree)
00041             : m_scene_tree(scene_tree),
00042               m_lock(new SceneTree::SceneTreeMutex::scoped_lock(scene_tree->m_scene_mutex))
00043         {
00044         }
00045 
00046     public:
00047 
00048         SceneTreePtr() throw() : m_scene_tree(0), m_lock(0) {}
00049 
00050         ~SceneTreePtr() throw()
00051         {
00052             if( m_lock )
00053                 delete m_lock;
00054         }
00055 
00056         /*explicit SceneTreePtr(SceneTreePtr &ptr) throw()
00057         {
00058             m_scene_tree = ptr.m_scene_tree;
00059             m_lock = ptr.m_lock;
00060 
00061             ptr.m_scene_tree = 0;
00062             ptr.m_lock = 0;
00063         }*/
00064 
00065         SceneTreePtr &operator=(SceneTreePtr &ptr) throw()
00066         {
00067             m_scene_tree = ptr.m_scene_tree;
00068             m_lock = ptr.m_lock;
00069 
00070             ptr.m_scene_tree = 0;
00071             ptr.m_lock = 0;
00072 
00073             return *this;
00074         }
00075 
00076 
00077         SceneTree *operator->() throw()
00078         {
00079             return m_scene_tree;
00080         }
00081     };
00082 
00083 
00084 
00085     class TheSceneTree
00086     {
00087     public:
00088         static SceneTreePtr acquire() throw()
00089         {
00090             static SceneTree scene_tree;
00091 
00092             return SceneTreePtr(&scene_tree);
00093         }
00094     };
00095 
00096 
00097 }
00098 
00099 
00100 #endif // __PEEKABOT_SCENE_TREE_PTR_HH

Generated on Sun Jan 30 2011 for peekabot by  doxygen 1.7.1