From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109729 invoked by alias); 24 Nov 2016 15:28:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 109607 invoked by uid 89); 24 Nov 2016 15:28:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL,BAYES_50,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=Hx-spam-relays-external:sk:cable-1, H*RU:sk:cable-1, H*r:sk:cable-1, uiout X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Nov 2016 15:28:14 +0000 X-ASG-Debug-ID: 1480001292-0c856e65d4b89780001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 5g91HfHeM82CPUFa (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Nov 2016 10:28:12 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-11.246.173-162.electronicbox.net [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id 1182E440E7C; Thu, 24 Nov 2016 10:28:12 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 15/22] Class-ify ui_out_hdr Date: Thu, 24 Nov 2016 15:28:00 -0000 X-ASG-Orig-Subj: [PATCH 15/22] Class-ify ui_out_hdr Message-Id: <20161124152710.25007-15-simon.marchi@polymtl.ca> In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca> References: <20161124152428.24725-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1480001292 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 3922 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_SC0_MISMATCH_TO X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34709 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00754.txt.bz2 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/ui-out.c | 96 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 3cd5695..410f40c 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: + + 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.10.0