1 #ifndef _library__messagebuffer__hpp__included__
2 #define _library__messagebuffer__hpp__included__
22 virtual ~update_handler() throw();
26 virtual void messagebuffer_update() throw(std::bad_alloc
, std::runtime_error
) = 0;
29 * Create new message buffer with specified maximum message count.
31 * Parameter maxmessages: The maximum number of messages.
32 * Parameter windowsize: The initial window size.
33 * Throws std::bad_alloc: Not enough memory.
34 * Throws std::logic_error: Windowsize is greater than maxmessages or maxmessages is zero.
36 messagebuffer(size_t maxmessages
, size_t windowsize
) throw(std::bad_alloc
, std::logic_error
);
39 * Add a new message to the buffer.
41 * Parameter msg: The new message to add.
42 * Throws std::bad_alloc: Not enough memory.
43 * Throws std::runtime_error: Thrown through from update handler.
45 void add_message(const std::string
& msg
) throw(std::bad_alloc
, std::runtime_error
);
50 * Parameter msgnum: Number of message to read.
51 * Returns: The read message.
52 * Throws std::bad_alloc: Not enough memory.
53 * Throws std::logic_error: Invalid message number.
55 const std::string
& get_message(size_t msgnum
) throw(std::bad_alloc
, std::logic_error
);
58 * Get the number of first message present.
60 * Returns: The number of first message present.
62 size_t get_msg_first() throw();
65 * Get the number of messages present.
67 * Returns: The number of messages present.
69 size_t get_msg_count() throw();
72 * Get the number of first message visible.
74 * Returns: The number of first message visible.
76 size_t get_visible_first() throw();
79 * Get the number of messages visible.
81 * Returns: The number of messages visible.
83 size_t get_visible_count() throw();
86 * Is there more messages after the current window?
88 * Returns: True if there is, false if not.
90 bool is_more_messages() throw();
95 void freeze_scrolling() throw();
100 void unfreeze_scrolling() throw();
105 void freeze_updates() throw();
110 * Returns: True if update is needed.
112 bool unfreeze_updates() throw();
115 * Scroll to beginning.
117 * Throws std::bad_alloc: Not enough memory.
118 * Throws std::runtime_error: Thrown through from update handler.
120 void scroll_beginning() throw(std::bad_alloc
, std::runtime_error
);
123 * Scroll up one page.
125 * Throws std::bad_alloc: Not enough memory.
126 * Throws std::runtime_error: Thrown through from update handler.
128 void scroll_up_page() throw(std::bad_alloc
, std::runtime_error
);
131 * Scroll up one line.
133 * Throws std::bad_alloc: Not enough memory.
134 * Throws std::runtime_error: Thrown through from update handler.
136 void scroll_up_line() throw(std::bad_alloc
, std::runtime_error
);
139 * Scroll down one line.
141 * Throws std::bad_alloc: Not enough memory.
142 * Throws std::runtime_error: Thrown through from update handler.
144 void scroll_down_line() throw(std::bad_alloc
, std::runtime_error
);
147 * Scroll down one page.
149 * Throws std::bad_alloc: Not enough memory.
150 * Throws std::runtime_error: Thrown through from update handler.
152 void scroll_down_page() throw(std::bad_alloc
, std::runtime_error
);
155 * Scroll to beginning.
157 * Throws std::bad_alloc: Not enough memory.
158 * Throws std::runtime_error: Thrown through from update handler.
160 void scroll_end() throw(std::bad_alloc
, std::runtime_error
);
163 * Register an update handler.
165 * Parameter handler: The new handler.
166 * Throws std::bad_alloc: Not enough memory.
168 void register_handler(update_handler
& handler
) throw(std::bad_alloc
);
171 * Unregister an update handler.
173 * Parameter handler: The handler to remove.
174 * Throws std::bad_alloc: Not enough memory.
176 void unregister_handler(update_handler
& handler
) throw();
179 * Change the window size.
181 * Parameter windowsize: The new window size.
182 * Throws std::bad_alloc: Not enough memory.
183 * Throws std::logic_error: Windowsize is greater than maxmessages or maxmessages is zero.
185 void set_max_window_size(size_t windowsize
) throw(std::bad_alloc
, std::logic_error
);
188 * Read the window size.
190 size_t get_max_window_size() throw();
192 * Read the last message.
194 std::string
get_last_message();
196 void send_notifications();
197 std::map
<uint64_t, std::string
> messages_buf
;
198 uint64_t first_present_message
;
199 uint64_t next_message_number
;
200 uint64_t window_start
;
205 uint64_t window_start_at_freeze
;
206 uint64_t window_size_at_freeze
;
207 uint64_t next_message_number_at_freeze
;
208 std::set
<update_handler
*> handlers
;