Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/src/OgreArchiveManager.cpp @ 48

Last change on this file since 48 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 4.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30
31#include "OgreArchiveManager.h"
32
33#include "OgreArchiveFactory.h"
34#include "OgreArchive.h"
35#include "OgreException.h"
36#include "OgreLogManager.h"
37
38namespace Ogre {
39    typedef void (*createFunc)( Archive**, const String& );
40
41    //-----------------------------------------------------------------------
42    template<> ArchiveManager* Singleton<ArchiveManager>::ms_Singleton = 0;
43    ArchiveManager* ArchiveManager::getSingletonPtr(void)
44    {
45        return ms_Singleton;
46    }
47    ArchiveManager& ArchiveManager::getSingleton(void)
48    { 
49        assert( ms_Singleton );  return ( *ms_Singleton ); 
50    }
51    //-----------------------------------------------------------------------
52
53    //-----------------------------------------------------------------------
54    Archive* ArchiveManager::load( const String& filename, const String& archiveType)
55    {
56        ArchiveMap::iterator i = mArchives.find(filename);
57        Archive* pArch = 0;
58
59        if (i == mArchives.end())
60        {
61            // Search factories
62            ArchiveFactoryMap::iterator it = mArchFactories.find(archiveType);
63            if (it == mArchFactories.end())
64                // Factory not found
65                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot find an archive factory "
66                    "to deal with archive of type " + archiveType, "ArchiveManager::load");
67
68            pArch = it->second->createInstance(filename);
69            pArch->load();
70            mArchives[filename] = pArch;
71
72        }
73        else
74        {
75            pArch = i->second;
76        }
77        return pArch;
78    }
79        //-----------------------------------------------------------------------
80        void ArchiveManager::unload(Archive* arch)
81        {
82                unload(arch->getName());
83        }
84        //-----------------------------------------------------------------------
85        void ArchiveManager::unload(const String& filename)
86        {
87                ArchiveMap::iterator i = mArchives.find(filename);
88
89                if (i != mArchives.end())
90                {
91                        i->second->unload();
92                        // Find factory to destroy
93                        ArchiveFactoryMap::iterator fit = mArchFactories.find(i->second->getType());
94                        if (fit == mArchFactories.end())
95                        {
96                                // Factory not found
97                                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot find an archive factory "
98                                        "to deal with archive of type " + i->second->getType(), "ArchiveManager::~ArchiveManager");
99                        }
100                        fit->second->destroyInstance(i->second);
101                        mArchives.erase(i);
102                }
103        }
104    //-----------------------------------------------------------------------
105    ArchiveManager::~ArchiveManager()
106    {
107        // Unload & delete resources in turn
108        for( ArchiveMap::iterator it = mArchives.begin(); it != mArchives.end(); ++it )
109        {
110            Archive* arch = it->second;
111            // Unload
112            arch->unload();
113            // Find factory to destroy
114            ArchiveFactoryMap::iterator fit = mArchFactories.find(arch->getType());
115            if (fit == mArchFactories.end())
116            {
117                // Factory not found
118                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot find an archive factory "
119                "to deal with archive of type " + arch->getType(), "ArchiveManager::~ArchiveManager");
120            }
121            fit->second->destroyInstance(arch);
122           
123        }
124        // Empty the list
125        mArchives.clear();
126    }
127    //-----------------------------------------------------------------------
128    void ArchiveManager::addArchiveFactory(ArchiveFactory* factory)
129    {       
130        mArchFactories.insert( ArchiveFactoryMap::value_type( factory->getType(), factory ) );
131        LogManager::getSingleton().logMessage("ArchiveFactory for archive type " +     factory->getType() + " registered.");
132    }
133
134}
135
Note: See TracBrowser for help on using the repository browser.