1 /** @file
2  *
3  * @authors Copyright (c) 2014-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  *
5  * @par License
6  * GPL: http://www.gnu.org/licenses/gpl.html
7  *
8  * <small>This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; either version 2 of the License, or (at your
11  * option) any later version. This program is distributed in the hope that it
12  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details. You should have received a copy of the GNU
15  * General Public License along with this program; if not, see:
16  * http://www.gnu.org/licenses</small>
17  */
18 
19 #include "doomsday/filesys/filetype.h"
20 
21 using namespace de;
22 
23 static NullFileType nullFileType;
24 
25 /// A symbolic name => file type map.
26 static FileTypes fileTypeMap;
27 
DD_AddFileType(FileType const & ftype)28 void DD_AddFileType(FileType const &ftype)
29 {
30     fileTypeMap.insert(ftype.name().toLower(), &ftype);
31 }
32 
DD_FileTypeByName(String name)33 FileType const &DD_FileTypeByName(String name)
34 {
35     if (!name.isEmpty())
36     {
37         FileTypes::const_iterator found = fileTypeMap.constFind(name.toLower());
38         if (found != fileTypeMap.constEnd()) return **found;
39     }
40     return nullFileType; // Not found.
41 }
42 
DD_GuessFileTypeFromFileName(String path)43 FileType const &DD_GuessFileTypeFromFileName(String path)
44 {
45     if (!path.isEmpty())
46     {
47         DENG2_FOR_EACH_CONST(FileTypes, i, fileTypeMap)
48         {
49             FileType const &ftype = **i;
50             if (ftype.fileNameIsKnown(path))
51                 return ftype;
52         }
53     }
54     return nullFileType;
55 }
56 
DD_FileTypes()57 FileTypes &DD_FileTypes()
58 {
59     return fileTypeMap;
60 }
61