rawfilefactory.cpp

00001 /*
00002  * libopenraw - rawfilefactory.cpp
00003  *
00004  * Copyright (C) 2006, 2008 Hubert Figuiere
00005  *
00006  * This library is free software: you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation, either version 3 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library.  If not, see
00018  * <http://www.gnu.org/licenses/>.
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   Local Variables:
00095   mode:c++
00096   c-file-style:"stroustrup"
00097   c-file-offsets:((innamespace . 0))
00098   indent-tabs-mode:nil
00099   fill-column:80
00100   End:
00101 */

Generated by  doxygen 1.6.2