refactor(kernel/formatter): hide 'unsafe' constructor

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-12-08 15:39:26 -08:00
parent 68c2e5cc7d
commit 759fcb7b4f
3 changed files with 9 additions and 4 deletions

View file

@ -1373,7 +1373,7 @@ public:
};
formatter mk_pp_formatter(frontend const & fe) {
return formatter(new pp_formatter_cell(fe));
return mk_formatter(pp_formatter_cell(fe));
}
std::ostream & operator<<(std::ostream & out, frontend const & fe) {

View file

@ -33,6 +33,6 @@ public:
}
};
formatter mk_simple_formatter() {
return formatter(new simple_formatter_cell());
return mk_formatter(simple_formatter_cell());
}
}

View file

@ -40,15 +40,20 @@ public:
*/
class formatter {
std::shared_ptr<formatter_cell> m_cell;
public:
formatter(formatter_cell * c):m_cell(c) {}
formatter(std::shared_ptr<formatter_cell> const & c):m_cell(c) {}
public:
format operator()(expr const & e, options const & opts = options()) const { return (*m_cell)(e, opts); }
format operator()(context const & c, options const & opts = options()) const { return (*m_cell)(c, opts); }
format operator()(context const & c, expr const & e, bool format_ctx = false, options const & opts = options()) const { return (*m_cell)(c, e, format_ctx, opts); }
format operator()(object const & obj, options const & opts = options()) const { return (*m_cell)(obj, opts); }
format operator()(environment const & env, options const & opts = options()) const { return (*m_cell)(env, opts); }
template<typename FCell>
friend formatter mk_formatter(FCell && fcell) {
return formatter(new FCell(std::forward<FCell>(fcell)));
}
};
/**
\brief Create a simple formatter object based on \c print function.
*/