]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Allow to query the number of entries in a subsection and its children.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 6 Jul 2005 02:53:32 +0000 (02:53 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 6 Jul 2005 02:53:32 +0000 (02:53 +0000)
Use this to suppress output for completely empty subsections when printing.

git-svn-id: https://svn.dealii.org/trunk@11075 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/parameter_handler.cc
deal.II/doc/news/changes.html

index a0ecc7d7a69dfce244d6fb4783478201ec103675..30d2a6657f16075943490578c25a1d9f1bda60a1 100644 (file)
@@ -981,65 +981,73 @@ ParameterHandler::print_parameters_section (std::ostream      &out,
     }
 
 
-                                   // if there was text before and
-                                   // there are sections to come, put
-                                   // two newlines between the last
-                                   // entry and the first subsection
+                                   // if there was text before and there are
+                                   // sections to come, put two newlines
+                                   // between the last entry and the first
+                                   // subsection; also make sure that the
+                                   // subsections will be printed at all
+                                   // (i.e. at least one of them is non-empty)
   if ((pd->entries.size() != 0)
       &&
-      (pd->subsections.size() != 0))
+      (pd->subsections.size() != 0)
+      &&
+      (pd->accumulated_no_of_entries() != pd->entries.size()))
     out << std::endl << std::endl;
 
-                                  // now transverse subsections tree
+                                  // now transverse subsections tree; only
+                                  // plot a subsection, if it has at least
+                                  // one entry somewhere in it
   std::map<std::string, Section*>::const_iterator ptrss;
-  for (ptrss = pd->subsections.begin(); ptrss != pd->subsections.end(); ++ptrss)
-    {
-      switch (style) 
-       {
-         case Text:
-               out << std::setw(indent_level*2) << ""
-                   << "subsection " << ptrss->first << std::endl;
-               break;
-         case LaTeX:
-               out << std::endl
-                   << "\\item {\\bf "
-                   << "Subsection " << ptrss->first
-                   << "}" << std::endl
-                   << "\\begin{itemize}"
-                   << std::endl;
-               break;
-         default:
-               Assert (false, ExcNotImplemented());
-       };
-      enter_subsection (ptrss->first);
-      print_parameters_section (out, style, indent_level+1);
-      leave_subsection ();
-      switch (style) 
-       {
-         case Text:
-                                                // write end of
-                                                // subsection. one
-                                                // blank line after
-                                                // each subsection
-               out << std::setw(indent_level*2) << ""
-                   << "end" << std::endl
-                   << std::endl;
-
-                                                // if this is a toplevel
-                                                // subsection, then have two
-                                                // newlines
-               if (indent_level == 0)
-                 out << std::endl;
+  for (ptrss = pd->subsections.begin();
+       ptrss != pd->subsections.end(); ++ptrss)
+    if (ptrss->second->accumulated_no_of_entries() != 0)
+      {
+        switch (style) 
+          {
+            case Text:
+                  out << std::setw(indent_level*2) << ""
+                      << "subsection " << ptrss->first << std::endl;
+                  break;
+            case LaTeX:
+                  out << std::endl
+                      << "\\item {\\bf "
+                      << "Subsection " << ptrss->first
+                      << "}" << std::endl
+                      << "\\begin{itemize}"
+                      << std::endl;
+                  break;
+            default:
+                  Assert (false, ExcNotImplemented());
+          };
+        enter_subsection (ptrss->first);
+        print_parameters_section (out, style, indent_level+1);
+        leave_subsection ();
+        switch (style) 
+          {
+            case Text:
+                                                   // write end of
+                                                   // subsection. one
+                                                   // blank line after
+                                                   // each subsection
+                  out << std::setw(indent_level*2) << ""
+                      << "end" << std::endl
+                      << std::endl;
+
+                                                   // if this is a toplevel
+                                                   // subsection, then have two
+                                                   // newlines
+                  if (indent_level == 0)
+                    out << std::endl;
                
-               break;
-         case LaTeX:
-               out << "\\end{itemize}"
-                   << std::endl;
-               break;
-         default:
-               Assert (false, ExcNotImplemented());
-       };
-    };
+                  break;
+            case LaTeX:
+                  out << "\\end{itemize}"
+                      << std::endl;
+                  break;
+            default:
+                  Assert (false, ExcNotImplemented());
+          }
+      }
 }
 
 
@@ -1331,6 +1339,24 @@ ParameterHandler::Section::~Section ()
 
 
 
+unsigned int
+ParameterHandler::Section::
+accumulated_no_of_entries () const
+{
+                                   // number of entries in this section
+  unsigned int n = entries.size();
+
+                                   //  then accumulate over all children
+  for (std::map<std::string, Section*>::const_iterator
+         s = subsections.begin();
+       s != subsections.end(); ++s)
+    n += s->second->accumulated_no_of_entries();
+
+  return n;
+}
+
+
+
 unsigned int 
 ParameterHandler::Section::memory_consumption () const
 {
index 7d1b867a1192e0212c250f54eef2b47a0b8bad93..16abfc783601367f50a3a46dc11b663de42a7326 100644 (file)
@@ -225,6 +225,15 @@ inconvenience this causes.
        (WB, 2005/07/05)
        </p>
 
+  <li> <p>
+       Changed: The <code
+       class="member">ParameterHandler::print_parameters</code>
+       function now omits printing subsections if they and the contained
+       sub-subsections contain no entries.
+       <br>
+       (WB, 2005/07/05)
+       </p>
+
   <li> <p>
        Changed: Some of the dimension independent functions in the <code
        class="class">DataOutInterface</code> class have been moved into the

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.