1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /***************************************************************************
4 
5     textbuf.h
6 
7     Debugger text buffering engine.
8 
9 ***************************************************************************/
10 
11 #ifndef MAME_EMU_DEBUG_TEXTBUF_H
12 #define MAME_EMU_DEBUG_TEXTBUF_H
13 
14 #include <memory>
15 
16 #include "emucore.h"
17 
18 
19 /***************************************************************************
20     TYPE DEFINITIONS
21 ***************************************************************************/
22 
23 struct text_buffer;
24 
25 struct text_buffer_line
26 {
27 	const char *text;
28 	size_t length;
29 };
30 
31 // helper class for iterating over the lines of a text_buffer
32 class text_buffer_lines
33 {
34 private:
35 	const text_buffer &m_buffer;
36 
37 public:
text_buffer_lines(const text_buffer & buffer)38 	text_buffer_lines(const text_buffer& buffer) : m_buffer(buffer) { }
39 
40 	class text_buffer_line_iterator
41 	{
42 		const text_buffer &m_buffer;
43 		s32 m_lineptr;
44 	public:
text_buffer_line_iterator(const text_buffer & buffer,s32 lineptr)45 		text_buffer_line_iterator(const text_buffer &buffer, s32 lineptr) :
46 			m_buffer(buffer),
47 			m_lineptr(lineptr)
48 		{
49 		}
50 
51 		// technically this isn't a valid forward iterator, because operator * doesn't return a reference
52 		text_buffer_line operator*() const;
53 		text_buffer_line_iterator &operator++();
54 
55 		bool operator!=(const text_buffer_line_iterator& rhs)
56 		{
57 			return m_lineptr != rhs.m_lineptr;
58 		}
59 		// according to C++ spec, only != is needed; == is present for completeness.
60 		bool operator==(const text_buffer_line_iterator& rhs) { return !operator!=(rhs); }
61 	};
62 
63 	typedef text_buffer_line_iterator iterator;
64 	typedef text_buffer_line_iterator const iterator_const;
65 
66 	iterator begin() const;
67 	iterator end() const;
68 };
69 
70 /***************************************************************************
71     FUNCTION PROTOTYPES
72 ***************************************************************************/
73 
74 // free a text buffer
75 struct text_buffer_deleter { void operator()(text_buffer *text) const; };
76 using text_buffer_ptr = std::unique_ptr<text_buffer, text_buffer_deleter>;
77 
78 // allocate a new text buffer
79 text_buffer_ptr text_buffer_alloc(u32 bytes, u32 lines);
80 
81 // clear a text buffer
82 void text_buffer_clear(text_buffer &text);
83 
84 // "print" data to a text buffer
85 void text_buffer_print(text_buffer &text, const char *data);
86 
87 // "print" data to a text buffer with word wrapping to a given column
88 void text_buffer_print_wrap(text_buffer &text, const char *data, int wrapcol);
89 
90 // get the maximum width of lines seen so far
91 u32 text_buffer_max_width(const text_buffer &text);
92 
93 // get the current number of lines in the buffer
94 u32 text_buffer_num_lines(const text_buffer &text);
95 
96 // get an absolute sequence number for a given line
97 u32 text_buffer_line_index_to_seqnum(const text_buffer &text, u32 index);
98 
99 // get a sequenced line from the text buffer
100 const char *text_buffer_get_seqnum_line(const text_buffer &text, u32 seqnum);
101 
102 #endif // MAME_EMU_DEBUG_TEXTBUF_H
103