From b913c1ea280f646c953dc6125714924feb862df5 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 10 Mar 1999 12:18:40 +0000 Subject: [PATCH] Make histogram class easily extendible. git-svn-id: https://svn.dealii.org/trunk@984 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/histogram.h | 33 +++++++++++++++++++- deal.II/deal.II/source/numerics/histogram.cc | 25 +++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/deal.II/deal.II/include/numerics/histogram.h b/deal.II/deal.II/include/numerics/histogram.h index 5d1ff78140..14d9e46f40 100644 --- a/deal.II/deal.II/include/numerics/histogram.h +++ b/deal.II/deal.II/include/numerics/histogram.h @@ -8,7 +8,7 @@ #include #include #include - +#include @@ -36,6 +36,14 @@ * Negative and zero values are sorted into the leftmost interval. * \end{itemize} * + * To keep programs extendible, you can use the two functions + * #get_interval_spacing_names# and #parse_interval_spacing#, which always + * give you a complete list of spacing formats presently supported and are + * able to generate the respective value of the #enum#. If you use them, + * you can write your program in a way such that it only needs to be + * recompiled to take effect of newly added formats, without changing your + * code. + * * * \subsection{Output formats} * @@ -117,6 +125,22 @@ class Histogram */ void write_gnuplot (ostream &out) const; + /** + * Return allowed names for the interval + * spacing as string. At present this + * is "linear|logarithmic". + */ + static string get_interval_spacing_names (); + + /** + * Get a string containing one of the + * names returned by the above function + * and return the respective value of + * #IntervalSpacing#. Throw an error + * if the string is no valid one. + */ + static IntervalSpacing parse_interval_spacing (const string &name); + /** * Exception. */ @@ -140,6 +164,13 @@ class Histogram int, int, << "The two array sizes " << arg1 << " and " << arg2 << " must match, but don't."); + /** + * Exception. + */ + DeclException1 (ExcInvalidName, + string, + << "The given name <" << arg1 + << "> does not match any of the known formats."); private: /** diff --git a/deal.II/deal.II/source/numerics/histogram.cc b/deal.II/deal.II/source/numerics/histogram.cc index 1862ec14d4..7e203a549e 100644 --- a/deal.II/deal.II/source/numerics/histogram.cc +++ b/deal.II/deal.II/source/numerics/histogram.cc @@ -249,6 +249,31 @@ void Histogram::write_gnuplot (ostream &out) const +string Histogram::get_interval_spacing_names () +{ + return "linear|logarithmic"; +}; + + + +Histogram::IntervalSpacing +Histogram::parse_interval_spacing (const string &name) +{ + if (name=="linear") + return linear; + else + if (name=="logarithmic") + return logarithmic; + else + { + AssertThrow (false, ExcInvalidName(name)); + + return linear; + }; +}; + + + // explicit instantiations for float template -- 2.39.5