VoronoiGrowthSimulator
Based on Site Saturated Nucleation and Isotropic Growth
Loading...
Searching...
No Matches
PrintUtils::CSV< T > Class Template Reference

Class for printing data structures as CSV files. More...

#include <PrintUtils.hpp>

Collaboration diagram for PrintUtils::CSV< T >:

Static Public Member Functions

static void TwoDArrayAsTwoD (int rows, int columns, T **M, std::string Filename)
 Prints a two-dimensional array as a two-dimensional CSV file.
 
static void OneDArrayAsOneD (int p, T *M, std::string Filename)
 Prints a one-dimensional array as a one-dimensional CSV file.
 
static void OneDVectorAsOneD (std::vector< T > &M, std::string Filename)
 Prints a one-dimensional vector as a one-dimensional CSV file.
 
static void TwoDVectorAsTwoDVector (std::vector< std::vector< T > > M, std::string Filename)
 Prints a two-dimensional vector as a two-dimensional CSV file.
 
static void OneDVectorOneDVector (std::vector< T > V1, std::vector< T > V2, std::string Filename)
 Prints two one-dimensional vectors as a two-column CSV file.
 

Detailed Description

template<class T>
class PrintUtils::CSV< T >

Class for printing data structures as CSV files.

Template Parameters
TThe type of data in the data structures.

Definition at line 100 of file PrintUtils.hpp.

Member Function Documentation

◆ OneDArrayAsOneD()

template<class T >
void PrintUtils::CSV< T >::OneDArrayAsOneD ( int p,
T * M,
std::string Filename )
inlinestatic

Prints a one-dimensional array as a one-dimensional CSV file.

Parameters
pThe size of the array.
MThe one-dimensional array.
FilenameThe name of the output CSV file.

Writes the elements of a one-dimensional array to a CSV file.

Template Parameters
TThe type of the elements in the array.
Parameters
pThe number of elements in the array.
MPointer to the array.
FilenameThe name of the output CSV file.

Definition at line 181 of file PrintUtils.hpp.

182{
183 Filename = Filename + ".csv";
184 std::ofstream outdata;
185 outdata.open(Filename);
186
187 for (size_t i = 0; i < p - 1; i++)
188 {
189 outdata << M[i] << std::endl;
190 }
191 outdata << M[p - 1];
192}

◆ OneDVectorAsOneD()

template<class T >
void PrintUtils::CSV< T >::OneDVectorAsOneD ( std::vector< T > & M,
std::string Filename )
inlinestatic

Prints a one-dimensional vector as a one-dimensional CSV file.

Parameters
MThe one-dimensional vector.
FilenameThe name of the output CSV file.

Writes the elements of a one-dimensional vector to a CSV file. Each element is written on a separate line in the file.

Template Parameters
TThe type of elements in the vector.
Parameters
MThe one-dimensional vector to be written to the file.
FilenameThe name of the CSV file to be created.

Definition at line 203 of file PrintUtils.hpp.

204{
205 Filename = Filename + ".csv";
206 std::ofstream outdata;
207 outdata.open(Filename);
208 int p = M.size();
209 for (size_t i = 0; i < p - 1; i++)
210 {
211 outdata << M[i] << std::endl;
212 }
213 outdata << M[p - 1];
214}

◆ OneDVectorOneDVector()

template<class T >
void PrintUtils::CSV< T >::OneDVectorOneDVector ( std::vector< T > V1,
std::vector< T > V2,
std::string Filename )
inlinestatic

Prints two one-dimensional vectors as a two-column CSV file.

Parameters
V1The first one-dimensional vector.
V2The second one-dimensional vector.
FilenameThe name of the output CSV file.

Writes two one-dimensional vectors to a CSV file.

Template Parameters
TThe type of elements in the vectors.
Parameters
V1The first vector.
V2The second vector.
FilenameThe name of the output CSV file.

Definition at line 225 of file PrintUtils.hpp.

226{
227 Filename = Filename + ".csv";
228 std::ofstream outdata;
229 outdata.open(Filename);
230 int p = V1.size();
231 for (size_t i = 0; i < p - 1; i++)
232 {
233 outdata << V1[i] << "," << V2[i] << std::endl;
234 }
235 outdata << V1[p - 1] << "," << V2[p - 1];
236}

◆ TwoDArrayAsTwoD()

template<class T >
void PrintUtils::CSV< T >::TwoDArrayAsTwoD ( int rows,
int columns,
T ** M,
std::string Filename )
static

Prints a two-dimensional array as a two-dimensional CSV file.

Parameters
rowsThe number of rows in the array.
columnsThe number of columns in the array.
MThe two-dimensional array.
FilenameThe name of the output CSV file.

Writes a two-dimensional array to a CSV file.

Template Parameters
TThe type of elements in the array.
Parameters
rowsThe number of rows in the array.
columnsThe number of columns in the array.
MThe two-dimensional array to be written.
FilenameThe name of the output CSV file.

Definition at line 156 of file PrintUtils.hpp.

157{
158 Filename = Filename + ".csv";
159 std::ofstream outdata;
160 outdata.open(Filename);
161
162 for (size_t i = 0; i < rows; i++)
163 {
164 for (size_t j = 0; j < columns - 1; j++)
165 {
166 outdata << M[i][j] << ",";
167 }
168 outdata << M[i][columns - 1] << std::endl;
169 }
170}

◆ TwoDVectorAsTwoDVector()

template<class T >
void PrintUtils::CSV< T >::TwoDVectorAsTwoDVector ( std::vector< std::vector< T > > M,
std::string Filename )
inlinestatic

Prints a two-dimensional vector as a two-dimensional CSV file.

Parameters
MThe two-dimensional vector.
FilenameThe name of the output CSV file.

Writes a two-dimensional vector to a CSV file.

Template Parameters
TThe type of elements in the vector.
Parameters
MThe two-dimensional vector to be written.
FilenameThe name of the output CSV file.

Definition at line 246 of file PrintUtils.hpp.

247{
248 Filename = Filename + ".csv";
249 std::ofstream outdata;
250 outdata.open(Filename);
251 int rows = M.size();
252 int columns = M[0].size();
253
254 for (size_t i = 0; i < rows; i++)
255 {
256 for (size_t j = 0; j < columns - 1; j++)
257 {
258 outdata << M[i][j] << ",";
259 }
260 outdata << M[i][columns - 1] << std::endl;
261 }
262}
Here is the caller graph for this function:

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