rawfilefactory.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022
00023 #include <iostream>
00024 #include <cassert>
00025
00026 #include "rawfilefactory.h"
00027 #include "debug.h"
00028
00029 using namespace Debug;
00030
00031 namespace OpenRaw {
00032
00033 namespace Internals {
00034
00035
00036 RawFileFactory::RawFileFactory(RawFile::Type type,
00037 const RawFileFactory::raw_file_factory_t & fn,
00038 const char *ext)
00039 {
00040 Trace(DEBUG1) << "registering type "
00041 << (int)type << "\n";
00042 registerType(type, fn, ext);
00043 }
00044
00045
00046 void RawFileFactory::registerType(RawFile::Type type,
00047 const RawFileFactory::raw_file_factory_t & fn,
00048 const char *ext)
00049 {
00050 if (fn == NULL)
00051 {
00052 Trace(ERROR) << "NULL fn for registerFactory()\n";
00053 assert(fn == NULL);
00054 }
00055 table()[type] = fn;
00056 extensions()[ext] = type;
00057 }
00058
00059
00060 void RawFileFactory::unRegisterType(RawFile::Type type)
00061 {
00062 Table::iterator iter = table().find(type);
00063 if (iter == table().end())
00064 {
00065 Trace(ERROR) << "attempting to unregisterFactory() in unregistered "
00066 "element\n";
00067 assert(true);
00068 }
00069 table().erase(iter);
00070 }
00071
00072 const char **RawFileFactory::fileExtensions()
00073 {
00074 static const char **_fileExtensions = NULL;
00075 if(!_fileExtensions) {
00076 Extensions & ext = extensions();
00077 size_t s = ext.size();
00078 _fileExtensions = (const char**)calloc((s + 1), sizeof(char*));
00079 const char **current = _fileExtensions;
00080 Extensions::const_iterator iter(ext.begin());
00081 for ( ; iter != ext.end(); ++iter) {
00082 *current = iter->first.c_str();
00083 current++;
00084 }
00085 }
00086
00087 return _fileExtensions;
00088 }
00089
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101