Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/libraries/core/MemoryArchive.h @ 11663

Last change on this file since 11663 was 7401, checked in by landauf, 14 years ago

merged doc branch back to trunk

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @ingroup Management Resources
32*/
33
34#ifndef _MemoryArchive_H__
35#define _MemoryArchive_H__
36
37#include "CorePrereqs.h"
38#include <OgrePrerequisites.h>
39
40#if OGRE_VERSION < 0x010600
41
42#include <map>
43#include <OgreArchive.h>
44#include <OgreArchiveFactory.h>
45#include <boost/shared_array.hpp>
46
47namespace orxonox
48{
49    /**
50    @brief
51        Provides a simple mechanism of 'memory mapped IO', but compatible for Ogre 1.4
52
53        Files are stored as shared_array<char> in a static map with the archive names
54        (imaging the different archives as resource locations). This map then contains
55        yet another map with the actual files.
56        If you want to know why we make such a fuss, contact GraphicsManager::upgradeToGraphics()
57        for more information.
58    */
59    class MemoryArchive : public Ogre::Archive
60    {
61    public:
62        MemoryArchive(const Ogre::String& name, const Ogre::String& archiveType) : Ogre::Archive(name, archiveType) { }
63        ~MemoryArchive() { }
64
65        bool isCaseSensitive(void) const { return true; }
66
67        void load();
68        void unload() { }
69
70        Ogre::DataStreamPtr open(const Ogre::String& filename) const;
71
72        Ogre::StringVectorPtr list(bool recursive = true, bool dirs = false);
73        Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
74
75        Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true,
76            bool dirs = false);
77        Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern, bool recursive = true,
78            bool dirs = false);
79
80        bool exists(const Ogre::String& filename);
81
82        static void addFile(const std::string& archiveName, const std::string& filename, shared_array<char> content, size_t size)
83            { archives_s[archiveName][filename] = std::make_pair(content, size); }
84
85    private:
86        void findFiles(const Ogre::String& pattern, bool bRecursive,
87            bool bDirs, Ogre::StringVector* simpleList, Ogre::FileInfoList* detailList);
88
89        typedef std::map<std::string, std::pair<shared_array<char>, size_t> > FileMap;
90        typedef std::map<std::string, FileMap> ArchiveMap;
91        static ArchiveMap archives_s;
92    };
93
94    //! Specialisation of ArchiveFactory for MemoryArchive.
95    class _CoreExport MemoryArchiveFactory : public Ogre::ArchiveFactory
96    {
97    public:
98        const Ogre::String& getType(void) const;
99        Ogre::Archive* createInstance(const Ogre::String& name) { return new MemoryArchive(name, "Memory"); }
100        void destroyInstance(Ogre::Archive* arch)               { delete arch; }
101    };
102}
103
104#endif /* OGRE_VERSION < 0x010600 */
105
106#endif /* _MemoryArchive_H__ */
Note: See TracBrowser for help on using the repository browser.