Interpolator::FileReader Class Reference

This class provides basics tools to read files
It is mainly used for the correcting and coupling files
Thanks to this abstract class, it is possible to define a specific file reader for each scientific group
The only things to do is to implement the Parse method. More...

#include <FileReader.h>

Inherited by Interpolator::GenericFileReader1D, Interpolator::GenericFileReader2D, Interpolator::LowEnergyThetaBraggCorrectionReader, and Interpolator::SambaFileReader.

Inheritance diagram for Interpolator::FileReader:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 FileReader ()
 Default constructor.
 FileReader (const std::string &sFileName)
 This constructor requires 1 parameter :
  • the name of the file to read If the file can be opened, the file is put in an buffer
    Thus once the file read, the file is not still in use (the file is closed)
    All the Data are put in the buffer and all the operations are done in the buffer not directly in the file.

 FileReader (const std::string &sFileName, long lNbVariables, long lNbDatas)
 This constructor requires 3 parameters :
  • the name of the file to read
  • the number of variables (number of columns) of the file to read
  • the number of Data (number of lines) of the file to read (without the first line which contains the differents variables names) If the file can be opened, the file is put in an buffer
    Thus once the file read, the file is not still in use (the file is closed)
    All the Data are put in the buffer and all the operations are done in the buffer not directly in the file.

virtual ~FileReader ()
 Destructor.
bool isReadable ()
 This method test if the file can be open and read.
double extractDouble ()
 Extract a double from the buffer.
std::string extractString ()
 Extract a std::string from the buffer.
int extractInt ()
 Extract a int from the buffer.
std::string extractLine ()
 Return a complete line of the buffer.
long extractFileSize ()
 Return the size of the file.
long extractNbFileLines ()
 Return the number of lines of the file.
long extractBufferSize ()
 Compute the size of the buffer.
long getFileSize () const
 Return the file size.
long getNbFileLines () const
 Return the number of lines of the file.
long getBufferSize () const
 Return the size of the buffer containing the file.
long getNbVariables () const
 Return the number of variables (the number of columns) of the file.
long getNbData () const
 Return the number of Data (number of lines of Data) of the file.
void setFileSize (long lFileSize)
 Set the file size.
void setNbFileLines (long lNbFileLines)
 Set the number of lines in the file.
void setBufferSize (long lBufferSize)
 Set the size of the buffer containing the file.
void setNbVariables (long lNbVariables)
 Set the number of variables (the number of columns).
void setNbData (long lNbData)
 Set the number of Data (number of lines of Data).
void copyFileToBuffer ()
 This method is used to copy the file in the buffer
After the copy is done the file is closed.
virtual void Parse ()=0
void extractHeader ()

Private Attributes

std::string _sFileName
long _lNbVariables
long _lNbData
std::stringstream _mFileBuffer
long _lBufferSize
long _lFileSize
long _lNbFileLines

Detailed Description

This class provides basics tools to read files
It is mainly used for the correcting and coupling files
Thanks to this abstract class, it is possible to define a specific file reader for each scientific group
The only things to do is to implement the Parse method.

Definition at line 30 of file FileReader.h.


Constructor & Destructor Documentation

Interpolator::FileReader::FileReader  ) 
 

Default constructor.

Definition at line 23 of file FileReader.cpp.

00024 {
00025 
00026 }

Interpolator::FileReader::FileReader const std::string &  sFileName  ) 
 

This constructor requires 1 parameter :

  • the name of the file to read If the file can be opened, the file is put in an buffer
    Thus once the file read, the file is not still in use (the file is closed)
    All the Data are put in the buffer and all the operations are done in the buffer not directly in the file.

Exceptions:
This method throw a FileNotFoundException exception if the file sFileName can't be open or read.

Definition at line 40 of file FileReader.cpp.

References Interpolator::Interpolator::_verb, copyFileToBuffer(), extractBufferSize(), extractFileSize(), extractHeader(), extractNbFileLines(), isReadable(), setBufferSize(), setFileSize(), and setNbFileLines().

