Class for printing data structures as CSV files.
More...
#include <PrintUtils.hpp>
|
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.
|
|
template<class T>
class PrintUtils::CSV< T >
Class for printing data structures as CSV files.
- Template Parameters
-
T | The type of data in the data structures. |
Definition at line 100 of file PrintUtils.hpp.
◆ 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
-
p | The size of the array. |
M | The one-dimensional array. |
Filename | The name of the output CSV file. |
Writes the elements of a one-dimensional array to a CSV file.
- Template Parameters
-
T | The type of the elements in the array. |
- Parameters
-
p | The number of elements in the array. |
M | Pointer to the array. |
Filename | The 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
-
M | The one-dimensional vector. |
Filename | The 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
-
T | The type of elements in the vector. |
- Parameters
-
M | The one-dimensional vector to be written to the file. |
Filename | The 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
-
V1 | The first one-dimensional vector. |
V2 | The second one-dimensional vector. |
Filename | The name of the output CSV file. |
Writes two one-dimensional vectors to a CSV file.
- Template Parameters
-
T | The type of elements in the vectors. |
- Parameters
-
V1 | The first vector. |
V2 | The second vector. |
Filename | The 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
-
rows | The number of rows in the array. |
columns | The number of columns in the array. |
M | The two-dimensional array. |
Filename | The name of the output CSV file. |
Writes a two-dimensional array to a CSV file.
- Template Parameters
-
T | The type of elements in the array. |
- Parameters
-
rows | The number of rows in the array. |
columns | The number of columns in the array. |
M | The two-dimensional array to be written. |
Filename | The 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
-
M | The two-dimensional vector. |
Filename | The name of the output CSV file. |
Writes a two-dimensional vector to a CSV file.
- Template Parameters
-
T | The type of elements in the vector. |
- Parameters
-
M | The two-dimensional vector to be written. |
Filename | The 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}
The documentation for this class was generated from the following file: