Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/Resource.h @ 12398

Last change on this file since 12398 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 4.8 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    @defgroup Resources Resources
31    @ingroup Management
32*/
33
34/**
35    @file
36    @ingroup Management Resources
37*/
38
39#ifndef _Core_Resource_H__
40#define _Core_Resource_H__
41
42#include "CorePrereqs.h"
43
44#include <memory>
45
46#include <OgreDataStream.h>
47#include <OgreStringVector.h>
48
49namespace orxonox
50{
51    // Import the Ogre::DataStreamList
52    using Ogre::DataStreamList;
53    using Ogre::DataStreamListPtr;
54    using Ogre::StringVector;
55    using Ogre::StringVectorPtr;
56
57    //! Stores basic information about a Resource from Ogre
58    struct ResourceInfo
59    {
60        //! The file's fully qualified name
61        std::string filename;
62        //! Path name; separated by '/' and ending with '/'
63        std::string path;
64        //! Base filename
65        std::string basename;
66        //! Resource group the file is in
67        std::string group;
68        //! Uncompressed size
69        size_t size;
70        //! Absolute file path ("" for files not on filesystem)
71        std::string fileSystemPath;
72    };
73
74    /** Provides simple functions to easily access the Ogre::ResourceGroupManager.
75        The wrapper functions also avoid having to deal with resource groups.
76    */
77    class _CoreExport Resource
78    {
79        // Docs by Ogre::ResourceGroupManager.h
80    public:
81        /**
82        @brief
83            Open a single resource by name and return a DataStream
84            pointing at the source of the data.
85        @param name
86            The name of the resource to locate.
87            Even if resource locations are added recursively, you
88            must provide a fully qualified name to this method.
89        @return
90            Shared pointer to data stream containing the data. Will be
91            destroyed automatically when no longer referenced.
92        */
93        static DataStreamPtr open(const std::string& name);
94
95        //! Similar to open(string, string, bool), but with a fileInfo struct
96        static DataStreamPtr open(std::shared_ptr<ResourceInfo> fileInfo)
97        {
98            return open(fileInfo->filename);
99        }
100
101        /**
102        @brief
103            Open all resources matching a given pattern (which can contain
104            the character '*' as a wildcard), and return a collection of
105            DataStream objects on them.
106        @param pattern
107            The pattern to look for. If resource locations have been
108            added recursively, subdirectories will be searched too so this
109            does not need to be fully qualified.
110        @return
111            Shared pointer to a data stream list , will be
112            destroyed automatically when no longer referenced
113        */
114        static DataStreamListPtr openMulti(const std::string& pattern);
115
116        /**
117            Find out if the named file exists.
118        @param name
119            Fully qualified name of the file to test for
120        */
121        static bool exists(const std::string& name);
122
123        /**
124            Get struct with information about path and size.
125        @param name
126            Fully qualified name of the file to test for
127        */
128        static std::shared_ptr<ResourceInfo> getInfo(const std::string& name);
129
130        /**
131            Retrieves a list with all resources matching a certain pattern.
132        @param pattern
133            The pattern to look for. If resource locations have been
134            added recursively, subdirectories will be searched too so this
135            does not need to be fully qualified.
136        */
137        static StringVectorPtr findResourceNames(const std::string& pattern);
138
139        //! Name of the default resource group (usually "General")
140        static const std::string& getDefaultResourceGroup();
141
142    private:
143        // static class, no instances allowed:
144        Resource() = delete;
145        Resource(const Resource&) = delete;
146        Resource& operator=(const Resource&) = delete;
147        ~Resource() = delete;
148    };
149}
150
151#endif /* _Core_Resource_H__ */
Note: See TracBrowser for help on using the repository browser.