const environment* m_env;
id_manager m_id_manager;
config m_config;
- ostream& m_ostream;
+ ostream* m_ostream;
bool m_annotate;
bool m_show_locs;
mutable type_ptr_map m_type_id_map;
write_context(const environment* env, ostream& os)
: m_env(env),
m_id_manager(env),
- m_ostream(os),
+ m_ostream(&os),
m_annotate(false),
m_show_locs(true)
{}
get_config() const
{return m_config;}
+ /// Getter for the current ostream
+ ///
+ /// @return a reference to the current ostream
ostream&
get_ostream()
- {return m_ostream;}
+ {return *m_ostream;}
+
+ /// Setter for the current ostream
+ ///
+ /// @param os the new ostream
+ void
+ set_ostream(ostream& os)
+ {m_ostream = &os;}
/// Getter of the annotation option.
///
set_annotate(write_context& ctxt, bool flag)
{ctxt.set_annotate(flag);}
+/// Set the new ostream.
+///
+/// The ostream refers to the object, writers should stream new output to.
+///
+/// @param ctxt the context to set this to.
+///
+/// @param os the new ostream
+void
+set_ostream(write_context& ctxt, ostream& os)
+{ctxt.set_ostream(os);}
+
/// Serialize a translation unit to an output stream.
///
/// @param ctxt the context of the serialization. It contains e.g,
}
else
{
+ 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);
+
if (opts.abidiff)
{
// Save the abi in abixml format in a temporary file, read
// it back, and compare the ABI of what we've read back
// against the ABI of the input ELF file.
temp_file_sptr tmp_file = temp_file::create();
- const write_context_sptr& write_ctxt = create_write_context(
- corp->get_environment(), tmp_file->get_stream());
- set_annotate(*write_ctxt, opts.annotate);
+ set_ostream(*write_ctxt, tmp_file->get_stream());
write_corpus(*write_ctxt, corp, 0);
tmp_file->get_stream().flush();
corpus_sptr corp2 =
<< opts.out_file_path << "'\n";
return 1;
}
- const write_context_sptr& write_ctxt
- = create_write_context(corp->get_environment(), of);
- set_show_locs(*write_ctxt, opts.show_locs);
- set_annotate(*write_ctxt, opts.annotate);
+ set_ostream(*write_ctxt, of);
write_corpus(*write_ctxt, corp, 0);
of.close();
return 0;
}
else
{
- write_context_sptr write_ctxt
- = create_write_context(corp->get_environment(), cout);
- set_show_locs(*write_ctxt, opts.show_locs);
- set_annotate(*write_ctxt, opts.annotate);
exit_code = !write_corpus(*write_ctxt, corp, 0);
}
}
if (!opts.noout)
{
+ const xml_writer::write_context_sptr& ctxt
+ = xml_writer::create_write_context(group->get_environment(), cout);
+ set_annotate(*ctxt, opts.annotate);
+
if (!opts.out_file_path.empty())
{
ofstream of(opts.out_file_path.c_str(), std::ios_base::trunc);
<< opts.out_file_path << "'\n";
return 1;
}
- const write_context_sptr& ctxt
- = create_write_context(group->get_environment(), of);
- set_annotate(*ctxt, opts.annotate);
+ set_ostream(*ctxt, of);
exit_code = !write_corpus_group(*ctxt, group, 0);
}
else
{
- const write_context_sptr& ctxt
- = create_write_context(group->get_environment(), cout);
- set_annotate(*ctxt, opts.annotate);
exit_code = !write_corpus_group(*ctxt, group, 0);
}
}