00040                                                  : _sFileName(sFileName)// throw (FileNotFoundException)
00041 {
00042         if(isReadable()) 
00043         {
00044                 copyFileToBuffer();
00045                 setBufferSize(extractBufferSize());
00046                 setFileSize(extractFileSize());
00047                 setNbFileLines(extractNbFileLines());
00048                 extractHeader();
00049                 if(Interpolator::_verb == true) cout << "Open file : " << sFileName << " --> OK" << endl;
00050         }
00051         else throw FileNotFoundException(sFileName,"FileReader::FileReader(const std::string& sFileName)",__FILE__,__LINE__);
00052 }

Here is the call graph for this function:

Interpolator::FileReader::FileReader const std::string &  sFileName,
long  lNbVariables,
long  lNbData
 

This constructor requires 3 parameters :

  • the name of the file to read
  • the number of variables (number of columns) of the file to read
  • the number of Data (number of lines) of the file to read (without the first line which contains the differents variables names) If the file can be opened, the file is put in an buffer
    Thus once the file read, the file is not still in use (the file is closed)
    All the Data are put in the buffer and all the operations are done in the buffer not directly in the file.

Exceptions:
This method throw a FileNotFoundException exception if the file sFileName can't be open or read.

Definition at line 62 of file FileReader.cpp.

References Interpolator::Interpolator::_verb, copyFileToBuffer(), extractBufferSize(), extractFileSize(), extractNbFileLines(), isReadable(), setBufferSize(), setFileSize(), and setNbFileLines().

00062                                                                                  : _sFileName(sFileName),_lNbVariables(lNbVariables),_lNbData(lNbData) // throw (FileNotFoundException)
00063 {
00064         if(isReadable()) 
00065         {
00066                 copyFileToBuffer();
00067                 setBufferSize(extractBufferSize());
00068             setFileSize(extractFileSize());
00069                 setNbFileLines(extractNbFileLines());
00070                 if(Interpolator::_verb == true) cout << "Open file : " << sFileName << " --> OK" << endl;
00071         }
00072         else throw FileNotFoundException(sFileName,"FileReader::FileReader(const std::string& sFileName,long lNbVariables,long lNbData)",__FILE__,__LINE__);
00073 }

Here is the call graph for this function:

Interpolator::FileReader::~FileReader  )  [virtual]
 

Destructor.

Definition at line 29 of file FileReader.cpp.

00030 {
00031 
00032 }


Member Function Documentation

void Interpolator::FileReader::copyFileToBuffer  ) 
 

This method is used to copy the file in the buffer
After the copy is done the file is closed.

Exceptions:
This method throw a FileNotFoundException exception if the file can't be open or read.

Definition at line 194 of file FileReader.cpp.

References _mFileBuffer, _sFileName, extractBufferSize(), and setBufferSize().

Referenced by FileReader().

00195 {
00196         ifstream mFile(_sFileName.c_str());
00197 
00198     if ( mFile ) 
00199     {
00200                 _mFileBuffer << mFile.rdbuf();
00201         mFile.close();
00202                 setBufferSize(extractBufferSize());
00203     }
00204         else throw FileNotFoundException(_sFileName,"FileReader::copyFileToBuffer()",__FILE__,__LINE__);
00205 }

Here is the call graph for this function:

long Interpolator::FileReader::extractBufferSize  ) 
 

Compute the size of the buffer.

Definition at line 186 of file FileReader.cpp.

References _mFileBuffer.

Referenced by copyFileToBuffer(), and FileReader().

00187 {
00188         return (long)_mFileBuffer.str().size();
00189 }

double Interpolator::FileReader::extractDouble  ) 
 

Extract a double from the buffer.

Definition at line 161 of file FileReader.cpp.

References extractString().

Referenced by Interpolator::SambaFileReader::Parse(), Interpolator::LowEnergyThetaBraggCorrectionReader::Parse(), Interpolator::GenericFileReader2D::Parse(), and Interpolator::GenericFileReader1D::Parse().

00162 {
00163 
00164   std::string sTemp;
00165   sTemp = extractString();
00166   return atof(sTemp.c_str());
00167 }

Here is the call graph for this function:

long Interpolator::FileReader::extractFileSize  ) 
 

Return the size of the file.

Definition at line 90 of file FileReader.cpp.

References _sFileName.

Referenced by FileReader().

