Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreArchiveManager.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #include "OgreStableHeaders.h"
00026 
00027 #include "OgreArchiveManager.h"
00028 
00029 #include "OgreArchiveFactory.h"
00030 #include "OgreArchiveEx.h"
00031 #include "OgreException.h"
00032 #include "OgreLogManager.h"
00033 
00034 namespace Ogre {
00035     typedef void (*createFunc)( ArchiveEx**, const String& );
00036 
00037     //-----------------------------------------------------------------------
00038     template<> ArchiveManager* Singleton<ArchiveManager>::ms_Singleton = 0;
00039     //-----------------------------------------------------------------------
00040 
00041     //-----------------------------------------------------------------------
00042     ArchiveEx* ArchiveManager::load( const String& filename, const String& archiveType, int priority /* =1 */ )
00043     {
00044         ArchiveEx* pArch = (ArchiveEx*)(getByName(filename));
00045         if (!pArch)
00046         {
00047             // Search factories
00048             ArchiveFactoryMap::iterator it = mArchFactories.find(archiveType);
00049             if (it == mArchFactories.end())
00050                 // Factory not found
00051                 Except(Exception::ERR_ITEM_NOT_FOUND, "Cannot find an archive factory "
00052                     "to deal with archive of type " + archiveType, "ArchiveManager::load");
00053 
00054             pArch = it->second->createObj( filename );
00055 
00056             ResourceManager::load(pArch, priority);
00057         }
00058         return pArch;
00059     }
00060 
00061     //-----------------------------------------------------------------------
00062     Resource* ArchiveManager::create( const String& name ) {
00063         return NULL;
00064     }
00065 
00066     //-----------------------------------------------------------------------
00067     ArchiveManager& ArchiveManager::getSingleton(void)
00068     {
00069         return Singleton<ArchiveManager>::getSingleton();
00070     }
00071 
00072     //-----------------------------------------------------------------------
00073     ArchiveManager::~ArchiveManager()
00074     {
00075         // Unload & delete resources in turn
00076         for( ResourceMap::iterator it = mResources.begin(); it != mResources.end(); ++it )
00077         {
00078             it->second->unload();
00079         }
00080 
00081         // Empty the list
00082         mResources.clear();
00083     }
00084     //-----------------------------------------------------------------------
00085     void ArchiveManager::addArchiveFactory(ArchiveFactory* factory)
00086     {        
00087         mArchFactories.insert( ArchiveFactoryMap::value_type( factory->getType(), factory ) );
00088         LogManager::getSingleton().logMessage("ArchiveFactory for archive type " +     factory->getType() + " registered.");
00089     }
00090 
00091 }
00092 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:01 2004