xoreos  0.0.5
util.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_UTIL_H
26 #define AURORA_UTIL_H
27 
28 #include <map>
29 
30 #include "src/common/singleton.h"
31 #include "src/common/hash.h"
32 #include "src/common/ustring.h"
33 
34 #include "src/aurora/types.h"
35 
36 namespace Aurora {
37 
40 
41 
42 class FileTypeManager : public Common::Singleton<FileTypeManager> {
43 public:
46 
49 
51  FileType getFileType(Common::HashAlgo algo, uint64 hashedExtension);
52 
57 
58 
59 private:
61  struct Type {
63  const char *extension;
64  };
65 
66  static const Type types[];
67 
68  typedef std::map<Common::UString, const Type *> ExtensionLookup;
69  typedef std::map<FileType , const Type *> TypeLookup;
70  typedef std::map<uint64 , const Type *> HashLookup;
71 
75 
76 
77  void buildExtensionLookup();
78  void buildTypeLookup();
80 };
81 
82 } // End of namespace Aurora
83 
85 #define TypeMan ::Aurora::FileTypeManager::instance()
86 
87 #endif // AURORA_UTIL_H
ExtensionLookup _extensionLookup
Definition: util.h:72
void buildExtensionLookup()
Definition: util.cpp:401
Class and macro for implementing singletons.
std::map< FileType, const Type * > TypeLookup
Definition: util.h:69
A class holding an UTF-8 string.
Definition: ustring.h:48
uint64_t uint64
Definition: types.h:206
std::map< uint64, const Type * > HashLookup
Definition: util.h:70
const char * extension
Definition: util.h:63
Utility hash functions.
Common::UString addFileType(const Common::UString &path, FileType type)
Return the file name with an added extensions according to the specified file type.
Definition: util.cpp:373
Common::UString setFileType(const Common::UString &path, FileType type)
Return the file name with a swapped extensions according to the specified file type.
Definition: util.cpp:377
Generic template base class for implementing the singleton design pattern.
Definition: singleton.h:61
HashLookup _hashLookup[Common::kHashMAX]
Definition: util.h:74
std::map< Common::UString, const Type * > ExtensionLookup
Definition: util.h:68
For range checks.
Definition: hash.h:43
HashAlgo
The algorithm used for hashing.
Definition: hash.h:37
static const Type types[]
Definition: util.h:66
FileType getFileType(const Common::UString &path)
Return the file type of a file name, detected by its extension.
Definition: util.cpp:361
Unicode string handling.
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
void buildHashLookup(Common::HashAlgo algo)
Definition: util.cpp:417
File type <-> extension mapping.
Definition: util.h:61
FileType
Various file types used by the Aurora engine and found in archives.
Definition: types.h:56
Common::UString getPlatformDescription(Platform platform)
Return the human readable string of a Platform.
Definition: util.cpp:430
TypeLookup _typeLookup
Definition: util.h:73
Platform
Definition: types.h:429