00091 {
00092         ifstream mFile(_sFileName.c_str());
00093     long pos,size;
00094         if (mFile) 
00095         {
00096                 pos = mFile.tellg();
00097                 mFile.seekg( 0 ,        ios_base::end );
00098                 size = mFile.tellg() ;
00099                 mFile.seekg( pos,       ios_base::beg );
00100         }
00101         else throw FileNotFoundException(_sFileName,"FileReader::extractNbFileLines()",__FILE__,__LINE__);
00102         return size;
00103 }

void Interpolator::FileReader::extractHeader  ) 
 

Definition at line 124 of file FileReader.cpp.

References _lNbData, _lNbVariables, _sFileName, and extractInt().

Referenced by FileReader().

00125 {
00126         ifstream mFile(_sFileName.c_str());
00127         if (mFile) 
00128         {
00129                 _lNbVariables   = extractInt();
00130                 _lNbData                = extractInt();
00131         }
00132 }

Here is the call graph for this function:

int Interpolator::FileReader::extractInt  ) 
 

Extract a int from the buffer.

Definition at line 170 of file FileReader.cpp.

References extractString().

Referenced by extractHeader().

00171 {
00172         std::string sTemp;
00173         sTemp = extractString();
00174         return atoi(sTemp.c_str());
00175 }

Here is the call graph for this function:

std::string Interpolator::FileReader::extractLine  ) 
 

Return a complete line of the buffer.

Definition at line 153 of file FileReader.cpp.

References _mFileBuffer.

00154 {
00155         std::string sLine;
00156         getline(_mFileBuffer, sLine );
00157         return sLine;
00158 }

long Interpolator::FileReader::extractNbFileLines  ) 
 

Return the number of lines of the file.

Exceptions:
This method throw a FileNotFoundException exception if the file can't be open or read.

Definition at line 137 of file FileReader.cpp.

References _sFileName.

Referenced by FileReader().

00138 {
00139     ifstream mFile(_sFileName.c_str()); 
00140         int iLines = 0;
00141     if ( mFile )
00142     {
00143         iLines = count( istreambuf_iterator<char>( mFile ),
00144                                                 istreambuf_iterator<char>(),
00145                                                 '\n' );
00146     }
00147         else throw FileNotFoundException(_sFileName,"FileReader::extractNbFileLines()",__FILE__,__LINE__);
00148         return iLines+1;
00149 }

std::string Interpolator::FileReader::extractString  ) 
 

Extract a std::string from the buffer.

Definition at line 178 of file FileReader.cpp.

References _mFileBuffer.

Referenced by extractDouble(), extractInt(), Interpolator::SambaFileReader::Parse(), Interpolator::LowEnergyThetaBraggCorrectionReader::Parse(), Interpolator::GenericFileReader2D::Parse(), and Interpolator::GenericFileReader1D::Parse().

00179 {
00180         std::string sTemp;
00181         _mFileBuffer >> sTemp;
00182         return sTemp;
00183 }

long Interpolator::FileReader::getBufferSize  )  const
 

Return the size of the buffer containing the file.

Definition at line 232 of file FileReader.cpp.

References _lBufferSize.

00233 {
00234         return _lBufferSize;
00235 }

long Interpolator::FileReader::getFileSize  )  const
 

Return the file size.

Definition at line 208 of file FileReader.cpp.

References _lFileSize.

00209 {
00210         return _lFileSize;
00211 }

long Interpolator::FileReader::getNbData  )  const
 

Return the number of Data (number of lines of Data) of the file.

Definition at line 220 of file FileReader.cpp.

References _lNbData.

Referenced by Interpolator::GenericFileReader1D::displayAll(), Interpolator::FileWriter::FileWriter(), Interpolator::GenericFileReader1D::getColumn(), Interpolator::GenericFileReader1D::getColumnName(), Interpolator::GenericFileReader1D::getValue(), Interpolator::SambaFileReader::Parse(), Interpolator::LowEnergyThetaBraggCorrectionReader::Parse(), Interpolator::GenericFileReader2D::Parse(), Interpolator::GenericFileReader1D::Parse(), and Interpolator::Table1D::Table1D().

00221 {
00222         return _lNbData;
00223 }

long Interpolator::FileReader::getNbFileLines  )  const
 

Return the number of lines of the file.

Definition at line 214 of file FileReader.cpp.

References _lNbFileLines.

00215 {
00216     return _lNbFileLines;
00217 }

long Interpolator::FileReader::getNbVariables  )  const
 

Return the number of variables (the number of columns) of the file.

Definition at line 226 of file FileReader.cpp.

References _lNbVariables.

Referenced by Interpolator::GenericFileReader1D::displayAll(), Interpolator::FileWriter::FileWriter(), Interpolator::GenericFileReader1D::getValue(), Interpolator::SambaFileReader::Parse(), Interpolator::LowEnergyThetaBraggCorrectionReader::Parse(), Interpolator::GenericFileReader2D::Parse(), and Interpolator::GenericFileReader1D::Parse().

00227 {
00228     return _lNbVariables;
00229 }

bool Interpolator::FileReader::isReadable  ) 
 

This method test if the file can be open and read.

Definition at line 77 of file FileReader.cpp.

References _sFileName.

Referenced by FileReader().

00078 { 
00079 
00080         if (_sFileName.empty()) return false;
00081         else
00082         {
00083                 ifstream mFile( _sFileName.c_str() ); 
00084                 return mFile != 0;
00085         }
00086      
00087 } 

virtual void Interpolator::FileReader::Parse  )  [pure virtual]
 

Implemented in Interpolator::GenericFileReader1D, Interpolator::GenericFileReader2D, Interpolator::LowEnergyThetaBraggCorrectionReader, and Interpolator::SambaFileReader.

void Interpolator::FileReader::setBufferSize long  lBufferSize  ) 
 

Set the size of the buffer containing the file.

Definition at line 238 of file FileReader.cpp.

References _lBufferSize.

Referenced by copyFileToBuffer(), and FileReader().

00239 {
00240         _lBufferSize = lBufferSize;
00241 }

void Interpolator::FileReader::setFileSize long  lFileSize  ) 
 

Set the file size.

Definition at line 250 of file FileReader.cpp.

References _lFileSize.

Referenced by FileReader().

00251 {
00252         _lFileSize = lFileSize;
00253 }

void Interpolator::FileReader::setNbData long  lNbData  ) 
 

Set the number of Data (number of lines of Data).

Definition at line 262 of file FileReader.cpp.

References _lNbData.

00263 {
00264         _lNbData = lNbData;
00265 }

void Interpolator::FileReader::setNbFileLines long  lNbFileLines  ) 
 

Set the number of lines in the file.

Definition at line 256 of file FileReader.cpp.

References _lNbFileLines.

Referenced by FileReader().

00257 {
00258         _lNbFileLines = lNbFileLines;
00259 }

void Interpolator::FileReader::setNbVariables long  lNbVariables  ) 
 

Set the number of variables (the number of columns).

Definition at line 244 of file FileReader.cpp.

References _lNbVariables.

00245 {
00246         _lNbVariables = lNbVariables;
00247 }


Member Data Documentation

long Interpolator::FileReader::_lBufferSize [private]
 

Definition at line 77 of file FileReader.h.

Referenced by getBufferSize(), and setBufferSize().

long Interpolator::FileReader::_lFileSize [private]
 

Definition at line 78 of file FileReader.h.

Referenced by getFileSize(), and setFileSize().

long Interpolator::FileReader::_lNbData [private]
 

Definition at line 73 of file FileReader.h.

Referenced by extractHeader(), getNbData(), and setNbData().

long Interpolator::FileReader::_lNbFileLines [private]
 

Definition at line 79 of file FileReader.h.

Referenced by getNbFileLines(), and setNbFileLines().

long Interpolator::FileReader::_lNbVariables [private]
 

Definition at line 72 of file FileReader.h.

Referenced by extractHeader(), getNbVariables(), and setNbVariables().

std::stringstream Interpolator::FileReader::_mFileBuffer [private]
 

Definition at line 75 of file FileReader.h.

Referenced by copyFileToBuffer(), extractBufferSize(), extractLine(), and extractString().

std::string Interpolator::FileReader::_sFileName [private]
 

Definition at line 70 of file FileReader.h.

Referenced by copyFileToBuffer(), extractFileSize(), extractHeader(), extractNbFileLines(), and isReadable().


The documentation for this class was generated from the following files:
Generated on Tue Apr 14 09:51:10 2009 for Interpolator Library by  doxygen 1.4.5