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_IENTITY_H) 00023 #define INCLUDED_IENTITY_H 00024 00025 #include <string> 00026 #include "generic/constant.h" 00027 00028 #include "string/string.h" 00029 #include "scenelib.h" 00030 00031 class EntityClass; 00032 00033 typedef Callback1<const std::string&> KeyObserver; 00034 00035 class EntityKeyValue 00036 { 00037 public: 00038 virtual ~EntityKeyValue () 00039 { 00040 } 00041 virtual const char* c_str () const = 0; 00042 virtual void assign (const std::string& other) = 0; 00043 virtual void attach (const KeyObserver& observer) = 0; 00044 virtual void detach (const KeyObserver& observer) = 0; 00045 }; 00046 00047 class Entity 00048 { 00049 public: 00050 STRING_CONSTANT(Name, "Entity"); 00051 00052 class Observer 00053 { 00054 public: 00055 virtual ~Observer () 00056 { 00057 } 00058 virtual void insert (const std::string& key, EntityKeyValue& value) = 0; 00059 virtual void erase (const std::string& key, EntityKeyValue& value) = 0; 00060 virtual void clear () 00061 { 00062 } 00063 ; 00064 }; 00065 00066 class Visitor 00067 { 00068 public: 00069 virtual ~Visitor () 00070 { 00071 } 00072 virtual void visit (const char* key, const char* value) = 0; 00073 }; 00074 00075 virtual ~Entity () 00076 { 00077 } 00078 00079 virtual const EntityClass& getEntityClass () const = 0; 00080 virtual void forEachKeyValue (Visitor& visitor) const = 0; 00081 00086 virtual void setKeyValue (const std::string& key, const std::string& value) = 0; 00087 00088 /* Old const char* key value functions 00089 * @todo deprecate these 00090 */ 00091 00092 virtual const char* getKeyValue (const std::string& key) const = 0; 00093 00094 virtual void addMandatoryKeyValues () = 0; 00095 virtual bool isContainer () const = 0; 00096 virtual void attach (Observer& observer) = 0; 00097 virtual void detach (Observer& observer) = 0; 00098 }; 00099 00100 inline Entity* Node_getEntity (scene::Node& node) 00101 { 00102 return NodeTypeCast<Entity>::cast(node); 00103 } 00104 00105 template<typename value_type> 00106 class Stack; 00107 template<typename Contained> 00108 class Reference; 00109 00110 namespace scene 00111 { 00112 class Node; 00113 } 00114 00115 typedef Reference<scene::Node> NodeReference; 00116 00117 namespace scene 00118 { 00119 typedef Stack<NodeReference> Path; 00120 } 00121 00122 class Counter; 00123 00124 class EntityCreator 00125 { 00126 public: 00127 INTEGER_CONSTANT(Version, 2); 00128 STRING_CONSTANT(Name, "entity"); 00129 00130 virtual ~EntityCreator () 00131 { 00132 } 00133 00134 virtual scene::Node& createEntity (EntityClass* eclass) = 0; 00135 00136 typedef void (*KeyValueChangedFunc) (); 00137 virtual void setKeyValueChangedFunc (KeyValueChangedFunc func) = 0; 00138 00139 virtual void setCounter (Counter* counter) = 0; 00140 00141 virtual void connectEntities (const scene::Path& e1, const scene::Path& e2) = 0; 00142 00143 virtual void setShowNames (bool showNames) = 0; 00144 virtual bool getShowNames () = 0; 00145 virtual void setShowAngles (bool showAngles) = 0; 00146 virtual bool getShowAngles () = 0; 00147 virtual void setLightRadii (bool lightRadii) = 0; 00148 virtual bool getLightRadii () = 0; 00149 virtual void setForceLightRadii (bool forceLightRadii) = 0; 00150 virtual bool getForceLightRadii () = 0; 00151 00152 virtual void printStatistics () const = 0; 00153 }; 00154 00155 #include "modulesystem.h" 00156 00157 template<typename Type> 00158 class GlobalModule; 00159 typedef GlobalModule<EntityCreator> GlobalEntityModule; 00160 00161 template<typename Type> 00162 class GlobalModuleRef; 00163 typedef GlobalModuleRef<EntityCreator> GlobalEntityModuleRef; 00164 00165 inline EntityCreator& GlobalEntityCreator () 00166 { 00167 return GlobalEntityModule::getTable(); 00168 } 00169 00170 #endif