Blame lib/rawfilefactory.hpp

rpm-build d2b433
/*
rpm-build d2b433
 * libopenraw - rawfilefactory.h
rpm-build d2b433
 *
rpm-build d2b433
 * Copyright (C) 2006-2016 Hubert Figuiere
rpm-build d2b433
 *
rpm-build d2b433
 * This library is free software: you can redistribute it and/or
rpm-build d2b433
 * modify it under the terms of the GNU Lesser General Public License
rpm-build d2b433
 * as published by the Free Software Foundation, either version 3 of
rpm-build d2b433
 * the License, or (at your option) any later version.
rpm-build d2b433
 *
rpm-build d2b433
 * This library is distributed in the hope that it will be useful,
rpm-build d2b433
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build d2b433
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build d2b433
 * Lesser General Public License for more details.
rpm-build d2b433
 *
rpm-build d2b433
 * You should have received a copy of the GNU Lesser General Public
rpm-build d2b433
 * License along with this library.  If not, see
rpm-build d2b433
 * <http://www.gnu.org/licenses/>.
rpm-build d2b433
 */
rpm-build d2b433
rpm-build d2b433
#ifndef OR_INTERNALS_RAWFILEFACTORY_H_
rpm-build d2b433
#define OR_INTERNALS_RAWFILEFACTORY_H_
rpm-build d2b433
rpm-build d2b433
#include <string>
rpm-build d2b433
#include <map>
rpm-build d2b433
#include <functional>
rpm-build d2b433
rpm-build d2b433
#include "rawfile.hpp"
rpm-build d2b433
#include "io/stream.hpp"
rpm-build d2b433
rpm-build d2b433
namespace OpenRaw {
rpm-build d2b433
namespace Internals {
rpm-build d2b433
rpm-build d2b433
class RawFileFactory
rpm-build d2b433
{
rpm-build d2b433
public:
rpm-build d2b433
    typedef std::function<RawFile*(const IO::Stream::Ptr&)> raw_file_factory_t;
rpm-build d2b433
    /** the factory type for raw files
rpm-build d2b433
     * key is the extension. file is factory method
rpm-build d2b433
     */
rpm-build d2b433
    typedef
rpm-build d2b433
    std::map<RawFile::Type, raw_file_factory_t> Table;
rpm-build d2b433
    typedef
rpm-build d2b433
    std::map<std::string, RawFile::Type> Extensions;
rpm-build d2b433
rpm-build d2b433
    /** register a filetype with the factory
rpm-build d2b433
     * @param type the type of file
rpm-build d2b433
     * @param fn the factory method
rpm-build d2b433
     * @param ext the extension associated
rpm-build d2b433
     * @note it is safe to call this method with the same
rpm-build d2b433
     * fn and type to register a different extension
rpm-build d2b433
     */
rpm-build d2b433
    RawFileFactory(RawFile::Type type,
rpm-build d2b433
                   const raw_file_factory_t & fn,
rpm-build d2b433
                   const char * ext);
rpm-build d2b433
rpm-build d2b433
    /** access the table. Ensure that it has been constructed. */
rpm-build d2b433
    static Table & table();
rpm-build d2b433
    /** access the extensions table. Ensure that it has been constructed. */
rpm-build d2b433
    static Extensions & extensions();
rpm-build d2b433
rpm-build d2b433
    /** access the the list of file extenstions registered. */
rpm-build d2b433
    static const char **fileExtensions();
rpm-build d2b433
rpm-build d2b433
    static void registerType(RawFile::Type type,
rpm-build d2b433
                             const raw_file_factory_t & fn,
rpm-build d2b433
                             const char * ext);
rpm-build d2b433
    static void unRegisterType(RawFile::Type type);
rpm-build d2b433
};
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
/** accessor. This make sure the instance has been
rpm-build d2b433
 * constructed when needed
rpm-build d2b433
 */
rpm-build d2b433
inline RawFileFactory::Table & RawFileFactory::table()
rpm-build d2b433
{
rpm-build d2b433
    /** the factory table */
rpm-build d2b433
    static Table rawFactoryTable;
rpm-build d2b433
    return rawFactoryTable;
rpm-build d2b433
}
rpm-build d2b433
rpm-build d2b433
inline RawFileFactory::Extensions & RawFileFactory::extensions()
rpm-build d2b433
{
rpm-build d2b433
    /** the factory table */
rpm-build d2b433
    static Extensions rawExtensionsTable;
rpm-build d2b433
    return rawExtensionsTable;
rpm-build d2b433
}
rpm-build d2b433
rpm-build d2b433
}
rpm-build d2b433
}
rpm-build d2b433
rpm-build d2b433
#endif
rpm-build d2b433
/*
rpm-build d2b433
  Local Variables:
rpm-build d2b433
  mode:c++
rpm-build d2b433
  c-file-style:"stroustrup"
rpm-build d2b433
  c-file-offsets:((innamespace . 0))
rpm-build d2b433
  indent-tabs-mode:nil
rpm-build d2b433
  fill-column:80
rpm-build d2b433
  End:
rpm-build d2b433
*/