LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ErrorObj.h
Go to the documentation of this file.
1 #ifndef messagefacility_Utilities_ErrorObj_h
2 #define messagefacility_Utilities_ErrorObj_h
3 // vim: set sw=2 expandtab :
4 
7 
8 #include <list>
9 #include <sstream>
10 #include <string>
11 
12 #include <sys/time.h>
13 
14 namespace mf {
15 
16  // Note: This class is virtual because it is user-visible and customizable.
17  class ErrorObj {
18  public:
19  virtual ~ErrorObj();
20  ErrorObj() = delete;
21  ErrorObj(ELseverityLevel const sev,
22  std::string const& category,
23  bool verbatim = false,
24  std::string const& filename = "",
25  int lineNumber = 0);
26  ErrorObj(ErrorObj const&);
27 
28  int serial() const;
29  ELextendedID const& xid() const;
30  std::string const& idOverflow() const;
31  timeval timestamp() const;
32  std::list<std::string> const& items() const;
33  bool reactedTo() const;
34 
35  // Return concatenated items, the full text of the message.
36  std::string fullText() const;
37 
38  // Note: Obsolete! Remove me when user code migrated.
39  std::string const& context() const;
40  std::string const& iteration() const;
41  bool is_verbatim() const;
42  std::string const& filename() const;
43  int lineNumber() const;
44 
45  // mine
46  virtual void setTimestamp(timeval const&);
47  // Note: Obsolete! Remove me when user code migrated.
48  virtual void setContext(std::string const&);
49  virtual void setIteration(std::string const&);
50 
51  // part of xid
52  virtual void setSeverity(ELseverityLevel const);
53  virtual void setID(std::string const&);
54  virtual void setModule(std::string const&);
55  virtual void setSubroutine(std::string const&);
56 
57  // Per-message overrides for the global settings, part of xid
58  virtual void setHostName(std::string const&);
59  virtual void setHostAddr(std::string const&);
60  virtual void setApplication(std::string const&);
61  virtual void setPID(long);
62 
63  ErrorObj& operator<<(std::ostream& (*f)(std::ostream&));
64  ErrorObj& operator<<(std::ios_base& (*f)(std::ios_base&));
65 
66  // Explicit function for char const* to avoid unnecessary
67  // instantiations of char const[] types.
68  ErrorObj& opltlt(char const*);
69 
70  template <class T>
71  ErrorObj& opltlt(T const&);
72 
73  virtual ErrorObj& eo_emit(std::string const&);
74 
75  virtual void clear();
76  virtual void set(ELseverityLevel const, std::string const& id);
77  virtual void setReactedTo(bool);
78 
79  private:
80  int serial_{};
82  std::string idOverflow_{};
83  timeval timestamp_{0, 0};
84  std::list<std::string> items_{};
85  bool reactedTo_{false};
86  std::string iteration_{};
87  std::ostringstream oss_{};
88  bool verbatim_{false};
89  std::string filename_{};
90  int lineNumber_{};
91  };
92 
93  template <class T>
94  ErrorObj&
95  ErrorObj::opltlt(T const& t)
96  {
97  oss_.str({});
98  oss_ << t;
99  if (!oss_.str().empty()) {
100  eo_emit(oss_.str());
101  }
102  return *this;
103  }
104 
105  //
106  ErrorObj& operator<<(ErrorObj& e, char const* s);
107 
108  // Force conversion of char arrays to string.
109  template <class T>
110  ErrorObj&
111  operator<<(ErrorObj& e, T const& t)
112  {
113  return e.opltlt(t);
114  }
115 
116 } // namespace mf
117 
118 #endif /* messagefacility_Utilities_ErrorObj_h */
119 
120 // Local variables:
121 // mode: c++
122 // End:
int lineNumber() const
Definition: ErrorObj.cc:126
virtual ErrorObj & eo_emit(std::string const &)
Definition: ErrorObj.cc:207
virtual void setID(std::string const &)
Definition: ErrorObj.cc:141
bool verbatim_
Definition: ErrorObj.h:88
timeval timestamp() const
Definition: ErrorObj.cc:73
timeval timestamp_
Definition: ErrorObj.h:83
std::string idOverflow_
Definition: ErrorObj.h:82
virtual void setModule(std::string const &)
Definition: ErrorObj.cc:151
virtual void setPID(long)
Definition: ErrorObj.cc:201
virtual void setTimestamp(timeval const &)
Definition: ErrorObj.cc:241
virtual void setHostName(std::string const &)
Definition: ErrorObj.cc:183
std::string filename_
Definition: ErrorObj.h:89
std::list< std::string > const & items() const
Definition: ErrorObj.cc:79
std::string const & context() const
Definition: ErrorObj.cc:98
bool is_verbatim() const
Definition: ErrorObj.cc:91
TFile f
Definition: plotHisto.C:6
int serial_
Definition: ErrorObj.h:80
virtual ~ErrorObj()
Definition: ErrorObj.cc:20
std::string const & iteration() const
Definition: ErrorObj.cc:104
std::string const & idOverflow() const
Definition: ErrorObj.cc:67
virtual void clear()
Definition: ErrorObj.cc:218
ErrorObj & operator<<(std::ostream &(*f)(std::ostream &))
Definition: ErrorObj.cc:247
int lineNumber_
Definition: ErrorObj.h:90
bool reactedTo_
Definition: ErrorObj.h:85
ELextendedID const & xid() const
Definition: ErrorObj.cc:61
virtual void setSeverity(ELseverityLevel const)
Definition: ErrorObj.cc:132
std::string const & filename() const
Definition: ErrorObj.cc:120
virtual void setContext(std::string const &)
Definition: ErrorObj.cc:158
ELextendedID xid_
Definition: ErrorObj.h:81
virtual void setHostAddr(std::string const &)
Definition: ErrorObj.cc:189
std::string fullText() const
Definition: ErrorObj.cc:110
virtual void setApplication(std::string const &)
Definition: ErrorObj.cc:195
int serial() const
Definition: ErrorObj.cc:55
ErrorObj & opltlt(char const *)
Definition: ErrorObj.cc:263
ErrorObj()=delete
bool reactedTo() const
Definition: ErrorObj.cc:85
std::string iteration_
Definition: ErrorObj.h:86
std::ostringstream oss_
Definition: ErrorObj.h:87
virtual void setSubroutine(std::string const &)
Definition: ErrorObj.cc:170
virtual void setReactedTo(bool)
Definition: ErrorObj.cc:177
virtual void setIteration(std::string const &)
Definition: ErrorObj.cc:164
Float_t e
Definition: plot.C:35
std::list< std::string > items_
Definition: ErrorObj.h:84