SUNphi  1.0
Crash.hpp
Go to the documentation of this file.
1 #ifndef _CRASH_HPP
2 #define _CRASH_HPP
3 
4 /// \file Crash.hpp
5 ///
6 /// \brief Makes it possible to crash
7 
8 #include <errno.h>
9 
10 namespace SUNphi
11 {
12  /// Initialize the crasher
13 #define CRASH
14  SUNphi::runLog()<<SUNphi::Crasher(__FILE__,__LINE__,__PRETTY_FUNCTION__)
15 
16  /// Keep all the information to crash
17  class Crasher
18  {
19  /// File where the crash happened
20  const char* path;
21 
22  /// Line number where the crash happened
23  const int line;
24 
25  /// Function where the crash happened
26  const char* funcName;
27 
28  /// Error from standard error library
29  int errNo{-1};
30 
31  public:
32 
33  /// Creates the crasher
34  Crasher(const char* path,
35  const int line,
36  const char* funcName)
37  :
38  path(path),
39  line(line),
40  funcName(funcName)
41  {
42  }
43 
44  /// Returns the path
45  const char* getPath()
46  const
47  {
48  return
49  path;
50  }
51 
52  /// Returns the line
53  const int getLine()
54  const
55  {
56  return
57  line;
58  }
59 
60  /// Returns the function name
61  const char* getFuncName()
62  const
63  {
64  return
65  funcName;
66  }
67 
68  /// Returns the standard library error
69  const int getErrNo()
70  const
71  {
72  return
73  errNo;
74  }
75 
76  /// Store the stdlib error
78  {
79  errNo=
80  errno;
81 
82  return
83  *this;
84  }
85 
86  };
87 }
88 
89 #endif
Crasher & printStdLibErr()
Store the stdlib error.
Definition: Crash.hpp:77
const int line
Line number where the crash happened.
Definition: Crash.hpp:23
const char * getPath() const
Returns the path.
Definition: Crash.hpp:45
int errNo
Error from standard error library.
Definition: Crash.hpp:29
Crasher(const char *path, const int line, const char *funcName)
Creates the crasher.
Definition: Crash.hpp:34
const int getErrNo() const
Returns the standard library error.
Definition: Crash.hpp:69
const char * getFuncName() const
Returns the function name.
Definition: Crash.hpp:61
const char * funcName
Function where the crash happened.
Definition: Crash.hpp:26
const char * path
File where the crash happened.
Definition: Crash.hpp:20
const int getLine() const
Returns the line.
Definition: Crash.hpp:53