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 #include <type_traits>
12 
13 #include <sys/time.h>
14 
15 namespace mf {
16 
17  class ErrorLog;
18 
19  // Note: This class is virtual because it is user-visible and customizable.
20  class ErrorObj {
21 
22  public:
23  virtual ~ErrorObj();
24  ErrorObj() = delete;
25  ErrorObj(ELseverityLevel const sev,
26  std::string const& category,
27  bool verbatim = false,
28  std::string const& filename = "",
29  int lineNumber = 0);
30  ErrorObj(ErrorObj const&);
31 
32  int serial() const;
33  ELextendedID const& xid() const;
34  std::string const& idOverflow() const;
35  timeval timestamp() const;
36  std::list<std::string> const& items() const;
37  bool reactedTo() const;
38 
39  // Return concatenated items, the full text of the message.
40  std::string fullText() const;
41 
42  // Note: Obsolete! Remove me when user code migrated.
43  std::string const& context() const;
44  std::string const& iteration() const;
45  bool is_verbatim() const;
46  std::string const& filename() const;
47  int lineNumber() const;
48 
49  // mine
50  virtual void setTimestamp(timeval const&);
51  // Note: Obsolete! Remove me when user code migrated.
52  virtual void setContext(std::string const&);
53  virtual void setIteration(std::string const&);
54 
55  // part of xid
56  virtual void setSeverity(ELseverityLevel const);
57  virtual void setID(std::string const&);
58  virtual void setModule(std::string const&);
59  virtual void setSubroutine(std::string const&);
60 
61  // Per-message overrides for the global settings, part of xid
62  virtual void setHostName(std::string const&);
63  virtual void setHostAddr(std::string const&);
64  virtual void setApplication(std::string const&);
65  virtual void setPID(long);
66 
67  ErrorObj& operator<<(std::ostream& (*f)(std::ostream&));
68  ErrorObj& operator<<(std::ios_base& (*f)(std::ios_base&));
69 
70  // Explicit function for char const* to avoid unnecessary
71  // instantiations of char const[] types.
72  ErrorObj& opltlt(char const*);
73 
74  template <class T>
75  ErrorObj& opltlt(T const&);
76 
77  virtual ErrorObj& eo_emit(std::string const&);
78 
79  virtual void clear();
80  virtual void set(ELseverityLevel const, std::string const& id);
81  virtual void setReactedTo(bool);
82 
83  private:
84  int serial_{};
87  timeval timestamp_{0, 0};
88  std::list<std::string> items_{};
89  bool reactedTo_{false};
91  std::ostringstream oss_{};
92  bool verbatim_{false};
94  int lineNumber_{};
95  };
96 
97  template <class T>
98  ErrorObj&
100  {
101  oss_.str({});
102  oss_ << t;
103  if (!oss_.str().empty()) {
104  eo_emit(oss_.str());
105  }
106  return *this;
107  }
108 
109  //
110  ErrorObj& operator<<(ErrorObj& e, char const* s);
111 
112  // Force conversion of char arrays to string.
113  template <class T>
114  ErrorObj&
115  operator<<(ErrorObj& e, T const& t)
116  {
117  return e.opltlt(t);
118  }
119 
120 } // namespace mf
121 
122 #endif /* messagefacility_Utilities_ErrorObj_h */
123 
124 // Local variables:
125 // mode: c++
126 // End:
std::string const & idOverflow() const
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
int lineNumber() const
virtual void setSeverity(ELseverityLevel const)
bool verbatim_
Definition: ErrorObj.h:92
ErrorObj & opltlt(char const *)
timeval timestamp() const
timeval timestamp_
Definition: ErrorObj.h:87
std::string idOverflow_
Definition: ErrorObj.h:86
virtual ErrorObj & eo_emit(std::string const &)
virtual void setHostName(std::string const &)
virtual void setTimestamp(timeval const &)
std::string fullText() const
virtual void setIteration(std::string const &)
std::string const & iteration() const
std::string const & filename() const
virtual void setContext(std::string const &)
virtual void setModule(std::string const &)
std::string filename_
Definition: ErrorObj.h:93
virtual ~ErrorObj()
bool is_verbatim() const
int serial_
Definition: ErrorObj.h:84
const XML_Char * s
Definition: expat.h:262
int lineNumber_
Definition: ErrorObj.h:94
bool reactedTo_
Definition: ErrorObj.h:89
virtual void setApplication(std::string const &)
std::string const & context() const
virtual void setReactedTo(bool)
virtual void setSubroutine(std::string const &)
ELextendedID xid_
Definition: ErrorObj.h:85
ELextendedID const & xid() const
virtual void setPID(long)
virtual void clear()
int serial() const
virtual void setHostAddr(std::string const &)
ErrorObj()=delete
bool reactedTo() const
std::string iteration_
Definition: ErrorObj.h:90
ErrorObj & operator<<(std::ostream &(*f)(std::ostream &))
std::ostringstream oss_
Definition: ErrorObj.h:91
virtual void setID(std::string const &)
std::list< std::string > const & items() const
double T
Definition: Xdiff_gwt.C:5
Float_t e
Definition: plot.C:35
std::list< std::string > items_
Definition: ErrorObj.h:88
enum BeamMode string