μHAL (v2.7.9)
Part of the IPbus software repository
log_inserters.time.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
33 
34 #ifndef _uhal_log_inserters_time_hpp_
35 #define _uhal_log_inserters_time_hpp_
36 
37 
38 #include <iostream>
39 #include <stdint.h>
40 #include <sys/time.h>
41 
43 
44 
45 // Forward declarations
46 struct timeval;
47 struct tm;
48 
49 
50 namespace uhal
51 {
52 
55  {
56  null,
57  year,
58  yr,
60  mth,
61  day,
62  hr,
63  min,
64  sec,
65  usec
66  };
67 
69  template< time_element T0 , char D0 = ' ' ,
70  time_element T1 = null, char D1 = ' ' ,
71  time_element T2 = null, char D2 = ' ' ,
72  time_element T3 = null, char D3 = ' ' ,
73  time_element T4 = null, char D4 = ' ' ,
74  time_element T5 = null, char D5 = ' ' ,
75  time_element T6 = null > struct TimeFmt {};
76 
78  typedef TimeFmt<day,'/',mth,'/',year,' ',hr,':',min,':',sec> DefaultTimeFmt;
79 
80 
82  template< typename FORMAT > class _Time;
83 
89  _Time< DefaultTimeFmt > Time ( const timeval& aTime );
90 
91 
92  template< time_element T0, char D0 ,
93  time_element T1 , char D1 ,
94  time_element T2 , char D2 ,
95  time_element T3 , char D3 ,
96  time_element T4 , char D4 ,
97  time_element T5 , char D5 ,
98  time_element T6 >
100 
101  template< time_element T0, char D0 ,
102  time_element T1 , char D1 ,
103  time_element T2 , char D2 ,
104  time_element T3 , char D3 ,
105  time_element T4 , char D4 ,
106  time_element T5 >
108 
109  template< time_element T0, char D0 ,
110  time_element T1 , char D1 ,
111  time_element T2 , char D2 ,
112  time_element T3 , char D3 ,
113  time_element T4 >
115 
116  template< time_element T0, char D0 ,
117  time_element T1 , char D1 ,
118  time_element T2 , char D2 ,
119  time_element T3 >
121 
122  template< time_element T0, char D0 ,
123  time_element T1 , char D1 ,
124  time_element T2 >
126 
127  template< time_element T0, char D0 ,
128  time_element T1 >
130 
131  template< time_element T0 >
133 
134 
135 
142  template< typename FORMAT > _Time< FORMAT > Time ( const timeval& aTime , const FORMAT& aFmt );
143 
144 
145 
150  template< typename FORMAT >
151  class _Time : public RefWrapper< timeval >
152  {
153  friend _Time< DefaultTimeFmt > Time ( const timeval& aTime );
154  friend _Time< FORMAT > Time<> ( const timeval& aTime , const FORMAT& aFmt );
155 
156  template< time_element T0, char D0 ,
157  time_element T1 , char D1 ,
158  time_element T2 , char D2 ,
159  time_element T3 , char D3 ,
160  time_element T4 , char D4 ,
161  time_element T5 , char D5 ,
162  time_element T6 >
163  friend _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,D5,T6> > Time ( const timeval& aTime );
164 
165  template< time_element T0, char D0 ,
166  time_element T1 , char D1 ,
167  time_element T2 , char D2 ,
168  time_element T3 , char D3 ,
169  time_element T4 , char D4 ,
170  time_element T5 >
171  friend _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,' ',null> > Time ( const timeval& aTime );
172 
173  template< time_element T0, char D0 ,
174  time_element T1 , char D1 ,
175  time_element T2 , char D2 ,
176  time_element T3 , char D3 ,
177  time_element T4 >
178  friend _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,' ',null,' ',null> > Time ( const timeval& aTime );
179 
180  template< time_element T0, char D0 ,
181  time_element T1 , char D1 ,
182  time_element T2 , char D2 ,
183  time_element T3 >
185 
186  template< time_element T0, char D0 ,
187  time_element T1 , char D1 ,
188  time_element T2 >
190 
191  template< time_element T0, char D0 ,
192  time_element T1 >
194 
195  template< time_element T0 >
197 
198 
203  _Time ( const timeval& aTime ) : RefWrapper< timeval > ( aTime ) {}
204  };
205 
206 
207 
213  template< time_element T >
214  void print ( std::ostream& aStr , const tm* aTm , const uint32_t& aUsec );
215 
216 
221  timeval Now();
222 
223 
224  template< time_element T0, char D0 ,
225  time_element T1 , char D1 ,
226  time_element T2 , char D2 ,
227  time_element T3 , char D3 ,
228  time_element T4 , char D4 ,
229  time_element T5 , char D5 ,
230  time_element T6 >
231  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,D5,T6> >& aTime );
232 
233  template< time_element T0, char D0 ,
234  time_element T1 , char D1 ,
235  time_element T2 , char D2 ,
236  time_element T3 , char D3 ,
237  time_element T4 , char D4 ,
238  time_element T5 >
239  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,' ',null> >& aTime );
240 
241  template< time_element T0, char D0 ,
242  time_element T1 , char D1 ,
243  time_element T2 , char D2 ,
244  time_element T3 , char D3 ,
245  time_element T4 >
246  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,' ',null,' ',null> >& aTime );
247 
248  template< time_element T0, char D0 ,
249  time_element T1 , char D1 ,
250  time_element T2 , char D2 ,
251  time_element T3 >
252  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,' ',null,' ',null,' ',null> >& aTime );
253 
254  template< time_element T0, char D0 ,
255  time_element T1 , char D1 ,
256  time_element T2 >
257  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,' ',null,' ',null,' ',null,' ',null> >& aTime );
258 
259  template< time_element T0, char D0 ,
260  time_element T1 >
261  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,' ',null,' ',null,' ',null,' ',null,' ',null> >& aTime );
262 
263  template< time_element T0 >
264  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,' ',null,' ',null,' ',null,' ',null,' ',null,' ',null> >& aTime );
265 
266 }
267 
268 
270 
271 #endif
uhal::time_element
time_element
Enumerated type defining the different elements which can be used for formatting a time.
Definition: log_inserters.time.hpp:55
uhal::usec
@ usec
microseconds past the second formatted as exactly six digits e.g.
Definition: log_inserters.time.hpp:65
uhal::operator<<
std::ostream & operator<<(std::ostream &aStr, const uhal::HttpResponseType &aHttpResponse)
Definition: HttpResponseGrammar.cpp:41
uhal::_Time
Forward declaration.
Definition: log_inserters.time.hpp:82
uhal::yr
@ yr
year formatted as two digits e.g.
Definition: log_inserters.time.hpp:58
uhal::year
@ year
year formatted as four digits e.g.
Definition: log_inserters.time.hpp:57
log_inserters.time.hxx
uhal::day
@ day
day of the month formatted as two digits e.g.
Definition: log_inserters.time.hpp:61
uhal::hr
@ hr
hour of the day formatted as two digits, 24-hour clock e.g.
Definition: log_inserters.time.hpp:62
uhal::print
void print(std::ostream &aStr, const tm *aTm, const uint32_t &aUsec)
Format a time element for for sending to the log.
uhal::min
@ min
minutes past the hour formatted as two digits e.g.
Definition: log_inserters.time.hpp:63
log_inserter_helper.hpp
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::RefWrapper
Definition: log_inserter_helper.hpp:45
uhal::DefaultTimeFmt
TimeFmt< day,'/', mth,'/', year,' ', hr,':', min,':', sec > DefaultTimeFmt
Typedef the most commonly used time format (day/month/year hour:minut:second) for convenience.
Definition: log_inserters.time.hpp:78
uhal::TimeFmt
A struct whose template parameters represent a time format.
Definition: log_inserters.time.hpp:75
uhal::sec
@ sec
seconds past the minute formatted as two digits e.g.
Definition: log_inserters.time.hpp:64
uhal::Now
timeval Now()
A helper function to return the current time.
Definition: log_inserters.time.cpp:155
uhal::_Time::Time
friend _Time< DefaultTimeFmt > Time(const timeval &aTime)
Helper function which wrap the template uglyness in a pretty package.
Definition: log_inserters.time.hxx:53
uhal::strmth
@ strmth
month formatted as three character string e.g.
Definition: log_inserters.time.hpp:59
uhal::mth
@ mth
month formatted as two digits e.g.
Definition: log_inserters.time.hpp:60
uhal::_Time::_Time
_Time(const timeval &aTime)
Constructor.
Definition: log_inserters.time.hpp:203
uhal::Time
_Time< DefaultTimeFmt > Time(const timeval &aTime)
Helper function which wrap the template uglyness in a pretty package.
Definition: log_inserters.time.hxx:53