From 37e20dd6599203c4e261fc3a2e86711c90cbbed9 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 1 Dec 2016 16:02:00 -0500 Subject: [PATCH] Class-ify ui_out_hdr This patch makes ui_out_hdr (the object that represents an ui-out table header) a proper C++ class. No behavior changes, it's all about encapsulation. gdb/ChangeLog: * ui-out.c (struct ui_out_hdr): Replace with ... (class ui_out_hdr): ... this. (append_header_to_list): Update. (get_next_header): Update. (ui_out_query_field): Update. --- gdb/ChangeLog | 8 +++++ gdb/ui-out.c | 96 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 15b1b7919e9..f5e78debe8e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2016-12-01 Simon Marchi + + * ui-out.c (struct ui_out_hdr): Replace with ... + (class ui_out_hdr): ... this. + (append_header_to_list): Update. + (get_next_header): Update. + (ui_out_query_field): Update. + 2016-12-01 Simon Marchi * mi/mi-out.c (mi_table_header): Change char * args to diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 3cd5695a2b6..d2ceac53f01 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -29,16 +29,66 @@ #include #include -/* table header structures */ +/* A header of a ui_out_table. */ -struct ui_out_hdr +class ui_out_hdr +{ + public: + + explicit ui_out_hdr (int number, int min_width, ui_align alignment, + const std::string &name, const std::string &header) + : m_number (number), + m_min_width (min_width), + m_alignment (alignment), + m_name (name), + m_header (header) { - int colno; - int width; - enum ui_align alignment; - std::string col_name; - std::string col_hdr; - }; + } + + int number () const + { + return m_number; + } + + int min_width () const + { + return m_min_width; + } + + ui_align alignment () const + { + return m_alignment; + } + + const std::string &header () const + { + return m_header; + } + + const std::string &name () const + { + return m_name; + } + + private: + + /* The number of the table column this header represents, 1-based. */ + int m_number; + + /* Minimal column width in characters. May or may not be applicable, + depending on the actual implementation of ui_out. */ + int m_min_width; + + /* Alignment of the content in the column. May or may not be applicable, + depending on the actual implementation of ui_out. */ + ui_align m_alignment; + + /* Internal column name, used to internally refer to the column. */ + std::string m_name; + + /* Printed header text of the column. */ + std::string m_header; +}; struct ui_out_level { @@ -705,17 +755,9 @@ append_header_to_list (struct ui_out *uiout, const std::string &col_name, const std::string &col_hdr) { - std::unique_ptr temphdr (new ui_out_hdr ()); - - temphdr->width = width; - temphdr->alignment = alignment; - - /* Make our own copy of the strings, since the lifetime of the original - versions may be too short. */ - temphdr->col_hdr = col_hdr; - temphdr->col_name = col_name; - - temphdr->colno = uiout->table.headers.size () + 1; + std::unique_ptr temphdr( + new ui_out_hdr (uiout->table.headers.size () + 1, width, + alignment, col_name, col_hdr)); uiout->table.headers.push_back (std::move (temphdr)); } @@ -736,10 +778,10 @@ get_next_header (struct ui_out *uiout, ui_out_hdr *hdr = uiout->table.headers_iterator->get (); - *colno = hdr->colno; - *width = hdr->width; - *alignment = hdr->alignment; - *col_hdr = hdr->col_hdr.c_str (); + *colno = hdr->number (); + *width = hdr->min_width (); + *alignment = hdr->alignment (); + *col_hdr = hdr->header ().c_str (); /* Advance the header pointer to the next entry. */ uiout->table.headers_iterator++; @@ -814,11 +856,11 @@ ui_out_query_field (struct ui_out *uiout, int colno, { ui_out_hdr *hdr = uiout->table.headers[index].get (); - gdb_assert (colno == hdr->colno); + gdb_assert (colno == hdr->number ()); - *width = hdr->width; - *alignment = hdr->alignment; - *col_name = hdr->col_name.c_str (); + *width = hdr->min_width (); + *alignment = hdr->alignment (); + *col_name = hdr->name ().c_str (); return 1; } -- 2.30.2