iscenegraph.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined (INCLUDED_ISCENEGRAPH_H)
00023 #define INCLUDED_ISCENEGRAPH_H
00024 
00025 #include <cstddef>
00026 #include "generic/constant.h"
00027 #include "signal/signalfwd.h"
00028 
00029 template<typename value_type>
00030 class Stack;
00031 template<typename Contained>
00032 class Reference;
00033 
00034 namespace scene
00035 {
00036     class Instance;
00037     const Instance* const nullInstancePointer = 0;
00038     inline const Instance& nullInstance ()
00039     {
00040         return *nullInstancePointer;
00041     }
00042 
00043     class Node;
00044     const Node* const nullNodePointer = 0;
00045     inline const Node& nullNode ()
00046     {
00047         return *nullNodePointer;
00048     }
00049 }
00050 
00051 typedef Reference<scene::Node> NodeReference;
00052 
00053 typedef std::size_t TypeId;
00054 
00055 const TypeId NODETYPEID_MAX = 64;
00056 const TypeId NODETYPEID_NONE = NODETYPEID_MAX;
00057 
00058 const TypeId INSTANCETYPEID_MAX = 64;
00059 const TypeId INSTANCETYPEID_NONE = INSTANCETYPEID_MAX;
00060 
00068 namespace scene
00069 {
00071     typedef Stack<NodeReference> Path;
00072 
00083     class Graph
00084     {
00085         public:
00086             INTEGER_CONSTANT(Version, 1);
00087             STRING_CONSTANT(Name, "scenegraph");
00088 
00089             class Walker
00090             {
00091                 public:
00092                     virtual ~Walker ()
00093                     {
00094                     }
00096                     virtual bool pre (const Path& path, Instance& instance) const = 0;
00098                     virtual void post (const Path& path, Instance& instance) const
00099                     {
00100                     }
00101             };
00102 
00103             virtual ~Graph ()
00104             {
00105             }
00106 
00108             virtual Node& root () = 0;
00110             virtual void insert_root (Node& root) = 0;
00112             virtual void erase_root () = 0;
00114             virtual void traverse (const Walker& walker) = 0;
00116             virtual void traverse_subgraph (const Walker& walker, const Path& start) = 0;
00118             virtual scene::Instance* find (const Path& path) = 0;
00120             virtual scene::Instance* find (Node& node) = 0;
00121 
00124             virtual void sceneChanged () = 0;
00127             virtual void addSceneChangedCallback (const SignalHandler& handler) = 0;
00128 
00131             virtual void boundsChanged () = 0;
00133             virtual SignalHandlerId addBoundsChangedCallback (const SignalHandler& boundsChanged) = 0;
00135             virtual void removeBoundsChangedCallback (SignalHandlerId id) = 0;
00136 
00137             virtual TypeId getNodeTypeId (const char* name) = 0;
00138             virtual TypeId getInstanceTypeId (const char* name) = 0;
00139     };
00140 
00141     class Traversable
00142     {
00143         public:
00144             STRING_CONSTANT(Name, "scene::Traversable");
00145 
00146             class Observer
00147             {
00148                 public:
00149                     virtual ~Observer ()
00150                     {
00151                     }
00152 
00154                     virtual void insert (Node& node) = 0;
00156                     virtual void erase (Node& node) = 0;
00157             };
00158 
00159             class Walker
00160             {
00161                 public:
00162                     virtual ~Walker ()
00163                     {
00164                     }
00165 
00167                     virtual bool pre (Node& node) const = 0;
00169                     virtual void post (Node& node) const
00170                     {
00171                     }
00172             };
00173 
00174             virtual ~Traversable ()
00175             {
00176             }
00177 
00179             virtual void insert (Node& node) = 0;
00181             virtual void erase (Node& node) = 0;
00183             virtual void traverse (const Walker& walker) = 0;
00185             virtual bool empty () const = 0;
00186     };
00187 
00188     class Instantiable
00189     {
00190         public:
00191             STRING_CONSTANT(Name, "scene::Instantiable");
00192 
00193             class Observer
00194             {
00195                 public:
00196                     virtual ~Observer ()
00197                     {
00198                     }
00199 
00201                     virtual void insert (scene::Instance* instance) = 0;
00203                     virtual void erase (scene::Instance* instance) = 0;
00204             };
00205 
00206             class Visitor
00207             {
00208                 public:
00209                     virtual ~Visitor ()
00210                     {
00211                     }
00212 
00213                     virtual void visit (Instance& instance) const = 0;
00214             };
00215 
00216             virtual ~Instantiable ()
00217             {
00218             }
00219 
00221             virtual scene::Instance* create (const scene::Path& path, scene::Instance* parent) = 0;
00223             virtual void forEachInstance (const Visitor& visitor) = 0;
00225             virtual void insert (Observer* observer, const Path& path, scene::Instance* instance) = 0;
00227             virtual scene::Instance* erase (Observer* observer, const Path& path) = 0;
00228     };
00229 
00230     class Cloneable
00231     {
00232         public:
00233             STRING_CONSTANT(Name, "scene::Cloneable");
00234 
00235             virtual ~Cloneable ()
00236             {
00237             }
00238 
00240             virtual scene::Node& clone () const = 0;
00241     };
00242 }
00243 
00244 #include "modulesystem.h"
00245 
00246 template<typename Type>
00247 class GlobalModule;
00248 typedef GlobalModule<scene::Graph> GlobalSceneGraphModule;
00249 
00250 template<typename Type>
00251 class GlobalModuleRef;
00252 typedef GlobalModuleRef<scene::Graph> GlobalSceneGraphModuleRef;
00253 
00254 inline scene::Graph& GlobalSceneGraph ()
00255 {
00256     return GlobalSceneGraphModule::getTable();
00257 }
00258 
00259 inline void AddSceneChangeCallback (const SignalHandler& handler)
00260 {
00261     GlobalSceneGraph().addSceneChangedCallback(handler);
00262 }
00263 inline void SceneChangeNotify ()
00264 {
00265     GlobalSceneGraph().sceneChanged();
00266 }
00267 
00268 #endif

Generated by  doxygen 1.6.2