μHAL (v2.6.5)
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 _log_inserters_time_hpp_
35 #define _log_inserters_time_hpp_
36 
37 
38 #include <iostream>
39 #include <stdint.h>
40 #include <sys/time.h>
41 
42 
44 
45 
46 // Forward declarations
47 struct timeval;
48 struct tm;
49 
50 
51 namespace uhal
52 {
53 
56  {
57  null,
58  year,
59  yr,
61  mth,
62  day,
63  hr,
64  min,
65  sec,
67  };
68 
70  template< time_element T0 , char D0 = ' ' ,
71  time_element T1 = null, char D1 = ' ' ,
72  time_element T2 = null, char D2 = ' ' ,
73  time_element T3 = null, char D3 = ' ' ,
74  time_element T4 = null, char D4 = ' ' ,
75  time_element T5 = null, char D5 = ' ' ,
76  time_element T6 = null > struct TimeFmt {};
77 
79  typedef TimeFmt<day,'/',mth,'/',year,' ',hr,':',min,':',sec> DefaultTimeFmt;
80 
81 
83  template< typename FORMAT > class _Time;
84 
90  _Time< DefaultTimeFmt > Time ( const timeval& aTime );
91 
92 
93  template< time_element T0, char D0 ,
94  time_element T1 , char D1 ,
95  time_element T2 , char D2 ,
96  time_element T3 , char D3 ,
97  time_element T4 , char D4 ,
98  time_element T5 , char D5 ,
99  time_element T6 >
101 
102  template< time_element T0, char D0 ,
103  time_element T1 , char D1 ,
104  time_element T2 , char D2 ,
105  time_element T3 , char D3 ,
106  time_element T4 , char D4 ,
107  time_element T5 >
109 
110  template< time_element T0, char D0 ,
111  time_element T1 , char D1 ,
112  time_element T2 , char D2 ,
113  time_element T3 , char D3 ,
114  time_element T4 >
116 
117  template< time_element T0, char D0 ,
118  time_element T1 , char D1 ,
119  time_element T2 , char D2 ,
120  time_element T3 >
122 
123  template< time_element T0, char D0 ,
124  time_element T1 , char D1 ,
125  time_element T2 >
127 
128  template< time_element T0, char D0 ,
129  time_element T1 >
131 
132  template< time_element T0 >
134 
135 
136 
143  template< typename FORMAT > _Time< FORMAT > Time ( const timeval& aTime , const FORMAT& aFmt );
144 
145 
146 
147 
152  template< typename FORMAT >
153  class _Time : public RefWrapper< timeval >
154  {
155  friend _Time< DefaultTimeFmt > Time ( const timeval& aTime );
156  friend _Time< FORMAT > Time<> ( const timeval& aTime , const FORMAT& aFmt );
157 
158  template< time_element T0, char D0 ,
159  time_element T1 , char D1 ,
160  time_element T2 , char D2 ,
161  time_element T3 , char D3 ,
162  time_element T4 , char D4 ,
163  time_element T5 , char D5 ,
164  time_element T6 >
165  friend _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,D5,T6> > Time ( const timeval& aTime );
166 
167  template< time_element T0, char D0 ,
168  time_element T1 , char D1 ,
169  time_element T2 , char D2 ,
170  time_element T3 , char D3 ,
171  time_element T4 , char D4 ,
172  time_element T5 >
173  friend _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,' ',null> > Time ( const timeval& aTime );
174 
175  template< time_element T0, char D0 ,
176  time_element T1 , char D1 ,
177  time_element T2 , char D2 ,
178  time_element T3 , char D3 ,
179  time_element T4 >
180  friend _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,' ',null,' ',null> > Time ( const timeval& aTime );
181 
182  template< time_element T0, char D0 ,
183  time_element T1 , char D1 ,
184  time_element T2 , char D2 ,
185  time_element T3 >
187 
188  template< time_element T0, char D0 ,
189  time_element T1 , char D1 ,
190  time_element T2 >
192 
193  template< time_element T0, char D0 ,
194  time_element T1 >
196 
197  template< time_element T0 >
199 
200 
201 
206  _Time ( const timeval& aTime ) : RefWrapper< timeval > ( aTime ) {}
207 
208 
209  };
210 
211 
212 
218  template< time_element T >
219  void print ( std::ostream& aStr , const tm* aTm , const uint32_t& aUsec );
220 
221 
226  timeval Now();
227 
228 
229  template< time_element T0, char D0 ,
230  time_element T1 , char D1 ,
231  time_element T2 , char D2 ,
232  time_element T3 , char D3 ,
233  time_element T4 , char D4 ,
234  time_element T5 , char D5 ,
235  time_element T6 >
236  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,D5,T6> >& aTime );
237 
238  template< time_element T0, char D0 ,
239  time_element T1 , char D1 ,
240  time_element T2 , char D2 ,
241  time_element T3 , char D3 ,
242  time_element T4 , char D4 ,
243  time_element T5 >
244  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,D4,T5,' ',null> >& aTime );
245 
246  template< time_element T0, char D0 ,
247  time_element T1 , char D1 ,
248  time_element T2 , char D2 ,
249  time_element T3 , char D3 ,
250  time_element T4 >
251  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,D3,T4,' ',null,' ',null> >& aTime );
252 
253  template< time_element T0, char D0 ,
254  time_element T1 , char D1 ,
255  time_element T2 , char D2 ,
256  time_element T3 >
257  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,D2,T3,' ',null,' ',null,' ',null> >& aTime );
258 
259  template< time_element T0, char D0 ,
260  time_element T1 , char D1 ,
261  time_element T2 >
262  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,D1,T2,' ',null,' ',null,' ',null,' ',null> >& aTime );
263 
264  template< time_element T0, char D0 ,
265  time_element T1 >
266  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,D0,T1,' ',null,' ',null,' ',null,' ',null,' ',null> >& aTime );
267 
268  template< time_element T0 >
269  std::ostream& operator<< ( std::ostream& aStr , const _Time< TimeFmt<T0,' ',null,' ',null,' ',null,' ',null,' ',null,' ',null> >& aTime );
270 
271 
272 }
273 
274 
276 
277 #endif
hour of the day formatted as two digits, 24-hour clock e.g.
Forward declaration.
minutes past the hour formatted as two digits e.g.
year formatted as four digits e.g.
day of the month formatted as two digits e.g.
year formatted as two digits e.g.
_Time< DefaultTimeFmt > Time(const timeval &aTime)
Helper function which wrap the template uglyness in a pretty package.
_Time(const timeval &aTime)
Constructor.
seconds past the minute formatted as two digits e.g.
month formatted as two digits e.g.
an unused entry
month formatted as three character string e.g.
time_element
Enumerated type defining the different elements which can be used for formatting a time...
TimeFmt< day,'/', mth,'/', year,' ', hr,':', min,':', sec > DefaultTimeFmt
Typedef the most commonly used time format (day/month/year hour:minut:second) for convenience...
A struct whose template parameters represent a time format.
timeval Now()
A helper function to return the current time.
void print(std::ostream &aStr, const tm *aTm, const uint32_t &aUsec)
Format a time element for for sending to the log.
microseconds past the second formatted as exactly six digits e.g.