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     ArchiveManager* ArchiveManager::getSingletonPtr(void)
    00040     {
    00041         return ms_Singleton;
    00042     }
    00043     ArchiveManager& ArchiveManager::getSingleton(void)
    00044     {
    00045         assert( ms_Singleton );  return ( *ms_Singleton );
    00046     }
    00047     //-----------------------------------------------------------------------
    00048
    00049     //-----------------------------------------------------------------------
    00050     ArchiveEx* ArchiveManager::load( const String& filename, const String& archiveType, int priority /* =1 */ )
    00051     {
    00052         ArchiveEx* pArch = (ArchiveEx*)(getByName(filename));
    00053         if (!pArch)
    00054         {
    00055             // Search factories
    00056             ArchiveFactoryMap::iterator it = mArchFactories.find(archiveType);
    00057             if (it == mArchFactories.end())
    00058                 // Factory not found
    00059                 Except(Exception::ERR_ITEM_NOT_FOUND, "Cannot find an archive factory "
    00060                     "to deal with archive of type " + archiveType, "ArchiveManager::load");
    00061
    00062             pArch = it->second->createObj( filename );
    00063
    00064             ResourceManager::load(pArch, priority);
    00065         }
    00066         return pArch;
    00067     }
    00068
    00069     //-----------------------------------------------------------------------
    00070     Resource* ArchiveManager::create( const String& name ) {
    00071         return NULL;
    00072     }
    00073
    00074     //-----------------------------------------------------------------------
    00075     ArchiveManager::~ArchiveManager()
    00076     {
    00077         // Unload & delete resources in turn
    00078         for( ResourceMap::iterator it = mResources.begin(); it != mResources.end(); ++it )
    00079         {
    00080             it->second->unload();
    00081         }
    00082
    00083         // Empty the list
    00084         mResources.clear();
    00085     }
    00086     //-----------------------------------------------------------------------
    00087     void ArchiveManager::addArchiveFactory(ArchiveFactory* factory)
    00088     {
    00089         mArchFactories.insert( ArchiveFactoryMap::value_type( factory->getType(), factory ) );
    00090         LogManager::getSingleton().logMessage("ArchiveFactory for archive type " +     factory->getType() + " registered.");
    00091     }
    00092
    00093 }
    00094

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:14 2004