Interpolator::GenericFileReader1D Class Reference

This class is a generic file reader for file with data sorted by columns. More...

#include <GenericFileReader1D.h>

Inherits Interpolator::FileReader.

Inheritance diagram for Interpolator::GenericFileReader1D:

Inheritance graph
[legend]
Collaboration diagram for Interpolator::GenericFileReader1D:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GenericFileReader1D ()
 Default constructor.
virtual ~GenericFileReader1D ()
 Destructor.
 GenericFileReader1D (const std::string &sFileName)
 This constructor requires 1 parameter :
  • the name of the file to read (the file must provide a header giving the number of variables and number of lines).

 GenericFileReader1D (const std::string &sFileName, long lNbColumns, long lNbLines)
 This constructor requires 3 parameters :
  • the name of the file to read
  • the number of columns of the file
  • the number of lines of the file (without the first line which contains the name of the data).

virtual void Parse ()
 This method parse the buffer to read a generic file
.
double * getColumn (int iColumnNumber) const
 Return the iColumnNumber column data
Exceptions:
This method throw a IndexOutOfBoundException exception if the iColumnNumber is outside the bound
This method throw a NullPointerException exception if the data vector is null.

double getValue (int iColumnNumber, int iLineNumber) const
 Return the value of iLineNumber line and iColumnNumber column
Exceptions:
This method throw a IndexOutOfBoundException exception if the iColumnNumber or the iLineNumber are outside the bound
This method throw a NullPointerException exception if the data vector is null.

std::string getColumnName (int iColumnNumber) const
 Return the iColumnNumber column data name
Exceptions:
This method throw a IndexOutOfBoundException exception if the iColumnNumber is outside the bound
This method throw a NullPointerException exception if the name vector is null.

void displayAll ()
 Display the data
Used for debug.

Private Attributes

vector< double * > * _mColumnsVector
vector< std::string > * _mColumnsNameVector

Detailed Description

This class is a generic file reader for file with data sorted by columns.

Definition at line 23 of file GenericFileReader1D.h.


Constructor & Destructor Documentation

Interpolator::GenericFileReader1D::GenericFileReader1D  ) 
 

Default constructor.

Definition at line 16 of file GenericFileReader1D.cpp.

References _mColumnsNameVector, and _mColumnsVector.

00017 {
00018         _mColumnsVector         = new vector< double* >();
00019         _mColumnsNameVector = new vector< std::string >();
00020 }

Interpolator::GenericFileReader1D::~GenericFileReader1D  )  [virtual]
 

Destructor.

Definition at line 23 of file GenericFileReader1D.cpp.

References _mColumnsVector, and getColumn().

00024 {
00025   for (int i=0;i< (signed)_mColumnsVector->size();i++) 
00026         {
00027                 double * pColumn = getColumn(i);
00028                 if (pColumn) 
00029                 {
00030                         delete [] pColumn;
00031                         pColumn = 0;
00032                 }
00033         }
00034 
00035         DESTRUCTION (_mColumnsVector);  
00036         DESTRUCTION (_mColumnsNameVector);
00037 }

Here is the call graph for this function:

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

This constructor requires 1 parameter :

  • the name of the file to read (the file must provide a header giving the number of variables and number of lines).

Definition at line 41 of file GenericFileReader1D.cpp.

References _mColumnsNameVector, _mColumnsVector, and Parse().

00041                                                                    : FileReader(sFileName) 
00042 {
00043         _mColumnsVector = new vector< double* >();
00044         _mColumnsNameVector = new vector< std::string >();
00045         Parse();
00046 }

Here is the call graph for this function:

Interpolator::GenericFileReader1D::GenericFileReader1D const std::string &  sFileName,
long  lNbColumns,
long  lNbLines
 

This constructor requires 3 parameters :

  • the name of the file to read
  • the number of columns of the file
  • the number of lines of the file (without the first line which contains the name of the data).

