From: David Wells Date: Sun, 31 May 2015 22:28:45 +0000 (-0400) Subject: Replace all set_flags functions with a template. X-Git-Tag: v8.3.0-rc1~136^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbc1d421508d46a2cdfa925544a742179b4376aa;p=dealii.git Replace all set_flags functions with a template. This sacrifices some type safety in optimized mode to decrease redundancy. --- diff --git a/cmake/config/template-arguments.in b/cmake/config/template-arguments.in index e655291ad1..c28bc84b3d 100644 --- a/cmake/config/template-arguments.in +++ b/cmake/config/template-arguments.in @@ -90,3 +90,7 @@ SPARSITY_PATTERNS := { SparsityPattern; DIMENSIONS := { 1; 2; 3 } SPACE_DIMENSIONS := { 1; 2; 3 } + +OUTPUT_FLAG_TYPES := { DXFlags; UcdFlags; GnuplotFlags; PovrayFlags; EpsFlags; + GmvFlags; TecplotFlags; VtkFlags; SvgFlags; + Deal_II_IntermediateFlags } \ No newline at end of file diff --git a/include/deal.II/base/data_out_base.h b/include/deal.II/base/data_out_base.h index ac625dc3ec..99a3a12d17 100644 --- a/include/deal.II/base/data_out_base.h +++ b/include/deal.II/base/data_out_base.h @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -2316,55 +2317,14 @@ public: */ void set_default_format (const DataOutBase::OutputFormat default_format); - /** - * Set the flags to be used for output in OpenDX format. - */ - void set_flags (const DataOutBase::DXFlags &dx_flags); /** - * Set the flags to be used for output in UCD format. + * Set the flags to be used for output. This method expects flags to + * be a member of one of the child classes of OutputFlagsBase. */ - void set_flags (const DataOutBase::UcdFlags &ucd_flags); + template + void set_flags (const FlagType &flags); - /** - * Set the flags to be used for output in GNUPLOT format. - */ - void set_flags (const DataOutBase::GnuplotFlags &gnuplot_flags); - - /** - * Set the flags to be used for output in POVRAY format. - */ - void set_flags (const DataOutBase::PovrayFlags &povray_flags); - - /** - * Set the flags to be used for output in EPS output. - */ - void set_flags (const DataOutBase::EpsFlags &eps_flags); - - /** - * Set the flags to be used for output in GMV format. - */ - void set_flags (const DataOutBase::GmvFlags &gmv_flags); - - /** - * Set the flags to be used for output in Tecplot format. - */ - void set_flags (const DataOutBase::TecplotFlags &tecplot_flags); - - /** - * Set the flags to be used for output in VTK format. - */ - void set_flags (const DataOutBase::VtkFlags &vtk_flags); - - /** - * Set the flags to be used for output in SVG format. - */ - void set_flags (const DataOutBase::SvgFlags &svg_flags); - - /** - * Set the flags to be used for output in deal.II intermediate format. - */ - void set_flags (const DataOutBase::Deal_II_IntermediateFlags &deal_II_intermediate_flags); /** * A function that returns the same string as the respective function in the diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 53a7b6f338..ab69d353c0 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -7380,94 +7380,33 @@ DataOutInterface::set_default_format(const DataOutBase::OutputForm default_fmt = fmt; } - - -template -void -DataOutInterface::set_flags (const DataOutBase::DXFlags &flags) -{ - dx_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::UcdFlags &flags) -{ - ucd_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::GnuplotFlags &flags) -{ - gnuplot_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::PovrayFlags &flags) -{ - povray_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::EpsFlags &flags) -{ - eps_flags = flags; -} - - - template +template void -DataOutInterface::set_flags (const DataOutBase::GmvFlags &flags) +DataOutInterface::set_flags (const FlagType &flags) { - gmv_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::TecplotFlags &flags) -{ - tecplot_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::VtkFlags &flags) -{ - vtk_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::SvgFlags &flags) -{ - svg_flags = flags; -} - - - -template -void -DataOutInterface::set_flags (const DataOutBase::Deal_II_IntermediateFlags &flags) -{ - deal_II_intermediate_flags = flags; + // The price for not writing ten duplicates of this function is some loss in + // type safety. + if (typeid(flags) == typeid(dx_flags)) + dx_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(ucd_flags)) + ucd_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(povray_flags)) + povray_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(eps_flags)) + eps_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(gmv_flags)) + gmv_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(tecplot_flags)) + tecplot_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(vtk_flags)) + vtk_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(svg_flags)) + svg_flags = *reinterpret_cast(&flags); + else if (typeid(flags) == typeid(deal_II_intermediate_flags)) + deal_II_intermediate_flags = *reinterpret_cast(&flags); + else + Assert(false, ExcNotImplemented()); } diff --git a/source/base/data_out_base.inst.in b/source/base/data_out_base.inst.in index ea48dd342f..508d8aa6db 100644 --- a/source/base/data_out_base.inst.in +++ b/source/base/data_out_base.inst.in @@ -19,7 +19,7 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS #if deal_II_dimension <= deal_II_space_dimension template class DataOutInterface; template class DataOutReader; - + namespace DataOutBase \{ template struct Patch; @@ -133,3 +133,10 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS \} #endif } + +for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS; flag_type : OUTPUT_FLAG_TYPES) +{ + template + void + DataOutInterface::set_flags (const DataOutBase::flag_type &flags); +}