abidw: Consolidate setting options
authorMatthias Maennich <maennich@google.com>
Tue, 21 May 2019 04:39:19 +0000 (05:39 +0100)
committerDodji Seketeli <dodji@redhat.com>
Wed, 22 May 2019 12:33:45 +0000 (14:33 +0200)
When setting options meant to be used for the write_context, it is easy
to forget to change all relavant locations. In order to consolidate
that, introduce a set_opts function that sets various known options.

We benefit from earlier refactoring as now the write_context is passed
around to carry options for writers. Hence we can be sure, that if we
set up the context correctly (and do not use deprecated functionality),
the respective write_* function will see the options set in the context.

* include/abg-writer.h (set_common_option): Declare new function.
* tools/abidw.cc (load_corpus_and_write_abixml)
(load_kernel_corpus_group_and_write_abixml): Use the newly
introduced set_common_option.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-writer.h
tools/abidw.cc

index dddb554..200b5f7 100644 (file)
@@ -53,6 +53,24 @@ set_show_locs(write_context& ctxt, bool flag);
 void
 set_annotate(write_context& ctxt, bool flag);
 
+
+/// A convenience generic function to set common options (usually used
+/// by Libabigail tools) from a generic options carrying-object, into
+/// a given @ref write_context.
+///
+/// @param ctxt the @ref the write_context to consider.
+///
+/// @param opts the option-carrying object to set the options from.
+/// It must contain data members named: annotate, and show_locs, at
+/// very least.
+template <typename OPTS>
+void
+set_common_options(write_context& ctxt, const OPTS& opts)
+{
+  set_annotate(ctxt, opts.annotate);
+  set_show_locs(ctxt, opts.show_locs);
+}
+
 void
 set_ostream(write_context& ctxt, ostream& os);
 
index 2ff6cf3..33b7c76 100644 (file)
@@ -444,8 +444,7 @@ load_corpus_and_write_abixml(char* argv[],
     {
       const write_context_sptr& write_ctxt
          = create_write_context(corp->get_environment(), cout);
-      set_annotate(*write_ctxt, opts.annotate);
-      set_show_locs(*write_ctxt, opts.show_locs);
+      set_common_options(*write_ctxt, opts);
 
       if (opts.abidiff)
        {
@@ -558,7 +557,7 @@ load_kernel_corpus_group_and_write_abixml(char* argv[],
     {
       const xml_writer::write_context_sptr& ctxt
          = xml_writer::create_write_context(group->get_environment(), cout);
-      set_annotate(*ctxt, opts.annotate);
+      set_common_options(*ctxt, opts);
 
       if (!opts.out_file_path.empty())
        {