* function.
*
* The function generates an
- * exception if an entry with
- * this name already exists, or
- * if the default value doesn't
- * match the given pattern.
+ * exception if the default value
+ * doesn't match the given
+ * pattern. An entry can be
+ * declared more than once
+ * without generating an error,
+ * for example to override an
+ * earlier default value.
*/
void declare_entry (const std::string &entry,
const std::string &default_value,
{
Section* p = get_present_defaults_subsection ();
- // assertions:
- // entry must not already exist
- Assert (p->entries.find (entry) == p->entries.end(),
- ExcEntryAlreadyExists (entry));
- // Default must match Pattern
+ // default must match Pattern
Assert (pattern.match (default_value),
ExcDefaultDoesNotMatchPattern(default_value,
pattern.description()));
+
+ // if the entry already existed,
+ // make sure we don't create a
+ // memory leak
+ if (p->entries.find (entry) != p->entries.end())
+ delete p->entries[entry].pattern;
- // entry doesn't yet exist, but
- // map::operator[] will create it
+ // if the entry didn't yet exist,
+ // but map::operator[] will create
+ // it
p->entries[entry].value = default_value;
p->entries[entry].documentation = documentation;
p->entries[entry].pattern = pattern.clone();
unsigned int longest_value = 0;
for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
longest_value
- = std::max ((size_t) longest_value,
+ = std::max (static_cast<size_t> (longest_value),
(pc->entries.find(ptr->first) != pc->entries.end()
?
pc->entries[ptr->first].value
<h3>base</h3>
<ol>
+ <li> <p> Changed: The <code
+ class="member">ParameterHandler::declare_entry</code> function
+ now allows to redeclare an entry that has already been
+ declared. This can be used to override a default value
+ previously set.
+ <br>
+ (WB 2002/09/03)
+ </p>
+
<li> <p> Improved: The <code
- class="member">ParameterHandler::declare_entry</code> now takes an
+ class="member">ParameterHandler::declare_entry</code> function now takes an
additional parameter (defaulting to the empty string) that can be used
to document the intent of a parameter. This string, together with the
default value of an entry, is written to the output by the <code
gerold_1.exe : gerold_1.g.$(OBJEXT) $(libraries)
roy_1.exe : roy_1.g.$(OBJEXT) $(libraries)
denis_1.exe : denis_1.g.$(OBJEXT) $(libraries)
+point_inside_1.exe : point_inside_1.g.$(OBJEXT) $(libraries)
unit_support_points.exe : unit_support_points.g.$(OBJEXT) $(libraries)
parameter_handler_1.exe : parameter_handler_1.g.$(OBJEXT) $(libraries)
parameter_handler_2.exe : parameter_handler_2.g.$(OBJEXT) $(libraries)
parameter_handler_3.exe : parameter_handler_3.g.$(OBJEXT) $(libraries)
parameter_handler_4.exe : parameter_handler_4.g.$(OBJEXT) $(libraries)
+parameter_handler_5.exe : parameter_handler_5.g.$(OBJEXT) $(libraries)
sparse_lu_decomposition_1.exe: sparse_lu_decomposition_1.g.$(OBJEXT) $(libraries)
block_sparse_matrix_1.exe:block_sparse_matrix_1.g.$(OBJEXT) $(libraries)
hyper_ball_3d.exe : hyper_ball_3d.g.$(OBJEXT) $(libraries)
tests = anna_1 anna_2 anna_3 anna_4 anna_5 anna_6 \
- geometry_info_1 \
+ geometry_info_1 point_inside_1 \
data_out_01 data_out_02 data_out_faces_01 data_out_faces_02 \
data_out_rotation_01 data_out_rotation_02 data_out_stack_01 \
dof_tools_00a \
unit_support_points \
parameter_handler_1 parameter_handler_2 \
parameter_handler_3 parameter_handler_4 \
+ parameter_handler_5 \
sparse_lu_decomposition_1 block_sparse_matrix_1 \
hyper_ball_3d cylinder
--- /dev/null
+//---------------------------- parameter_handler_5.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2003 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- parameter_handler_5.cc ---------------------------
+
+
+// ParameterHandler::declare_entry did not allow to redeclare an
+// entry. make sure this works now
+
+#include <base/logstream.h>
+#include <base/parameter_handler.h>
+#include <fstream>
+#include <iostream>
+
+
+int main ()
+{
+ try
+ {
+ std::ofstream logfile("parameter_handler_5.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ ParameterHandler prm;
+ prm.declare_entry ("int",
+ "1",
+ Patterns::Integer());
+ prm.declare_entry ("int",
+ "2",
+ Patterns::Integer());
+
+ prm.print_parameters (logfile, ParameterHandler::Text);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+
+ return 0;
+}