/*
 * class FileName
 *
 * $Date$
 * $Revision$
 *
 */

#ifndef FILE_NAME_HH__
#define FILE_NAME_HH__

/** 
 * @addtogroup WImage 
 * @{ */

/** 
 * File types. These are tags standing for known and supported file
 * formats or unknown files. */
typedef enum { 
  fn_pgm, fn_raw, fn_pfi, fn_ppm, fn_jpg, 
  fn_vid, fn_avi, fn_png, fn_gif, fn_unknown 
} filetype;

/** 
 * File names. This splits a DOS- or Unix-like filespec into its
 * parts (dir, name without extension, extension) and guesses what
 * kind of (image) file it is according to the (case insignificant) 
 * file extension. 
 */
class 
FileName
{
public:
  /** Constructor. The file name is being set, and the filename is 
   * split into its bits. At last the file type is guessed. 
   * @param name
   * the file name 
   * @exception invalid_argument
   * the file name is a {\em NULL} pointer */
  FileName (char const *name);
  /** Destructor. Releases allocated memory. */
  ~FileName (void);

  /** Compares two extensions. The comparison is case insensitive. 
   * @param ext
   * the other extension
   * @return
   * they are equal: {\em true} else {\em false} */
  bool isext (const char *ext) const;
  /** Set a new extension. This might be useful if we want to 
   * create an output file name. 
   * @param ext
   * the new extension */
  void toext (const char *ext);

  /** Return the guessed type. No calculation is done here. 
   * @return 
   * the file type */
  inline filetype guess (void) const { return m_ftype; }
  /** Return a mime type for the guessed type.
   * @return 
   * the mime type, empty string if none was found */
  const char * guessedMimeType (void) const;
  /** Return the file name. 
   * @return
   * the file name */
  inline char *file (void) const { return m_fname; }
  /** Return the directory name. 
   * @return
   * the directory name */
  inline char *dir (void) const { return m_dirname; }
  /** Return the basename without extension. 
   * @return
   * the name without extension */
  inline char *base (void) const { return m_basename; }
  /** Return the file extension. 
   * @return
   * the file extension */
  inline char *ext (void) const { return m_extension; }
  /** Is it a DOS-like name?
   * @return
   * if a DOS-like name: {\em true}, else {\em false} */
  inline bool dos (void) const { return m_isdos; }
  
private:
  /** The complete filename */
  char *m_fname;
  /** The directory name */
  char *m_dirname;
  /** The file name without extension */
  char *m_basename;
  /** The file extension */
  char *m_extension;
  /** Is it a DOS-like filespec? It is as soon as we find a backslash
   * somewhere in it! */
  bool m_isdos;
  /** The file type. This is guessed from the file's extension. */
  filetype m_ftype;
  /** Guess the type. This sets the {\em m_ftype} variable. */
  void guessext (void);

}; /* class FileName */

/** @} */

#endif /* FILE_NAME_HH__ */

