API
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 
11 namespace MagAOX
12 {
13 namespace logger
14 {
15 
17 {
18  return;
19 }
20 
21 logFileName::logFileName(const std::string & fn) : m_fullName {fn}
22 {
23  parseName();
24 }
25 
26 int logFileName::fullName(const std::string & fn)
27 {
28  m_fullName = fn;
29  return parseName();
30 }
31 
32 logFileName & logFileName::operator=(const std::string & fn)
33 {
34  fullName(fn);
35 
36  return *this;
37 }
38 
39 std::string logFileName::fullName() const
40 {
41  return m_fullName;
42 }
43 
44 std::string logFileName::baseName() const
45 {
46  return m_baseName;
47 }
48 
49 std::string logFileName::appName() const
50 {
51  return m_appName;
52 }
53 
54 int logFileName::year() const
55 {
56  return m_year;
57 }
58 
59 int logFileName::month() const
60 {
61  return m_month;
62 }
63 
64 int logFileName::day() const
65 {
66  return m_day;
67 }
68 
69 int logFileName::hour() const
70 {
71  return m_hour;
72 }
73 
75 {
76  return m_minute;
77 }
78 
80 {
81  return m_second;
82 }
83 
84 int logFileName::nsec() const
85 {
86  return m_nsec;
87 }
88 
90 {
91  return m_timestamp;
92 }
93 
94 std::string logFileName::extension() const
95 {
96  return m_extension;
97 }
98 
99 bool logFileName::valid() const
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.
Definition: logFileName.hpp:29
int m_year
The year of the timestamp.
Definition: logFileName.hpp:36
std::string extension() const
Get the current value of.
Definition: logFileName.cpp:94
std::string m_extension
The extension of the file.
Definition: logFileName.hpp:46
int m_minute
The minute of the timestamp.
Definition: logFileName.hpp:40
int day() const
Get the current value of m_day.
Definition: logFileName.cpp:64
int minute() const
Get the current value of m_minute.
Definition: logFileName.cpp:74
int year() const
Get the current value of m_year.
Definition: logFileName.cpp:54
flatlogs::timespecX m_timestamp
The timestamp.
Definition: logFileName.hpp:44
int m_month
The month of the timestamp.
Definition: logFileName.hpp:37
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.
Definition: logFileName.hpp:48
int m_second
The second of the timestamp.
Definition: logFileName.hpp:41
std::string m_appName
The name of the application which wrote the file.
Definition: logFileName.hpp:35
std::string m_fullName
The full name of the file, including path.
Definition: logFileName.hpp:32
flatlogs::timespecX timestamp() const
Get the current value of m_valid.
Definition: logFileName.cpp:89
int m_day
The day of the timestamp.
Definition: logFileName.hpp:38
std::string appName() const
Get the current value of m_appName.
Definition: logFileName.cpp:49
logFileName()
Default c'tor.
Definition: logFileName.cpp:16
int m_hour
The hour of the timestamp.
Definition: logFileName.hpp:39
std::string m_baseName
The base name of the file, not including path.
Definition: logFileName.hpp:33
int second() const
Get the current value of m_second.
Definition: logFileName.cpp:79
int hour() const
Get the current value of m_hour.
Definition: logFileName.cpp:69
int m_nsec
The nanosecond of the timestamp.
Definition: logFileName.hpp:42
std::string fullName() const
Get the current value of m_fullName.
Definition: logFileName.cpp:39
logFileName & operator=(const std::string &fullName)
Assignment operator from string.
Definition: logFileName.cpp:32
int nsec() const
Get the current value of m_nsec.
Definition: logFileName.cpp:84
std::string baseName() const
Get the current value of m_baseName.
Definition: logFileName.cpp:44
bool valid() const
Get the current value of.
Definition: logFileName.cpp:99
int month() const
Get the current value of m_month.
Definition: logFileName.cpp:59
Declares and defines the logFileName class.
std::ostream & cerr()
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