Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
export.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional.hpp>
4#include <iostream>
5
6#include "storm/io/file.h"
8
9namespace storm {
10namespace io {
11
12template<typename DataType, typename Header1Type = DataType, typename Header2Type = DataType>
13inline void exportDataToCSVFile(std::string filepath, std::vector<std::vector<DataType>> const& data,
14 boost::optional<std::vector<Header1Type>> const& header1 = boost::none,
15 boost::optional<std::vector<Header2Type>> const& header2 = boost::none) {
16 std::ofstream filestream;
17 storm::io::openFile(filepath, filestream);
18
19 if (header1) {
20 for (auto columnIt = header1->begin(); columnIt != header1->end(); ++columnIt) {
21 if (columnIt != header1->begin()) {
22 filestream << ",";
23 }
24 filestream << *columnIt;
25 }
26 filestream << '\n';
27 }
28
29 if (header2) {
30 for (auto columnIt = header2->begin(); columnIt != header2->end(); ++columnIt) {
31 if (columnIt != header2->begin()) {
32 filestream << ",";
33 }
34 filestream << *columnIt;
35 }
36 filestream << '\n';
37 }
38
39 for (auto const& row : data) {
40 for (auto columnIt = row.begin(); columnIt != row.end(); ++columnIt) {
41 if (columnIt != row.begin()) {
42 filestream << ",";
43 }
44 filestream << *columnIt;
45 }
46 filestream << '\n';
47 }
48 storm::io::closeFile(filestream);
49}
50
59template<typename Container>
60inline void outputFixedWidth(std::ostream& stream, Container const& output, size_t maxWidth = 30) {
61 size_t curLength = 0;
62 for (auto s : output) {
63 if (curLength > 0) {
64 stream << ", ";
65 curLength += 2;
66 }
67 stream << s;
68 curLength += s.length();
69 if (maxWidth > 0 && curLength >= maxWidth) {
70 stream << '\n';
71 curLength = 0;
72 }
73 }
74}
75} // namespace io
76} // namespace storm
void exportDataToCSVFile(std::string filepath, std::vector< std::vector< DataType > > const &data, boost::optional< std::vector< Header1Type > > const &header1=boost::none, boost::optional< std::vector< Header2Type > > const &header2=boost::none)
Definition export.h:13
void outputFixedWidth(std::ostream &stream, Container const &output, size_t maxWidth=30)
Output list of strings with linebreaks according to fixed width.
Definition export.h:60
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
LabParser.cpp.
Definition cli.cpp:18