Definition at line 52 of file GenericFileReader1D.cpp.

References _mColumnsNameVector, _mColumnsVector, and Parse().

00052                                                                                                  : FileReader(sFileName,lNbColumns,lNbLines)
00053 {
00054         _mColumnsVector = new vector< double* >();
00055         _mColumnsNameVector = new vector< std::string >();
00056         Parse();
00057 }

Here is the call graph for this function:


Member Function Documentation

void Interpolator::GenericFileReader1D::displayAll  ) 
 

Display the data
Used for debug.

Definition at line 153 of file GenericFileReader1D.cpp.

References _mColumnsNameVector, Interpolator::Interpolator::_verb, Interpolator::FileReader::getNbData(), Interpolator::FileReader::getNbVariables(), and getValue().

Referenced by Parse().

00154 {
00155         for (int i=0;i<getNbVariables();i++)
00156         {
00157                 if(Interpolator::_verb == true) cout << "Column : " << i << " --> " << (*_mColumnsNameVector)[i] << endl;               
00158         }
00159 
00160         for (int j=0;j<getNbData();j++)
00161         {
00162                 if(Interpolator::_verb == true) cout    << "[" << j << "=\t";
00163                 for (int i=0;i<getNbVariables();i++)
00164                 {
00165                         if(Interpolator::_verb == true) cout << getValue(i,j) << "\t";          
00166                 }
00167                 if(Interpolator::_verb == true) cout << "]" << endl;
00168         }
00169 }

Here is the call graph for this function:

double * Interpolator::GenericFileReader1D::getColumn int  iColumnNumber  )  const
 

Return the iColumnNumber column data

Exceptions:
This method throw a IndexOutOfBoundException exception if the iColumnNumber is outside the bound
This method throw a NullPointerException exception if the data vector is null.

Definition at line 106 of file GenericFileReader1D.cpp.

References _mColumnsVector, and Interpolator::FileReader::getNbData().

Referenced by Interpolator::Table1D::Table1D(), and ~GenericFileReader1D().

00107 {
00108   if ((iColumnNumber < 0) || (iColumnNumber >= (int)_mColumnsVector->size())) throw IndexOutOfBoundException("iColumnNumber",iColumnNumber,0,getNbData(),"GenericFileReader1D::getColumn(int iColumnNumber)",__FILE__,__LINE__); 
00109 
00110         if (_mColumnsVector == 0) throw NullPointerException("_mColumnsVector","GenericFileReader1D::getColumn(int iColumnNumber)",__FILE__,__LINE__);
00111         return ((*_mColumnsVector)[iColumnNumber]);
00112 }

Here is the call graph for this function:

std::string Interpolator::GenericFileReader1D::getColumnName int  iColumnNumber  )  const
 

Return the iColumnNumber column data name

Exceptions:
This method throw a IndexOutOfBoundException exception if the iColumnNumber is outside the bound
This method throw a NullPointerException exception if the name vector is null.

Definition at line 117 of file GenericFileReader1D.cpp.

References _mColumnsNameVector, and Interpolator::FileReader::getNbData().

Referenced by Interpolator::FileWriter::FileWriter(), and Interpolator::Table1D::Table1D().

00118 {
00119   if ((iColumnNumber < 0) || (iColumnNumber >= (int)_mColumnsNameVector->size())) throw IndexOutOfBoundException("iColumnNumber",iColumnNumber,0,getNbData(),"GenericFileReader1D::getColumnName(int iColumnNumber)",__FILE__,__LINE__); 
00120 
00121         if (_mColumnsNameVector == 0) throw NullPointerException("_mColumnsNameVector","GenericFileReader1D::getColumnName(int iColumnNumber)",__FILE__,__LINE__);
00122         return ((*_mColumnsNameVector)[iColumnNumber]);
00123 }

Here is the call graph for this function:

double Interpolator::GenericFileReader1D::getValue int  iColumnNumber,
int  iLineNumber
const
 

