ATLAS Offline Software
Loading...
Searching...
No Matches
datetimestamp.h
Go to the documentation of this file.
1
16
17
18#ifndef DATETIMESTAMP_H
19#define DATETIMESTAMP_H
20
21#include <dlfcn.h>
22#include <sys/stat.h>
23#include <time.h>
24#include <string>
25
26inline std::string datetimestamp_addr(const void* address)
27{
28 Dl_info info;
29
30 struct stat st;
31
32 if ( dladdr( address, &info )==0 || info.dli_fname==0 || stat( info.dli_fname, &st )!=0 ) return "???";
33
34 std::string stime( 25, '\0' );
35
36 ctime_r( &st.st_mtime, &stime[0] );
37 stime.pop_back();
38
39 return stime;
40}
41
42template<typename T, typename... Args>
43std::string datetimestamp(T (*func)(Args...)) { return datetimestamp_addr((void*)(func)); }
44
45template<typename T>
46struct timestamp { static void stamper() {} };
47
48template<typename T>
49std::string datetimestamp(const T* /* t */ ) { return datetimestamp_addr((void*)(&timestamp<T>::stamper)); }
50
51
52#endif // DATETIMESTAMP_H
53
std::string stime()
return the current data and time
std::string datetimestamp(T(*func)(Args...))
std::string datetimestamp_addr(const void *address)
static void stamper()