libopenraw
rawfilefactory.cpp
1/*
2 * libopenraw - rawfilefactory.cpp
3 *
4 * Copyright (C) 2006-2017 Hubert Figuière
5 *
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
21#include <stdlib.h>
22#include <stddef.h>
23
24#include <utility>
25#include <cassert>
26
27#include <libopenraw/debug.h>
28
29#include "rawfile.hpp"
30#include "rawfilefactory.hpp"
31#include "trace.hpp"
32
33using namespace Debug;
34
35namespace OpenRaw {
36
37namespace Internals {
38
40 const RawFileFactory::raw_file_factory_t &fn,
41 const char *ext)
42{
43 LOGDBG1("registering type %d\n", (int)type);
44 registerType(type, fn, ext);
45}
46
47void RawFileFactory::registerType(RawFile::Type type,
48 const RawFileFactory::raw_file_factory_t &fn,
49 const char *ext)
50{
51 if (fn == nullptr) {
52 LOGERR("NULL fn for registerFactory()\n");
53 assert(fn == nullptr);
54 }
55 table()[type] = fn;
56 extensions()[ext] = type;
57}
58
59void RawFileFactory::unRegisterType(RawFile::Type type)
60{
61 Table::iterator iter = table().find(type);
62 if (iter == table().end()) {
63 LOGERR("attempting to unregisterFactory() in unregistered element\n");
64 assert(true);
65 }
66 table().erase(iter);
67}
68
70{
71 static const char **_fileExtensions = NULL;
72 if (!_fileExtensions) {
73 Extensions &ext = extensions();
74 size_t s = ext.size();
75 _fileExtensions = (const char **)calloc((s + 1), sizeof(char *));
76 const char **current = _fileExtensions;
77 Extensions::const_iterator iter(ext.begin());
78 for (; iter != ext.end(); ++iter) {
79 *current = iter->first.c_str();
80 current++;
81 }
82 }
83
84 return _fileExtensions;
85}
86}
87}
88
static const char ** fileExtensions()
RawFileFactory(RawFile::Type type, const raw_file_factory_t &fn, const char *ext)
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard....
Definition: arwfile.cpp:30