Return the value of iLineNumber line and iColumnNumber column

Exceptions:
This method throw a IndexOutOfBoundException exception if the iColumnNumber or the iLineNumber are outside the bound
This method throw a NullPointerException exception if the data vector is null.

Definition at line 128 of file GenericFileReader1D.cpp.

References _mColumnsVector, Interpolator::FileReader::getNbData(), and Interpolator::FileReader::getNbVariables().

Referenced by displayAll(), and Interpolator::FileWriter::FileWriter().

00129 {
00130         if ((iColumnNumber < 0) || (iColumnNumber >= (int)_mColumnsVector->size())) throw IndexOutOfBoundException("iColumnNumber",iColumnNumber,0,getNbVariables(),"GenericFileReader1D::getValue(int iColumnNumber,int jLineNumber)",__FILE__,__LINE__); 
00131         if ((iLineNumber < 0) || (iLineNumber >= getNbData())) throw IndexOutOfBoundException("iLineNumber",iLineNumber,0,getNbData(),"GenericFileReader1D::getValue(int iColumnNumber,int jLineNumber)",__FILE__,__LINE__); 
00132         
00133         if (_mColumnsVector == 0) throw NullPointerException("_mColumnsVector","GenericFileReader1D::getValue(int iColumnNumber,int jLineNumber)",__FILE__,__LINE__);
00134         
00135         return ((*_mColumnsVector)[iColumnNumber])[iLineNumber];
00136 }

Here is the call graph for this function:

void Interpolator::GenericFileReader1D::Parse  )  [virtual]
 

This method parse the buffer to read a generic file
.

Implements Interpolator::FileReader.

Definition at line 61 of file GenericFileReader1D.cpp.

References _mColumnsNameVector, _mColumnsVector, Interpolator::Interpolator::_verb, displayAll(), Interpolator::FileReader::extractDouble(), Interpolator::FileReader::extractString(), Interpolator::FileReader::getNbData(), and Interpolator::FileReader::getNbVariables().

Referenced by GenericFileReader1D().

00062 {
00063 
00064 int iNbData = getNbData();
00065 if(Interpolator::_verb == true) cout << "NbData : " << iNbData << endl;
00066 
00067 int iNbVariables = getNbVariables();
00068 if(Interpolator::_verb == true) cout << "NbVariables : " << iNbVariables << endl;
00069 
00070 //Reading of the first line to extract the variables names
00071 std::string sColumnName;
00072 
00073 int i=0;
00074 
00075 for (i=0;i<iNbVariables;i++) 
00076 {
00077         sColumnName = extractString();
00078         _mColumnsNameVector->push_back(sColumnName);
00079         if(Interpolator::_verb == true) cout << "Column " << i << " --> " <<    (*_mColumnsNameVector)[i] << endl;
00080 
00081         _mColumnsVector->push_back(new double[iNbData]);
00082 
00083 }
00084 
00085 double dValue;
00086 
00087 for (i=0;i<iNbData;i++) 
00088 {
00089         for (int j=0;j<iNbVariables;j++) 
00090         {
00091                 dValue = extractDouble();
00092                         
00093                 ((*_mColumnsVector)[j])[i] = dValue;
00094 
00095         }
00096         
00097 }
00098 displayAll();
00099 
00100 }

Here is the call graph for this function:


Member Data Documentation

vector<std::string>* Interpolator::GenericFileReader1D::_mColumnsNameVector [private]
 

Definition at line 42 of file GenericFileReader1D.h.

Referenced by displayAll(), GenericFileReader1D(), getColumnName(), and Parse().

vector<double*>* Interpolator::GenericFileReader1D::_mColumnsVector [private]
 

Definition at line 41 of file GenericFileReader1D.h.

Referenced by GenericFileReader1D(), getColumn(), getValue(), Parse(), and ~GenericFileReader1D().


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