|
STK++ 1.0
|
Export data to a Csv stream. More...
#include <STK_ExportToCsv.h>
Public Member Functions | |
| ExportToCsv (const DataFrame &df) | |
| Constructor : create an instance of ExportToCvs with a DataFrame. | |
| template<class TYPE , class TContainer2D > | |
| ExportToCsv (const IArray2D< TYPE, TContainer2D > &A) | |
| Instantiates an instance of ExportToCvs with a IArray2D. | |
| template<class TYPE , class TContainer1D > | |
| ExportToCsv (const ITContainer1D< TYPE, TContainer1D > &A) | |
| Instantiates an instance of ExportToCvs with a ITContainer1D. | |
| void | setColumnsNames (String const &prefix=Csv::DEFAULT_COLUMN_PREFIX) |
| Set a name to each column of the ReadWriteCsv using the form prefix + number. | |
| virtual | ~ExportToCsv () |
| destructor. | |
| ReadWriteCsv *const | p_readWriteCsv () const |
| Accesor. | |
| void | release () |
| release the ReadWriteCsv. | |
Protected Attributes | |
| ReadWriteCsv * | p_data_ |
| ptr on the ReadWriteCsv containing the data. | |
| bool | isColNamed_ |
true if the columns have a name. | |
Export data to a Csv stream.
A ExportToCsv object create a ReadWriteCsv from a container of data like a DataFrame, a Vector or a Matrix. The data are stored in a String format in the ReadWriteCsv struct.
Definition at line 67 of file STK_ExportToCsv.h.
| STK::ExportToCsv::ExportToCsv | ( | const DataFrame & | df | ) |
Constructor : create an instance of ExportToCvs with a DataFrame.
| df | the DataFrame to export |
Definition at line 41 of file STK_ExportToCsv.cpp.
References STK::ReadWriteCsv::back(), STK::DataFrame::elt(), STK::IVariable::exportString(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), p_data_, and STK::ReadWriteCsv::push_back().
: p_data_(0) , isColNamed_(true) { // create an empty ReadWriteCsv p_data_ = new ReadWriteCsv(); // for each field Try a String conversion for(Integer iVar = df.firstCol(); iVar<=df.lastCol(); iVar++) { // add an empty string variable p_data_->push_back(); // use virtual method exportString() for getting Strings into Csv if (df.elt(iVar)) df.elt(iVar)->exportString(p_data_->back()); } }
| STK::ExportToCsv::ExportToCsv | ( | const IArray2D< TYPE, TContainer2D > & | A | ) | [inline] |
Instantiates an instance of ExportToCvs with a IArray2D.
| A | the IArray2d to export |
Definition at line 79 of file STK_ExportToCsv.h.
References STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::at(), STK::ReadWriteCsv::back(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), STK::IContainer2D::lastRow(), p_data_, STK::ITContainer1D< TYPE, TContainer1D >::push_back(), and STK::ReadWriteCsv::push_back().
: p_data_(0) , isColNamed_(false) { // create an empty ReadWriteCsv with no name p_data_ = new ReadWriteCsv(false); // for each field try a String conversion const Integer firstRow = A.firstRow(), lastRow = A.lastRow(); const Integer firstCol = A.firstCol(), lastCol = A.lastCol(); for(Integer iVar = firstCol; iVar<=lastCol; iVar++) { // add an empty string variable (an empty column) p_data_->push_back(); for (Integer irow=firstRow; irow<=lastRow; irow++) { p_data_->back().push_back(typeToString<TYPE>(A.at(irow,iVar))); } } }
| STK::ExportToCsv::ExportToCsv | ( | const ITContainer1D< TYPE, TContainer1D > & | A | ) | [inline] |
Instantiates an instance of ExportToCvs with a ITContainer1D.
| A | the ITContainer1D to export |
Definition at line 104 of file STK_ExportToCsv.h.
References STK::ITContainer1D< TYPE, TContainer1D >::at(), STK::ReadWriteCsv::back(), STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), p_data_, STK::ITContainer1D< TYPE, TContainer1D >::push_back(), and STK::ReadWriteCsv::push_back().
: p_data_(0) , isColNamed_(false) { // create an empty ReadWriteCsv with no variable name p_data_ = new ReadWriteCsv(false); // for each field Try a String conversion const Integer first = A.first(), last = A.last(); // add an empty string variable p_data_->push_back(); // add strings to the String variable for(Integer i = first; i<=last; i++) { p_data_->back().push_back(typeToString<TYPE>(A.at(i))); } }
| STK::ExportToCsv::~ExportToCsv | ( | ) | [virtual] |
destructor.
The protected field p_data_ will be liberated.
Definition at line 58 of file STK_ExportToCsv.cpp.
References p_data_.
| void STK::ExportToCsv::setColumnsNames | ( | String const & | prefix = Csv::DEFAULT_COLUMN_PREFIX | ) |
Set a name to each column of the ReadWriteCsv using the form prefix + number.
| prefix | the prefix to use for the names of the columns |
Definition at line 65 of file STK_ExportToCsv.cpp.
References STK::ReadWriteCsv::first(), isColNamed_, STK::ReadWriteCsv::last(), p_data_, STK::ReadWriteCsv::setName(), and STK::typeToString().
{
// get first and last column indexes
const Integer first = p_data_->first(), last = p_data_->last();
// set names of the variables
for(Integer i = first; i<=last; i++)
{
p_data_->setName(i, prefix + typeToString(i)) ;
}
isColNamed_ = true;
}
| ReadWriteCsv* const STK::ExportToCsv::p_readWriteCsv | ( | ) | const [inline] |
Accesor.
Return a ptr on the the ReadWriteCsv.
Definition at line 135 of file STK_ExportToCsv.h.
References p_data_.
Referenced by STK::out2D(), and STK::DataFrame::writeDataFrame().
{ return p_data_;}
| void STK::ExportToCsv::release | ( | ) | [inline] |
release the ReadWriteCsv.
It will be freed by the user.
Definition at line 139 of file STK_ExportToCsv.h.
References p_data_.
{ p_data_ =0;}
ReadWriteCsv* STK::ExportToCsv::p_data_ [protected] |
ptr on the ReadWriteCsv containing the data.
Definition at line 143 of file STK_ExportToCsv.h.
Referenced by ExportToCsv(), p_readWriteCsv(), release(), setColumnsNames(), and ~ExportToCsv().
bool STK::ExportToCsv::isColNamed_ [protected] |
true if the columns have a name.
false otherwise
Definition at line 145 of file STK_ExportToCsv.h.
Referenced by setColumnsNames().