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_IREFERENCE_H) 00023 #define INCLUDED_IREFERENCE_H 00024 00025 #include "generic/constant.h" 00026 00027 namespace scene 00028 { 00029 class Node; 00030 } 00031 00032 class ModuleObserver; 00033 00034 class Resource 00035 { 00036 public: 00037 virtual ~Resource () 00038 { 00039 } 00040 virtual bool load () = 0; 00041 virtual bool save () = 0; 00042 virtual void flush () = 0; 00043 virtual void refresh () = 0; 00044 virtual scene::Node* getNode () = 0; 00045 virtual void setNode (scene::Node* node) = 0; 00046 virtual void attach (ModuleObserver& observer) = 0; 00047 virtual void detach (ModuleObserver& observer) = 0; 00048 virtual void realise () = 0; 00049 virtual void unrealise () = 0; 00050 }; 00051 00052 class EntityCreator; 00053 00054 class ReferenceCache 00055 { 00056 public: 00057 INTEGER_CONSTANT(Version, 1); 00058 STRING_CONSTANT(Name, "reference"); 00059 00060 virtual ~ReferenceCache () 00061 { 00062 } 00063 /* load a resource with a path relative to base/ 00064 * don't forget to call load() on the resource */ 00065 virtual Resource* capture (const std::string& path) = 0; 00066 /* release the captured resource and reduce the reference counter */ 00067 virtual void release (const std::string& path) = 0; 00068 00069 virtual void setEntityCreator (EntityCreator& entityCreator) = 0; 00070 }; 00071 00072 #include "modulesystem.h" 00073 00074 template<typename Type> 00075 class GlobalModule; 00076 typedef GlobalModule<ReferenceCache> GlobalReferenceModule; 00077 00078 template<typename Type> 00079 class GlobalModuleRef; 00080 typedef GlobalModuleRef<ReferenceCache> GlobalReferenceModuleRef; 00081 00082 inline ReferenceCache& GlobalReferenceCache () 00083 { 00084 return GlobalReferenceModule::getTable(); 00085 } 00086 00087 #endif