From: David Wells Date: Sun, 31 May 2015 21:50:18 +0000 (-0400) Subject: Add a base class for all output flag classes. X-Git-Tag: v8.3.0-rc1~136^2~9 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6169586dc6a8456b0941aeb54cf39a1b8050122;p=dealii.git Add a base class for all output flag classes. The base class uses "the curiously recurring template pattern" technique so that they can all share a default implementation of memory consumption (i.e., something akin to "return sizeof(*this)" works for child classes unless overridden). --- diff --git a/include/deal.II/base/data_out_base.h b/include/deal.II/base/data_out_base.h index 5aed2aff43..dfd50b4f5b 100644 --- a/include/deal.II/base/data_out_base.h +++ b/include/deal.II/base/data_out_base.h @@ -349,12 +349,70 @@ namespace DataOutBase //@} }; + + /** + * Base class describing common functionality between different output flags. + * + * This is implemented with the "Curiously Recurring Template Pattern"; + * derived classes use their own type to fill in the typename so that + * memory_consumption works correctly. See the Wikipedia page on the + * pattern for more information. + * + * @ingroup output + */ + template + struct OutputFlagsBase + { + /** + * Declare all flags with name and type as offered by this class, for use + * in input files. + * + * This method does nothing, but child classes may override this method to + * add fields to prm. + */ + static void declare_parameters (ParameterHandler &prm); + + /** + * Read the parameters declared in declare_parameters() and set the flags + * for this output format accordingly. + * + * This method does nothing, but child classes may override this method to + * add fields to prm. + */ + void parse_parameters (const ParameterHandler &prm); + + /** + * Return an estimate for the memory consumption, in bytes, of this + * object. This is not exact (but will usually be close) because calculating + * the memory usage of trees (e.g., std::map) is difficult. + */ + std::size_t memory_consumption () const; + }; + + + template + void OutputFlagsBase::declare_parameters (ParameterHandler &) + {} + + + template + void OutputFlagsBase::parse_parameters (const ParameterHandler &) + {} + + + template + std::size_t OutputFlagsBase::memory_consumption () const + { + return sizeof(FlagsType); + } + + /** * Flags controlling the details of output in OpenDX format. * * @ingroup output */ - struct DXFlags + struct DXFlags : public OutputFlagsBase { /** * Write neighbor information. This information is necessary for instance, @@ -416,7 +474,7 @@ namespace DataOutBase * * @ingroup output */ - struct UcdFlags + struct UcdFlags : public OutputFlagsBase { /** * Write a comment at the beginning of the file stating the date of @@ -462,7 +520,7 @@ namespace DataOutBase * * @ingroup output */ - struct GnuplotFlags + struct GnuplotFlags : public OutputFlagsBase { private: /** @@ -506,7 +564,7 @@ namespace DataOutBase * * @ingroup output */ - struct PovrayFlags + struct PovrayFlags : public OutputFlagsBase { /** * Normal vector interpolation, if set to true @@ -566,7 +624,7 @@ namespace DataOutBase * * @ingroup output */ - struct EpsFlags + struct EpsFlags : public OutputFlagsBase { /** * This denotes the number of the data vector which shall be used for @@ -810,7 +868,7 @@ namespace DataOutBase * * @ingroup output */ - struct GmvFlags + struct GmvFlags : public OutputFlagsBase { private: /** @@ -853,7 +911,7 @@ namespace DataOutBase * * @ingroup output */ - struct TecplotFlags + struct TecplotFlags : public OutputFlagsBase { public: @@ -904,7 +962,7 @@ namespace DataOutBase * * @ingroup output */ - struct VtkFlags + struct VtkFlags : public OutputFlagsBase { public: /** @@ -980,7 +1038,7 @@ namespace DataOutBase /** * Flags for SVG output. */ - struct SvgFlags + struct SvgFlags : public OutputFlagsBase { public: /** @@ -1044,7 +1102,7 @@ namespace DataOutBase * * @ingroup output */ - struct Deal_II_IntermediateFlags + struct Deal_II_IntermediateFlags : public OutputFlagsBase { /** * An indicator of the currect file format version used to write