www.pudn.com > firev0.01.rar > filelist.hpp


/*
This file is part of the FIRE -- Flexible Image Retrieval System

FIRE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

FIRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FIRE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/**
 * @file   filelist.hpp
 * @author Thomas Deselaers
 * @date   Mon Jun 23 19:11:02 2003
 * 
 * @brief  FileList: generic filelist which can contain classes, descriptions and of course filenames.
 *      
 * a quite comfortable way to load (and save) should be provided.
 */
#ifndef __filelist_hpp
#define __filelist_hpp

#include 
#include 
#include 
#include 

typedef std::vector StringVector;
typedef std::vector IntVector;

class FileList {
public:

  /** 
   * Do nothing constructor.
   * 
   */
  FileList();


  /** 
   * Load Filelist from file filename
   * 
   * @param filename the filename of the file to be loaded
   */
  FileList(std::string filename);

  /**   load a filelist from a file.
    * 
    * 
    * @param filename the filename of the file to be loaded.
    * 
    * @return the number of files in this list.
    */
  int load(std::string filename);
  /** save a filelist to a file. (Take care, don't know if implemented and up to date)
   * @param filename, the name of the file to be written
   * @return the number of files written
   */
  int save(std::string filename);

  /**
   * return the basename of the i-th file, that is filename without suffices and path
   *
   * @param i the number of the file whichs basename is requested.
   * @return the basename of the i-th file.
   */
  const std::string basename(const unsigned int i) const;

  /** given a filename this returns the class 
   * @param filename the name of the file where the classname is wanted for
   * @return the classnumber of the file or -1 if the filename cannot be found
   */
  const int searchClassForFilename(const ::std::string & filename) const;
  const int searchIndexForFilename(const ::std::string & filename) const;
  
  /** 
   * return the name of the i-th file with path and 1st. suffix
   * 
   * @param i the number of the file to be returned
   * 
   * @return the name of the i-th file
   */
  const std::string operator[](const unsigned int i) const;

  /** 
   * return the name of the i-th file with the j-th suffix and path
   * @param i the number of the file
   * @param j the number of the suffix
   * @return the name of the i-th file with j-th suffix and path
   */
  const std::string operator()(const unsigned int i, const unsigned int j=0) const;
  
  /** 
   * return the i-th string description.
   * 
   * @param i the number of the image for which you want the
   * description.
   * 
   * @return the string describing the i-th image.
   */
  const ::std::string& description(const unsigned int i) const;


  /** 
   * return the set of tokens from the string description form the i-th image
   * @param i the number of the image for which you want the
   * description.
   * 
   * @return the set of tokens from the description
   */

  const ::std::set< ::std::string >  decomposedDescription(const unsigned int i) const;

  /** 
   * return the class of the i-th image
   * 
   * @param i the number of the image for which the class is needed.
   * 
   * @return the class of the i-th image.
   */
  const int cls(const unsigned int i) const;

  /**
   * reference to the class of the i-th image.
   * @param i the number of the image for which the class is needed and might be changed.
   * @return a reference to the class of the i-th image.
   */
  int & cls(const unsigned int i);
  
  /** 
   * the filename of the list
   * 
   * @return a reference to the filename of the list itself.
   */
  std::string& filename();
  
  /** 
   * the filename of the list
   * 
   * @return a reference to the filename of the list itself.
   */
  const std::string& filename() const;

  /** 
   * the path where the files from the list can be found.
   * 
   * 
   * @return the path where the files from the list can be found.
   */
  std::string& path();
  /** 
   * the path where the files from the list can be found.
   * 
   * 
   * @return the path where the files from the list can be found.
   */
  const std::string& path() const;
  
  /** 
   * return the i-th suffix for this list
   * 
   * @param i the number of the suffix which is requested.
   * 
   * @return the i-th suffix for this list
   */
  const std::string& suffix(const unsigned int i=0) const ;
  
  /** 
   * the number of suffices available for this list.
   * 
   * 
   * @return the number of suffices available for this list.
   */
  const unsigned int nOfSuffices() const;
  
  /** 
   * how many filenames are stored in this list?
   * 
   * 
   * @return the number of filenames stored.
   */
  const unsigned int size() const;
  /** 
   * clear the list.
   * 
   */
  void clear();

  const bool withDescription() const {return withDescription_;}
  const bool withCls() const {return withCls_;}


private:
  std::string filename_;

  bool withDescription_;
  
  std::string path_;  
  bool withCls_;

  StringVector suffices_;
  StringVector descriptions_;
  StringVector filenames_;
  IntVector classes_;


};

/**
 * Print the filelist to a stream.
 *
 */

inline std::ostream& operator<<(std::ostream& os, const FileList & src) {
  os << "Filename: " << src.filename() << std::endl
     << "Path:     " << src.path() << std::endl
     << "Suffix:   " << src.suffix() << std::endl
     << "Size:     " << src.size() << std::endl
     << "Files:" << std::endl;
  for(unsigned int i=0;i