#ifndef IMAGE_INPUT_H
#define IMAGE_INPUT_H

#include "mimasexception.h"
#include "image.h"

namespace mimas {

/** @defgroup imageIO Image I/O
    The I/O-facilities for images of mimas are implemented using inheritance.
    This makes it possible to write programs, where the input-source and the
    output-target for an image (or several images) are exchangable.
    @{ */
/** @defgroup imageInput Image Input
    This group contains classes for retrieving image(s) from different input
    sources.
    @{ */
/** Abstract base-class for input sources.
    This is a base-class for input sources. It allows to implement a program,
    which retrieves an image from an arbitrary input-source. E.g.:
    \code
    using namespace mimas;
    ...
    void test( image_input< rgba< unsigned char > > &source ) {
       image< rgba< unsigned char > > image;
       if ( source >> image ) {
         ...
       } else {
         // End of input has been reached.
       }
       ...
    };
    ...
    \endcode */
template< typename T >
class image_input: public object
{
 public:
  /** Constructor.
      The state is set to valid (end of stream not encountered yet). */
  image_input(void): state( true ) {}
  /** Read image from arbitrary source.
      This function is virtual and has to be implemented by the inheriting
      class.
      @param img Object to store image in. */
  virtual void read( image< T > &img ) throw (mimasexception) = 0;
  /// Indicator for input-source being alive.
  operator bool(void) const { return state; }
  /// Indicator for end of input-source.
  bool operator!(void) const { return !state; }
 protected:
  /// State variable.
  bool state;
};

/// Stream-operator for arbitrary input-source.
template< typename T >
inline image_input< T > &operator>>( image_input< T > &input,
                                        image< T > &img )
{ input.read( img ); return input; }

///@}

///@}

};

#endif