API
logFileName.hpp
Go to the documentation of this file.
1 /** \file logFileName.hpp
2  * \brief Declares and defines the logFileName class
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_files
6  *
7  * History:
8  * - 2019-12-16 created by JRM
9  */
10 
11 #ifndef logger_logFileName_hpp
12 #define logger_logFileName_hpp
13 
14 #include <map>
15 #include <set>
16 
17 #include <mx/ioutils/fileUtils.hpp>
18 
19 #include <flatlogs/flatlogs.hpp>
20 
21 namespace MagAOX
22 {
23 namespace logger
24 {
25 
26 
27 /// Organize and analyze the name of a log or telemetry file.
29 {
30 
31 protected:
32  std::string m_fullName; ///< The full name of the file, including path
33  std::string m_baseName; ///< The base name of the file, not including path
34 
35  std::string m_appName; ///< The name of the application which wrote the file
36  int m_year {0}; ///< The year of the timestamp
37  int m_month {0}; ///< The month of the timestamp
38  int m_day {0}; ///< The day of the timestamp
39  int m_hour {0}; ///< The hour of the timestamp
40  int m_minute {0}; ///< The minute of the timestamp
41  int m_second {0}; ///< The second of the timestamp
42  int m_nsec {0}; ///< The nanosecond of the timestamp
43 
44  flatlogs::timespecX m_timestamp {0,0}; ///< The timestamp
45 
46  std::string m_extension; ///< The extension of the file
47 
48  bool m_valid {false}; ///< Whether or not the file parsed correctly and the components are valid
49 
50 public:
51 
52  /// Default c'tor
53  logFileName();
54 
55  /// Construct from a full name
56  /** This calls parseName, which parses the input and
57  * populates all fields.
58  *
59  * On success, sets `m_valid=true`
60  *
61  * On error, sets `m_valid=false`
62  */
63  explicit logFileName(const std::string & fullName /**< [in] The new full name of the log (including the path)*/);
64 
65  /// Sets the full name
66  /** Setting the full name is the only way to set any of the values. This parses the input and
67  * populates all fields.
68  *
69  * \returns 0 on sucess, and sets `m_valid=true`
70  * \returns -1 on an error, and sets `m_valid=false`
71  */
72  int fullName(const std::string & fullName /**< [in] The new full name of the log (including the path)*/);
73 
74  /// Assignment operator from string
75  /** Sets the full name, which is the only way to set any of the values. This parses the input and
76  * populates all fields.
77  *
78  * On success, sets `m_valid=true`
79  *
80  * On error, sets `m_valid=false`
81  *
82  * \returns a reference the `this`
83  */
84  logFileName & operator=(const std::string & fullName /**< [in] The new full name of the log (including the path)*/);
85 
86  /// Get the current value of m_fullName
87  /**
88  * \returns the current value of m_fullName
89  */
90  std::string fullName() const;
91 
92  /// Get the current value of m_baseName
93  /**
94  * \returns the current value of m_baseName
95  */
96  std::string baseName() const;
97 
98  /// Get the current value of m_appName
99  /**
100  * \returns the current value of m_appName
101  */
102  std::string appName() const;
103 
104  /// Get the current value of m_year
105  /**
106  * \returns the current value of m_year
107  */
108  int year() const;
109 
110  /// Get the current value of m_month
111  /**
112  * \returns the current value of m_month
113  */
114  int month() const;
115 
116  /// Get the current value of m_day
117  /**
118  * \returns the current value of m_day
119  */
120  int day() const;
121 
122  /// Get the current value of m_hour
123  /**
124  * \returns the current value of m_hour
125  */
126  int hour() const;
127 
128  /// Get the current value of m_minute
129  /**
130  * \returns the current value of m_minute
131  */
132  int minute() const;
133 
134  /// Get the current value of m_second
135  /**
136  * \returns the current value of m_second
137  */
138  int second() const;
139 
140  /// Get the current value of m_nsec
141  /**
142  * \returns the current value of m_nsec
143  */
144  int nsec() const;
145 
146  /// Get the current value of m_valid
147  /**
148  * \returns the current value of m_valid
149  */
151 
152  /// Get the current value of
153  /**
154  * \returns the current value of
155  */
156  std::string extension() const;
157 
158  /// Get the current value of
159  /**
160  * \returns the current value of
161  */
162  bool valid() const;
163 
164 protected:
165 
166  /// Parses the `m_fullName` and populates all fields.
167  /**
168  * \returns 0 on sucess, and sets `m_valid=true`
169  * \returns -1 on an error, and sets `m_valid=false`
170  */
171  int parseName();
172 
173 
174 };
175 
176 
177 
178 /// Sort predicate for logFileNames
179 /** Sorting is on 'fullName()'
180  */
182 {
183  /// Comparison operator.
184  /** \returns true if a < b
185  * \returns false otherwise
186  */
187  bool operator()( const logFileName & a,
188  const logFileName & b
189  ) const
190  {
191  return (a.baseName() < b.baseName());
192  }
193 };
194 
195 } //namespace logger
196 } //namespace MagAOX
197 
198 #endif //logger_logFileName_hpp
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
Flatlogs single include file.
Definition: dm.hpp:24
Sort predicate for logFileNames.
bool operator()(const logFileName &a, const logFileName &b) const
Comparison operator.
A fixed-width timespec structure.
Definition: timespecX.hpp:35