API
 
Loading...
Searching...
No Matches
logFileName.cpp
Go to the documentation of this file.
1/** \file logFileName.cpp
2 * \brief Declares and defines the logFileName class
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_files
6 *
7 */
8
9#include "logFileName.hpp"
10
11namespace MagAOX
12{
13namespace logger
14{
15
17{
18 return;
19}
20
21logFileName::logFileName(const std::string & fn) : m_fullName {fn}
22{
23 parseName();
24}
25
26int logFileName::fullName(const std::string & fn)
27{
28 m_fullName = fn;
29 return parseName();
30}
31
32logFileName & logFileName::operator=(const std::string & fn)
33{
34 fullName(fn);
35
36 return *this;
37}
38
39std::string logFileName::fullName() const
40{
41 return m_fullName;
42}
43
44std::string logFileName::baseName() const
45{
46 return m_baseName;
47}
48
49std::string logFileName::appName() const
50{
51 return m_appName;
52}
53
55{
56 return m_year;
57}
58
60{
61 return m_month;
62}
63
65{
66 return m_day;
67}
68
70{
71 return m_hour;
72}
73
75{
76 return m_minute;
77}
78
80{
81 return m_second;
82}
83
85{
86 return m_nsec;
87}
88
93
94std::string logFileName::extension() const
95{
96 return m_extension;
97}
98
100{
101 return m_valid;
102}
103
105{
106 m_baseName = mx::ioutils::pathFilename(m_fullName);
107
108 size_t ext = m_fullName.rfind('.');
109
110 if(ext == std::string::npos)
111 {
112 std::cerr << "No extension found in: " << m_fullName << "\n";
113 m_valid = false;
114 return -1;
115 }
116
117 m_extension = m_fullName.substr(ext+1);
118
119 size_t ts = m_fullName.rfind('_', ext);
120
121 if(ts == std::string::npos)
122 {
123 std::cerr << "No app name found in: " << m_fullName << "\n";
124 m_valid = false;
125 return -1;
126 }
127
128 size_t ps = m_fullName.rfind('/', ts);
129
130 if(ps == std::string::npos) ps = 0;
131 else ++ps;
132
133 m_appName = m_fullName.substr(ps, ts-ps);
134
135 ++ts;
136 if(ext-ts != 23)
137 {
138 std::cerr << "Timestamp wrong size in: " << m_fullName << "\n";
139 m_valid = false;
140 return -1;
141 }
142
143 std::string tstamp = m_fullName.substr(ts, ext-ts);
144
145 m_year = std::stoi(tstamp.substr(0,4));
146 m_month = std::stoi(tstamp.substr(4,2));
147 m_day = std::stoi(tstamp.substr(6,2));
148 m_hour = std::stoi(tstamp.substr(8,2));
149 m_minute = std::stoi(tstamp.substr(10,2));
150 m_second = std::stoi(tstamp.substr(12,2));
151 m_nsec = std::stoi(tstamp.substr(14,9));
152
153 tm tmst;
154 tmst.tm_year = m_year-1900;
155 tmst.tm_mon = m_month - 1;
156 tmst.tm_mday = m_day;
157 tmst.tm_hour = m_hour;
158 tmst.tm_min = m_minute;
159 tmst.tm_sec = m_second;
160
161 m_timestamp.time_s = timegm(&tmst);
163
164 m_valid = true;
165
166 return 0;
167}
168
169
170
171} //namespace logger
172} //namespace MagAOX
173
Organize and analyze the name of a log or telemetry file.
int m_year
The year of the timestamp.
std::string extension() const
Get the current value of.
std::string m_extension
The extension of the file.
int m_minute
The minute of the timestamp.
int day() const
Get the current value of m_day.
int minute() const
Get the current value of m_minute.
int year() const
Get the current value of m_year.
flatlogs::timespecX m_timestamp
The timestamp.
int m_month
The month of the timestamp.
int parseName()
Parses the m_fullName and populates all fields.
bool m_valid
Whether or not the file parsed correctly and the components are valid.
int m_second
The second of the timestamp.
std::string m_appName
The name of the application which wrote the file.
std::string m_fullName
The full name of the file, including path.
flatlogs::timespecX timestamp() const
Get the current value of m_valid.
int m_day
The day of the timestamp.
std::string appName() const
Get the current value of m_appName.
int m_hour
The hour of the timestamp.
std::string m_baseName
The base name of the file, not including path.
int second() const
Get the current value of m_second.
int hour() const
Get the current value of m_hour.
int m_nsec
The nanosecond of the timestamp.
std::string fullName() const
Get the current value of m_fullName.
logFileName & operator=(const std::string &fullName)
Assignment operator from string.
int nsec() const
Get the current value of m_nsec.
std::string baseName() const
Get the current value of m_baseName.
bool valid() const
Get the current value of.
int month() const
Get the current value of m_month.
Declares and defines the logFileName class.
Definition dm.hpp:24
A fixed-width timespec structure.
Definition timespecX.hpp:35
nanosecT time_ns
Nanoseconds.
Definition timespecX.hpp:37
secT time_s
Time since the Unix epoch.
Definition timespecX.hpp:36