From 98cbf9eb2d8406d216f07e03c3760ff0cb385c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@dune-project.org> Date: Thu, 8 Oct 2009 09:19:48 +0000 Subject: [PATCH] Base class templates for function classes. This is meant as proposal for fs#597. [[Imported from SVN: r5626]] --- common/Makefile.am | 2 +- common/function.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 common/function.hh diff --git a/common/Makefile.am b/common/Makefile.am index b65316173..41b9d41e3 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -24,7 +24,7 @@ commoninclude_HEADERS = alignment.hh array.hh \ bartonnackmanifcheck.hh binaryfunctions.hh lru.hh fassign.hh \ static_assert.hh smallobject.hh version.hh \ float_cmp.cc float_cmp.hh nullptr.hh \ - forloop.hh + forloop.hh function.hh if EXPRESSIONTEMPLATES commoninclude_HEADERS += exprtmpl.hh exprtmpl/scalar.inc exprtmpl/exprexpr.inc diff --git a/common/function.hh b/common/function.hh new file mode 100644 index 000000000..7514a3807 --- /dev/null +++ b/common/function.hh @@ -0,0 +1,66 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: +#ifndef DUNE_FUNCTION_HH +#define DUNE_FUNCTION_HH + + +namespace Dune { + + /** @addtogroup Common + @{ + */ + + /*! \file + \brief Simple base class templates for functions. + */ + + /** + * \brief Base class template for function classes + * + * \tparam Domain Type of input variable. This could be some 'const T' or 'const T&'. + * + * \tparam Range Type of output variable. This should be some non-const 'T&' to allow to return results. + */ + template <class Domain, class Range> + class Function + { + public: + + /** + * \brief Function evaluation. + * + * \param x Argument for function evaluation. + * \param y Result of function evaluation. + */ + void evaluate(Domain x, Range y) const; + }; // end of Function class + + + + /** + * \brief Virtual base class template for function classes. + * + * \tparam DomainType The type of the input variable is 'const DomainType &' + * + * \tparam RangeType The type of the output variable is 'RangeType &' + */ + template <class DomainType, class RangeType> + class VirtualFunction : + public Function<const DomainType&, RangeType&> + { + public: + + /** + * \brief Function evaluation. + * + * \param x Argument for function evaluation. + * \param y Result of function evaluation. + */ + virtual void evaluate(const DomainType& x, RangeType& y) const = 0; + }; // end of VirtualFunction class + + /** @} end documentation */ + +} // end namespace + +#endif -- GitLab