Message.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_MESSAGE_H
2 #define GAUDIKERNEL_MESSAGE_H
3 
4 #include <string>
5 #include <iostream>
6 
14 class GAUDI_API Message final {
15 public:
17  Message();
18 
20  Message ( const char* src, int type, const char* msg );
21 
23  Message ( std::string src, int type, std::string msg );
24 
26  ~Message() = default;
27 
29  const std::string& getMessage() const;
30 
32  void setMessage( std::string msg );
33 
35  int getType() const;
36 
38  void setType( int msg_type );
39 
41  const std::string& getSource() const;
42 
44  void setSource( std::string src );
45 
47  const std::string& getFormat() const;
48 
50  static const std::string getDefaultFormat();
51 
53  void setFormat( std::string msg ) const;
54 
56  const std::string& getTimeFormat() const;
57 
59  static const std::string getDefaultTimeFormat() ;
60 
62  void setTimeFormat( std::string timeFormat ) const;
63 
65  bool operator < ( const Message& test );
66 
68  friend std::ostream& operator << ( std::ostream& stream, const Message& msg );
69 
71  friend bool operator == ( const Message& a, const Message& b );
72 
73 private:
75  void invalidFormat() const;
76 
78  void makeFormattedMsg( const std::string& format ) const;
79 
81  void decodeFormat( const std::string& format ) const;
82 
84  void sizeField( const std::string& text ) const;
85 
87  void setWidth( const std::string& formatArg ) const;
88 
90  std::string m_message;
91 
93  std::string m_source = "UNKNOWN";
94 
96  mutable std::string m_format = DEFAULT_FORMAT;
97 
99  mutable std::string m_time_format = DEFAULT_TIME_FORMAT;
100 
102  int m_type = 0;
103 
105  mutable std::string m_formatted_msg;
106 
108  mutable char m_fill = ' ';
109 
111  mutable int m_width = 0;
112 
114  mutable bool m_left = true;
115 
117 
119  static const char FORMAT_PREFIX = '%';
120 
122  static const char JUSTIFY_LEFT = 'L';
123 
125  static const char JUSTIFY_RIGHT = 'R';
126 
128  static const char MESSAGE = 'M';
129 
131  static const char TYPE = 'T';
132 
134  static const char TIME = 't';
135 
138  static const char UTIME = 'u';
139 
141  static const char SOURCE = 'S';
142 
146  static const char FILL = 'F';
147 
151  static const char WIDTH = 'W';
152 
154  //static const char* Message::DEFAULT_FORMAT = "% F%67W%L#############################################################################\n-----------------------------------------------------------------------------\nMessage follows...\nSource : %S\nType : %T\nMessage : %M\nEnd of message.\n-----------------------------------------------------------------------------\n";
155  static constexpr const char* DEFAULT_FORMAT = "% F%18W%S%7W%R%T %0W%M";
156 
158  // Time format accepts anything that strftime does plus %f for milliseconds
159  static constexpr const char* DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S,%f";
160 
162  static const char SLOT = 's';
163  static const char EVTNUM = 'e';
164  static const char THREAD = 'X';
165 
166  size_t m_ecSlot;
167  long int m_ecEvt;
168  pthread_t m_ecThrd;
169 };
170 
172 GAUDI_API std::ostream& operator << ( std::ostream& stream, const Message& msg );
173 
175 GAUDI_API bool operator == ( const Message& a, const Message& b );
176 
177 #endif
#define GAUDI_API
Definition: Kernel.h:107
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
The Message class.
Definition: Message.h:14
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Message &msg)
Insert the message into a stream.
Definition: Message.cpp:137
GAUDI_API bool operator==(const Message &a, const Message &b)
Insert the message into a stream.
Definition: Message.cpp:163
bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:232
string type
Definition: gaudirun.py:151