CsvLogger.cpp
Go to the documentation of this file.
1 #include "mvsim/CsvLogger.h"
2 
4 {
5  m_file = std::make_shared<std::ofstream>(std::ofstream());
6 }
7 
9 void CSVLogger::addColumn(std::string name) { m_columns[name] = 0.0; }
10 void CSVLogger::updateColumn(std::string name, double value)
11 {
12  m_columns[name] = value;
13 }
14 
16 {
17  columns_type::iterator it;
18  for (it = m_columns.begin(); it != m_columns.end();)
19  {
20  *m_file << it->first;
21 
22  if (++it != m_columns.end())
23  {
24  *m_file << ", ";
25  }
26  }
27 
28  *m_file << "\n"; // most CSV readers don't use \r\n
29 
30  return !!m_file;
31 }
32 
34 {
35  if (!isRecording) return true;
36 
37  if (!isOpen()) clear();
38 
39  columns_type::iterator it;
40  for (it = m_columns.begin(); it != m_columns.end();)
41  {
42  *m_file << it->second;
43 
44  if (++it != m_columns.end())
45  {
46  *m_file << ", ";
47  }
48  }
49 
50  *m_file << "\n";
51 
52  return !!m_file;
53 }
54 
56 {
57  if (m_file)
58  {
59  m_file->open((std::string("session") + std::to_string(currentSession) +
60  std::string("-") + m_filepath)
61  .c_str());
62  return isOpen();
63  }
64  return false;
65 }
66 
67 bool CSVLogger::isOpen() { return m_file->is_open(); }
69 {
70  if (m_file)
71  {
72  m_file->close();
73  return !isOpen();
74  }
75  return false;
76 }
77 
79 {
80  if (isOpen()) close();
81 
82  if (open())
83  {
84  return writeHeader();
85  }
86 
87  return false;
88 }
89 
91 {
93  close();
94 }
bool isOpen()
Definition: CsvLogger.cpp:67
void updateColumn(std::string name, double value)
Definition: CsvLogger.cpp:10
GLsizei const GLfloat * value
bool clear()
Definition: CsvLogger.cpp:78
virtual ~CSVLogger()
Definition: CsvLogger.cpp:8
bool close()
Definition: CsvLogger.cpp:68
std::shared_ptr< std::ofstream > m_file
Definition: CsvLogger.h:33
bool open()
Definition: CsvLogger.cpp:55
GLuint const GLchar * name
unsigned int currentSession
Definition: CsvLogger.h:36
columns_type m_columns
Definition: CsvLogger.h:32
bool isRecording
Definition: CsvLogger.h:35
bool writeHeader()
Definition: CsvLogger.cpp:15
std::string m_filepath
Definition: CsvLogger.h:34
bool writeRow()
Definition: CsvLogger.cpp:33
void newSession()
Definition: CsvLogger.cpp:90
void addColumn(std::string name)
Definition: CsvLogger.cpp:9


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51