cprover
ui_message.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_UI_MESSAGE_H
11 #define CPROVER_UTIL_UI_MESSAGE_H
12 
13 #include <memory>
14 
15 #include "message.h"
16 #include "json_stream.h"
17 #include "timestamper.h"
18 
20 {
21 public:
22  enum class uit { PLAIN, XML_UI, JSON_UI };
23 
25  uit,
26  const std::string &program,
27  const bool always_flush,
28  timestampert::clockt clock_type);
29 
30  ui_message_handlert(const class cmdlinet &, const std::string &program);
31 
34 
35  virtual ~ui_message_handlert();
36 
37  uit get_ui() const
38  {
39  return _ui;
40  }
41 
42  void set_ui(uit __ui)
43  {
44  _ui=__ui;
45  if(_ui == uit::JSON_UI && !json_stream)
46  {
47  json_stream =
48  std::unique_ptr<json_stream_arrayt>(new json_stream_arrayt(out));
49  }
50  }
51 
52  virtual void flush(unsigned level) override;
53 
55  {
56  PRECONDITION(json_stream!=nullptr);
57  return *json_stream;
58  }
59 
60 protected:
62  const bool always_flush;
63  std::unique_ptr<const timestampert> time;
64  std::ostream &out;
65  std::unique_ptr<json_stream_arrayt> json_stream;
66 
67  virtual void print(
68  unsigned level,
69  const std::string &message) override;
70 
71  virtual void print(
72  unsigned level,
73  const std::string &message,
74  int sequence_number,
75  const source_locationt &location) override;
76 
77  virtual void print(
78  unsigned level,
79  const xmlt &data) override;
80 
81  virtual void print(
82  unsigned level,
83  const jsont &data) override;
84 
85  virtual void xml_ui_msg(
86  const std::string &type,
87  const std::string &msg1,
88  const std::string &msg2,
89  const source_locationt &location);
90 
91  virtual void json_ui_msg(
92  const std::string &type,
93  const std::string &msg1,
94  const std::string &msg2,
95  const source_locationt &location);
96 
97  virtual void ui_msg(
98  const std::string &type,
99  const std::string &msg1,
100  const std::string &msg2,
101  const source_locationt &location);
102 
103  const char *level_string(unsigned level);
104 };
105 
106 #define OPT_FLUSH "(flush)"
107 
108 #define HELP_FLUSH " --flush flush every line of output\n"
109 
110 #endif // CPROVER_UTIL_UI_MESSAGE_H
std::ostream & out
Definition: ui_message.h:64
uit get_ui() const
Definition: ui_message.h:37
Definition: json.h:23
const char * level_string(unsigned level)
Definition: ui_message.cpp:117
ui_message_handlert()
Default constructor; implementation is in .cpp file.
Definition: ui_message.cpp:22
virtual void json_ui_msg(const std::string &type, const std::string &msg1, const std::string &msg2, const source_locationt &location)
Definition: ui_message.cpp:287
virtual void print(unsigned level, const std::string &message) override
Definition: ui_message.cpp:127
Provides methods for streaming JSON arrays.
Definition: json_stream.h:92
virtual void xml_ui_msg(const std::string &type, const std::string &msg1, const std::string &msg2, const source_locationt &location)
Definition: ui_message.cpp:264
#define PRECONDITION(CONDITION)
Definition: invariant.h:230
Definition: xml.h:18
clockt
Derived types of timestampert.
Definition: timestamper.h:45
virtual void ui_msg(const std::string &type, const std::string &msg1, const std::string &msg2, const source_locationt &location)
Definition: ui_message.cpp:243
const bool always_flush
Definition: ui_message.h:62
std::unique_ptr< json_stream_arrayt > json_stream
Definition: ui_message.h:65
virtual ~ui_message_handlert()
Definition: ui_message.cpp:96
void set_ui(uit __ui)
Definition: ui_message.h:42
Emit timestamps.
std::unique_ptr< const timestampert > time
Definition: ui_message.h:63
virtual void flush(unsigned level) override
Definition: ui_message.cpp:307
Definition: kdev_t.h:24
json_stream_arrayt & get_json_stream() override
Return the underlying JSON stream.
Definition: ui_message.h:54