00001 /*************************************************************************** 00002 * * 00003 * (c) Art Tevs, MPI Informatik Saarbruecken * 00004 * mailto: <tevs@mpi-sb.mpg.de> * 00005 * * 00006 * This program is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 2 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 ***************************************************************************/ 00012 00013 00014 //---------------------------------------------------------------------------------- 00015 // Includes 00016 //---------------------------------------------------------------------------------- 00017 #include "Resource.h" 00018 #include "Exception.h" 00019 #include "Log.h" 00020 00021 namespace nrEngine { 00022 00023 //---------------------------------------------------------------------------------- 00024 IResource::IResource(const std::string& resType) 00025 { 00026 // setup default data 00027 mResIsLoaded = false; 00028 mResHandle = 0; 00029 mResIsEmpty = false; 00030 mResDataSize = sizeof(*this); 00031 mResIsDirty = false; 00032 setResourceType(resType); 00033 } 00034 00035 //---------------------------------------------------------------------------------- 00036 IResource::~IResource() 00037 { 00038 00039 } 00040 00041 //---------------------------------------------------------------------------------- 00042 Result IResource::unload() 00043 { 00044 // check if resource is loaded 00045 if (isResourceLoaded()) 00046 { 00047 // unload resource 00048 Result ret = unloadResource(); 00049 00050 // if ok, then inform resource manager, that we are unloaded now 00051 if (ret == OK) 00052 Engine::sResourceManager()->notifyUnloaded(this); 00053 else 00054 return ret; 00055 } 00056 return OK; 00057 } 00058 00059 //---------------------------------------------------------------------------------- 00060 Result IResource::reload(PropertyList* params) 00061 { 00062 // if resource is loaded, then unload it first 00063 if (isResourceLoaded()) 00064 { 00065 Result ret = unload(); 00066 if (ret != OK) return ret; 00067 } 00068 00069 // check if resource is loaded 00070 if (!isResourceLoaded()) 00071 { 00072 // unload resource 00073 Result ret = reloadResource(params); 00074 00075 // if ok, then inform resource manager, that we are reloaded now 00076 if (ret == OK){ 00077 Engine::sResourceManager()->notifyLoaded(this); 00078 mResIsDirty = false; 00079 }else 00080 return ret; 00081 } 00082 return OK; 00083 } 00084 00085 //---------------------------------------------------------------------------------- 00086 Result IResource::remove() 00087 { 00088 // unload resource first 00089 unload(); 00090 00091 // remove resource in the loader 00092 return mResLoader->remove(getSharedPtrFromThis()); 00093 } 00094 00095 //---------------------------------------------------------------------------------- 00096 void IResource::addResourceFilename(const std::string& filename) 00097 { 00098 // first check if such a filename already exists 00099 std::list<std::string>::iterator it = std::find(mResFileNames.begin(), mResFileNames.end(), filename); 00100 if (it == mResFileNames.end()) 00101 mResFileNames.push_back(filename); 00102 } 00103 00104 //---------------------------------------------------------------------------------- 00105 void IResource::addResourceFilename(const std::list<std::string>& flist) 00106 { 00107 std::list<std::string>::const_iterator it = flist.begin(); 00108 for (; it != flist.end(); it++) 00109 addResourceFilename(*it); 00110 } 00111 00112 //---------------------------------------------------------------------------------- 00113 void IResource::setResourceFilename(const std::list<std::string>& flist) 00114 { 00115 mResFileNames = flist; 00116 } 00117 00118 }; 00119