Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
CStringDump.cpp
Go to the documentation of this file.
1 /*
2 * CStringDump.cpp
3 *
4 * Created on: 16.05.2015
5 * Author: Dag
6 */
7
8 #include <assert.h>
9 #include <stdio.h>
10
11 #include "CStringDump.h"
12
13 using namespace std;
14
15
16 CStringDump::CStringDump(string sBaseFileName)
17 {
18 assert (!sBaseFileName.empty());
19
20 m_sBaseFileName = sBaseFileName;
21 m_pFile = 0;
22 m_Count = 0;
23 }
24
25 CStringDump::~CStringDump()
26 {
27 if (m_pFile)
28 fclose (m_pFile);
29 m_sList.clear();
30 }
31
32 void CStringDump::Add(string sLine)
33 {
34 if (!m_pFile)
35 return;
36
37 m_sList.push_back(sLine);
38 m_Count++;
39 }
40
41 void CStringDump::Dump()
42 {
43 while (!m_sList.empty())
44 {
45 string sLine = m_sList.front();
46 m_sList.pop_front();
47 if (fputs(sLine.c_str(), m_pFile) < 0)
48 assert (false);
49 }
50 if (m_pFile)
51 {
52 fclose (m_pFile);
53 m_pFile = 0;
54 }
55 }
56
57 void CStringDump::Reset()
58 {
59 // Cleanup if needed.
60 if (m_pFile)
61 fclose (m_pFile);
62 m_sList.clear();
63 m_Count = 0;
64
65 string sLogFilename = m_sBaseFileName + GetDateTime('_', '_') + ".csv";
66 m_pFile = fopen (sLogFilename.c_str(), "wb");
67 if (!m_pFile)
68 {
69 printf ("Error opening file!\n");
70 assert (false);
71 }
72 }
73
74
75 string CStringDump::GetDateTime(char seperator, char timeSeperator)
76 {
77 time_t t = time(0); // get time now
78 struct tm *pNow = localtime (&t);
79 char buffer[128];
80 sprintf (buffer, "%02d.%02d.%d%c%02d%c%02d%c%02d", pNow->tm_mday, (pNow->tm_mon + 1), (pNow->tm_year + 1900), seperator, pNow->tm_hour, timeSeperator, pNow->tm_min, timeSeperator, pNow->tm_sec);
81 // printf ("Time = %s\n", buffer);
82 return string(buffer);
83 }
84
CStringDump::Dump
void Dump()
Definition: CStringDump.cpp:41
CStringDump::CStringDump
CStringDump(std::string sBaseFileName)
Definition: CStringDump.cpp:16
CStringDump::Add
void Add(std::string sLine)
Definition: CStringDump.cpp:32
CStringDump::Reset
void Reset()
Definition: CStringDump.cpp:57
std
CStringDump.h
CStringDump::GetDateTime
std::string GetDateTime(char seperator, char timeSeperator)
Definition: CStringDump.cpp:75
CStringDump::~CStringDump
virtual ~CStringDump()
Definition: CStringDump.cpp:25
GetDateTime
string GetDateTime(char seperator, char timeSeperator)
Definition: AnalogDump.cpp:95