STK++ 0.9.13
STK::ExportToCsv Class Reference

Export data to a Csv. More...

#include <STK_ExportToCsv.h>

Public Member Functions

 ExportToCsv ()
 Default constructor.
 
 ExportToCsv (DataFrame const &df)
 Constructor : create an instance of ExportToCvs with a DataFrame.
 
template<class Type >
 ExportToCsv (TReadWriteCsv< Type > const &rw)
 Constructor : create an instance of ExportToCvs with a ReadWriteCsv.
 
template<class Container >
 ExportToCsv (ITContainer1D< Container > const &A, bool byCol=true, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Instantiates an instance of ExportToCvs with an Array1D, a list1D, etc....
 
template<class Container >
 ExportToCsv (ITContainer< Container, Arrays::vector_ > const &A, bool byCol=true, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Instantiates an instance of ExportToCvs with a vector.
 
template<class Container >
 ExportToCsv (ITContainer< Container, Arrays::point_ > const &A, bool byCol=false, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Instantiates an instance of ExportToCvs with a point.
 
template<class Container >
 ExportToCsv (ITContainer< Container > const &A, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Instantiates an instance of ExportToCvs with a general array.
 
 ~ExportToCsv ()
 destructor.
 
template<class Container >
void append (ITContainer< Container, Arrays::vector_ > const &A, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Append a vector.
 
template<class Container >
void append (ITContainer< Container, Arrays::point_ > const &A, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Append a point (as a column vector).
 
template<class Container >
void append (ITContainer< Container, Arrays::array2D_ > const &A, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Append a 2D container.
 
template<class Container >
void append (ITContainer< Container, Arrays::square_ > const &A, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Append a 2D container.
 
template<class TYPE >
void appendData (TYPE const &A, String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Append a value.
 
void setColumnsNames (String const &prefix=Csv::DEFAULT_COLUMN_PREFIX)
 Set a name to each column of the ReadWriteCsv using the form prefix + number.
 
ReadWriteCsv *const p_readWriteCsv () const
 Accesor.
 
void release ()
 release the ReadWriteCsv.
 

Protected Attributes

ReadWriteCsvp_data_
 ptr on the ReadWriteCsv containing the data.
 

Detailed Description

Export data to a Csv.

An ExportToCsv object creates a ReadWriteCsv from a container of data like a DataFrame, a Vector, a point or a ArrayXX. The data are stored in a String format in the ReadWriteCsv struct.

Definition at line 62 of file STK_ExportToCsv.h.

Constructor & Destructor Documentation

◆ ExportToCsv() [1/7]

STK::ExportToCsv::ExportToCsv ( )
inline

Default constructor.

Create an instance of ExportToCvs.

Definition at line 66 of file STK_ExportToCsv.h.

66: p_data_(new ReadWriteCsv()) {}
ReadWriteCsv * p_data_
ptr on the ReadWriteCsv containing the data.
class TReadWriteCsv< String > ReadWriteCsv

◆ ExportToCsv() [2/7]

STK::ExportToCsv::ExportToCsv ( DataFrame const df)
inline

Constructor : create an instance of ExportToCvs with a DataFrame.

Parameters
dfthe DataFrame to export

Definition at line 70 of file STK_ExportToCsv.h.

70 : p_data_(new ReadWriteCsv())
71 {
72 p_data_->setReserve(df.sizeRows());
73 p_data_->resize(df.sizeRows(), df.sizeCols());
74 // for each field Try a String conversion
75 for(int iVar = df.beginCols(), irw = p_data_->begin(); iVar<df.endCols(); iVar++, irw++)
76 { if (df.elt(iVar)) df.elt(iVar)->exportAsString(p_data_->var(irw));}
77 }

References STK::DataFrame::beginCols(), STK::DataFrame::elt(), STK::DataFrame::endCols(), STK::IVariable::exportAsString(), p_data_, STK::DataFrame::sizeCols(), and STK::DataFrame::sizeRows().

◆ ExportToCsv() [3/7]

template<class Type >
STK::ExportToCsv::ExportToCsv ( TReadWriteCsv< Type > const rw)
inline

Constructor : create an instance of ExportToCvs with a ReadWriteCsv.

Parameters
rwthe TReadWriteCsv to export

Definition at line 82 of file STK_ExportToCsv.h.

82 : p_data_(new ReadWriteCsv())
83 {
84 p_data_->setReserve(rw.sizeRows());
85 p_data_->resize(rw.sizeRows(), rw.sizeCols());
86 p_data_->setWithNames(rw.withNames());
87 // for each field Try a String conversion
88 for(int iRw = rw.beginCols(), iData = p_data_->begin(); iRw<rw.endCols(); iRw++, iData++)
89 { rw.var(iRw).exportAsString(p_data_->var(iData));}
90 }

References p_data_.

◆ ExportToCsv() [4/7]

template<class Container >
STK::ExportToCsv::ExportToCsv ( ITContainer1D< Container > const A,
bool  byCol = true,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Instantiates an instance of ExportToCvs with an Array1D, a list1D, etc....

Parameters
Athe 1D container to export
byColexport the container as a column vector or a row vector ?
prefixthe prefix of the name to set to the variable

Definition at line 98 of file STK_ExportToCsv.h.

101 : p_data_(new ReadWriteCsv())
102 {
103#ifdef STK_DMANAGER_DEBUG
104 stk_cout << "Entering ExportToCsv( ITContainer1D<Container> const& A, byCol, prefix)\n";
105 stk_cout << "A.range()= " << A.range() << "\n";
106#endif
107 // add an empty string variable (an empty column)
108 p_data_->setWithNames(true);
109 if (byCol)
110 { // add to ReadWriteCsv a new variable
111 //p_data_->
112 p_data_->push_back(Variable<String>(A.range(), prefix));
113
114 for(int i = A.begin(); i<A.end(); i++)
115 { p_data_->back()[i] = typeToString(A.at(i));}
116 }
117 else // by row
118 {
119 for(int i = A.begin(); i<A.end(); i++)
120 { p_data_->push_back( Variable<String>(1, typeToString(A.at(i)), prefix+typeToString(i)) );}
121 }
122 }
#define stk_cout
Standard stk output stream.
String typeToString(Type const &t, std::ios_base &(*f)(std::ios_base &)=std::dec)
convert a Type to String
Definition STK_String.h:235

References p_data_, stk_cout, and STK::typeToString().

◆ ExportToCsv() [5/7]

template<class Container >
STK::ExportToCsv::ExportToCsv ( ITContainer< Container, Arrays::vector_ > const A,
bool  byCol = true,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Instantiates an instance of ExportToCvs with a vector.

Parameters
Athe ITContainer to export
byColexport the container as a column vector or a raw vector ?
prefixthe prefix of the name to set to the variable

Definition at line 130 of file STK_ExportToCsv.h.

133 : p_data_(new ReadWriteCsv())
134 {
135 // add an empty string variable (an empty column)
136 p_data_->setWithNames(true);
137 if (byCol)
138 {
139 p_data_->push_back(Variable<String>(A.range(), prefix));
140
141 for(int i = A.begin(); i<A.end(); i++)
142 { p_data_->back()[i] = typeToString(A.at(i));}
143 }
144 else
145 {
146 for(int i = A.begin(); i<A.end(); i++)
147 {
148 p_data_->push_back(Variable<String>(1, prefix+typeToString(i)));
149 p_data_->back().front() = typeToString(A.at(i));
150 }
151 }
152 }

References p_data_, and STK::typeToString().

◆ ExportToCsv() [6/7]

template<class Container >
STK::ExportToCsv::ExportToCsv ( ITContainer< Container, Arrays::point_ > const A,
bool  byCol = false,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Instantiates an instance of ExportToCvs with a point.

Parameters
Athe ITContainer1D to export
byColexport the container as a column vector or a raw vector ?
prefixthe prefix ot the name to set to the variable

Definition at line 159 of file STK_ExportToCsv.h.

162 : p_data_(new ReadWriteCsv())
163 {
164 // add an empty string variable (an empty column)
165 p_data_->setWithNames(true);
166 if (byCol)
167 {
168 p_data_->push_back(Variable<String>(A.range(), prefix));
169
170 for(int i = A.begin(); i<A.end(); i++)
171 { p_data_->back()[i] = typeToString(A.at(i));}
172 }
173 else
174 {
175 for(int i = A.begin(); i<A.end(); i++)
176 {
177 p_data_->push_back(Variable<String>(1, prefix+typeToString(i)));
178 p_data_->back().front() = typeToString(A.at(i));
179 }
180 }
181 }

References p_data_, and STK::typeToString().

◆ ExportToCsv() [7/7]

template<class Container >
STK::ExportToCsv::ExportToCsv ( ITContainer< Container > const A,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Instantiates an instance of ExportToCvs with a general array.

Parameters
Athe IArray2d to export
prefixthe prefix ot the name to set to the variable

Definition at line 187 of file STK_ExportToCsv.h.

189 : p_data_(new ReadWriteCsv())
190 {
191 p_data_->setWithNames(true);
192 for(int iVar = A.beginCols(); iVar<A.endCols(); iVar++)
193 {
194 // add an empty string variable (an empty column)
195 p_data_->push_back(Variable<String>(A.rows(), prefix));
196 for (int iRow=A.beginRows(); iRow<A.endRows(); iRow++)
197 { p_data_->back()[iRow] = typeToString(A.at(iRow,iVar));}
198 }
199 }

References p_data_, and STK::typeToString().

◆ ~ExportToCsv()

STK::ExportToCsv::~ExportToCsv ( )
inline

destructor.

The protected field p_data_ will be liberated.

Definition at line 204 of file STK_ExportToCsv.h.

204{ if (p_data_) delete p_data_;}

References p_data_.

Member Function Documentation

◆ append() [1/4]

template<class Container >
void STK::ExportToCsv::append ( ITContainer< Container, Arrays::array2D_ > const A,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Append a 2D container.

Parameters
Athe container to export
prefixthe prefix ot the name to set to the variable

Definition at line 236 of file STK_ExportToCsv.h.

237 {
238 // for each field try a String conversion
239 for(int iVar = A.beginCols(), iNum=1; iVar<A.endCols(); iVar++, iNum++)
240 {
241 // add an empty string variable (an empty column)
242 p_data_->push_back(Variable<String>(A.rows(), prefix+typeToString(iNum)));
243 for (int iRow=A.beginRows(); iRow<A.endRows(); iRow++)
244 { p_data_->back()[iRow] = typeToString(A.elt(iRow,iVar));}
245 }
246 }

References p_data_, and STK::typeToString().

◆ append() [2/4]

template<class Container >
void STK::ExportToCsv::append ( ITContainer< Container, Arrays::point_ > const A,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Append a point (as a column vector).

Parameters
Athe container to export
prefixthe prefix ot the name to set to the variable

Definition at line 223 of file STK_ExportToCsv.h.

224 {
225 // add an empty string variable
226 p_data_->push_back(Variable<String>(A.range(), prefix));
227 // add strings to the String variable
228 for(int i = A.begin(); i< A.end(); i++)
229 { p_data_->back()[i] = typeToString(A.elt(i));}
230 }

References p_data_, and STK::typeToString().

◆ append() [3/4]

template<class Container >
void STK::ExportToCsv::append ( ITContainer< Container, Arrays::square_ > const A,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Append a 2D container.

Parameters
Athe container to export
prefixthe prefix ot the name to set to the variable

Definition at line 252 of file STK_ExportToCsv.h.

253 {
254 // for each field try a String conversion
255 for(int iVar = A.beginCols(), iNum=1; iVar<A.endCols(); iVar++, iNum++)
256 {
257 // add an empty string variable (an empty column)
258 p_data_->push_back(Variable<String>(A.rows(), prefix+typeToString(iNum)));
259 for (int iRow=A.beginRows(); iRow<A.endRows(); iRow++)
260 { p_data_->back()[iRow] = typeToString(A.elt(iRow,iVar));}
261 }
262 }

References p_data_, and STK::typeToString().

◆ append() [4/4]

template<class Container >
void STK::ExportToCsv::append ( ITContainer< Container, Arrays::vector_ > const A,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Append a vector.

Parameters
Athe container to export
prefixthe prefix ot the name to set to the variable

Definition at line 210 of file STK_ExportToCsv.h.

211 {
212 // add an empty string variable
213 p_data_->push_back(Variable<String>(A.range(), prefix));
214 // add strings to the String variable
215 for(int i = A.begin(); i< A.end(); i++)
216 { p_data_->back()[i] = typeToString(A.elt(i));}
217 }

References p_data_, and STK::typeToString().

◆ appendData()

template<class TYPE >
void STK::ExportToCsv::appendData ( TYPE const A,
String const prefix = Csv::DEFAULT_COLUMN_PREFIX 
)
inline

Append a value.

Parameters
Athe value to export
prefixthe prefix ot the name to set to the variable

Definition at line 268 of file STK_ExportToCsv.h.

269 {
270 // add an empty string variable
271 p_data_->push_back(Variable<String>( prefix + typeToString(p_data_->lastIdx())) );
272 // add strings to the String variable
273 p_data_->back().push_back(typeToString(A));
274 }

References p_data_, and STK::typeToString().

◆ p_readWriteCsv()

ReadWriteCsv *const STK::ExportToCsv::p_readWriteCsv ( ) const
inline

Accesor.

Return a ptr on the the ReadWriteCsv.

Definition at line 286 of file STK_ExportToCsv.h.

286{ return p_data_;}

References p_data_.

◆ release()

void STK::ExportToCsv::release ( )
inline

release the ReadWriteCsv.

It will be freed by the user.

Definition at line 288 of file STK_ExportToCsv.h.

288{ p_data_ =0;}

References p_data_.

◆ setColumnsNames()

void STK::ExportToCsv::setColumnsNames ( String const prefix = Csv::DEFAULT_COLUMN_PREFIX)
inline

Set a name to each column of the ReadWriteCsv using the form prefix + number.

Parameters
prefixthe prefix to use for the names of the columns

Definition at line 279 of file STK_ExportToCsv.h.

280 {
281 for(int i = p_data_->begin(); i<p_data_->end(); i++)
282 { p_data_->setName(i, prefix + typeToString(i)) ;}
283 }

References p_data_, and STK::typeToString().

Member Data Documentation

◆ p_data_

ReadWriteCsv* STK::ExportToCsv::p_data_
protected

The documentation for this class was generated from the following file: