degate  0.1.2
Public Member Functions | Private Attributes
degate::ImageReaderFactory< ImageType > Class Template Reference

A factory for creating image reader objects. More...

#include <ImageReaderFactory.h>

List of all members.

Public Member Functions

 ImageReaderFactory ()
 ~ImageReaderFactory ()
file_format_collection const & get_file_formats () const
 Get a list of parseable file formats.
std::shared_ptr< class
ImageReaderBase< ImageType > > 
get_reader (std::string const &filename)
 Get a concrete image reader object for a file name.

Private Attributes

file_format_collection file_formats

Detailed Description

template<class ImageType>
class degate::ImageReaderFactory< ImageType >

A factory for creating image reader objects.

Definition at line 46 of file ImageReaderFactory.h.


Constructor & Destructor Documentation

template<class ImageType>
degate::ImageReaderFactory< ImageType >::ImageReaderFactory ( ) [inline]

Definition at line 56 of file ImageReaderFactory.h.

References degate::ImageReaderFactory< ImageType >::file_formats.

                         {
      // Tiff file format parser
      file_formats.push_back("tif");
      file_formats.push_back("tiff");

      // Jpeg file format parser
      file_formats.push_back("jpg");
      file_formats.push_back("jpeg");
    }
template<class ImageType>
degate::ImageReaderFactory< ImageType >::~ImageReaderFactory ( ) [inline]

Definition at line 67 of file ImageReaderFactory.h.

{}

Member Function Documentation

template<class ImageType>
file_format_collection const& degate::ImageReaderFactory< ImageType >::get_file_formats ( ) const [inline]

Get a list of parseable file formats.

Definition at line 72 of file ImageReaderFactory.h.

References degate::ImageReaderFactory< ImageType >::file_formats.

                                                           {
      return file_formats;
    }
template<class ImageType>
std::shared_ptr<class ImageReaderBase<ImageType> > degate::ImageReaderFactory< ImageType >::get_reader ( std::string const &  filename) [inline]

Get a concrete image reader object for a file name.

Parameters:
filenameThe file name is evaluated. Depending on the file suffix an image reader is choosen. The file must not exists for the reader selection, but the reader will fail, if it can't read the image.
Returns:
Returns an image reader object that is able to read the image.
Exceptions:
InvalidFileFormatExceptionThis exception is thrown if the there is no reader that can read the file.

Definition at line 87 of file ImageReaderFactory.h.

References degate::get_file_suffix().

Referenced by degate::load_image().

                                           {

      std::string suffix(get_file_suffix(filename).c_str());

      /*
        Convert suffix string to a lowercase string.

        This comment should not be necessary, if there would be a simple
        way to convert it. You may have seen other programming languages
        with a simple convenient way to lowercase strings. But hey! The
        transform is really generic, You can even apply it to strings. Wow!
        BTW: If you omit the static cast, you will get a long error message
        from your compiler. Great!
      */

      std::transform(suffix.begin(), suffix.end(), suffix.begin(),
                     static_cast<int (*)(int)>(std::tolower));

      // Ok. Enough sarcasm. Let us finish the job ...

      if(suffix == "tif" || suffix == "tiff")
        return std::shared_ptr<ImageReaderBase<ImageType> >
          (new TIFFReader<ImageType>(filename));
      else if(suffix == "jpg" || suffix == "jpeg")
        return std::shared_ptr<ImageReaderBase<ImageType> >
          (new JPEGReader<ImageType>(filename));
      else throw InvalidFileFormatException();
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

template<class ImageType>
file_format_collection degate::ImageReaderFactory< ImageType >::file_formats [private]

The documentation for this class was generated from the following file: