indii/ml/data/TextFileReader.hpp

00001 #ifndef INDII_ML_DATA_TEXTFILEReader_HPP
00002 #define INDII_ML_DATA_TEXTFILEReader_HPP
00003 
00004 #include "Reader.hpp"
00005 
00006 #include "../aux/vector.hpp"
00007 #include "../aux/matrix.hpp"
00008 
00009 #include <sstream>
00010 
00011 namespace indii {
00012   namespace ml {
00013     namespace data {
00014 
00015 /**
00016  * Reader for white-space delimited text files.
00017  *
00018  * @author Lawrence Murray <lawrence@indii.org>
00019  * @version $Rev: 582 $
00020  * @date $Date: 2008-12-15 17:03:50 +0000 (Mon, 15 Dec 2008) $
00021  */
00022 class TextFileReader : public Reader {
00023 public:
00024   /**
00025    * Construct new reader from input stream, where all columns are
00026    * of interest.
00027    *
00028    * @param in Stream from which to read.
00029    */
00030   TextFileReader(std::istream* in);
00031 
00032   /**
00033    * Construct new reader from file, where all columns are of
00034    * interest.
00035    *
00036    * @param file Name of file from which to read.
00037    */
00038   TextFileReader(const std::string& file);
00039 
00040   /**
00041    * Construct new reader from input stream, where only a single
00042    * column is of interest.
00043    *
00044    * @param in Stream from which to read.
00045    * @param col Index of column of interest.
00046    */
00047   TextFileReader(std::istream* in, unsigned int col);
00048 
00049   /**
00050    * Construct new reader from file, where only a single column is
00051    * of interest.
00052    *
00053    * @param file Name of file from which to read.
00054    * @param col Index of column of interest.
00055    */
00056   TextFileReader(const std::string& file, unsigned int col);
00057 
00058   /**
00059    * Construct new reader from input stream, where only a subset
00060    * of columns are of interest.
00061    *
00062    * @param in Stream from which to read.
00063    * @param cols Set of indices giving columns of interest.
00064    */
00065   TextFileReader(std::istream* in, const std::vector<unsigned int>& cols);
00066 
00067   /**
00068    * Construct new reader from file, where only a subset of columns
00069    * are of interest.
00070    *
00071    * @param file Name of file from which to read.
00072    * @param cols Set of indices giving columns of interest.
00073    */
00074   TextFileReader(const std::string& file,
00075       const std::vector<unsigned int>& cols);
00076 
00077   /**
00078    * Destructor.
00079    */
00080   ~TextFileReader();
00081 
00082   virtual unsigned int read(double* into);
00083 
00084   virtual unsigned int read(indii::ml::aux::vector* into);
00085 
00086   virtual unsigned int read(indii::ml::aux::matrix* into);
00087 
00088   virtual unsigned int read(indii::ml::aux::symmetric_matrix* into);
00089 
00090 private:
00091   /**
00092    * Values on the current line.
00093    */
00094   std::vector<double> values;
00095 
00096   /**
00097    * Current index in the columns of interest vector.
00098    */
00099   unsigned int nextIndex;
00100 
00101   /** 
00102    * Move to next line in the stream.
00103    */
00104   void nextLine();
00105 
00106 };
00107 
00108     }
00109   }
00110 }
00111 
00112 #endif

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3