]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Rearrange code for better readability. 8663/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 27 Aug 2019 23:16:43 +0000 (17:16 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 28 Aug 2019 03:32:33 +0000 (21:32 -0600)
Specifically, use a 'switch' statement instead of a sequence of if-else-if,
and move the simplest case to the top. So far, the simplest case was just
the fall-through, but it actually has a name -- so I test that as well
and make the fall-through into an assertion.

include/deal.II/numerics/data_out_dof_data.templates.h

index 26697b01021e15de1a71e6ca86171eee9098ec47..f0d1459e458cca2424af9d07264818476b608f4b 100644 (file)
@@ -1348,89 +1348,105 @@ DataOut_DoFData<DoFHandlerType, patch_dim, patch_space_dim>::
     for (unsigned int i = 0; i < (*d)->n_output_variables;)
       // see what kind of data we have here. note that for the purpose of the
       // current function all we care about is vector data
-      if ((*d)->data_component_interpretation[i] ==
-          DataComponentInterpretation::component_is_part_of_vector)
+      switch ((*d)->data_component_interpretation[i])
         {
-          // ensure that there is a continuous number of next space_dim
-          // components that all deal with vectors
-          Assert(i + patch_space_dim <= (*d)->n_output_variables,
-                 Exceptions::DataOutImplementation::ExcInvalidVectorDeclaration(
-                   i, (*d)->names[i]));
-          for (unsigned int dd = 1; dd < patch_space_dim; ++dd)
-            Assert(
-              (*d)->data_component_interpretation[i + dd] ==
-                DataComponentInterpretation::component_is_part_of_vector,
-              Exceptions::DataOutImplementation::ExcInvalidVectorDeclaration(
-                i, (*d)->names[i]));
-
-          // all seems alright, so figure out whether there is a common name to
-          // these components. if not, leave the name empty and let the output
-          // format writer decide what to do here
-          std::string name = (*d)->names[i];
-          for (unsigned int dd = 1; dd < patch_space_dim; ++dd)
-            if (name != (*d)->names[i + dd])
-              {
-                name = "";
-                break;
-              }
-
-          // finally add a corresponding range
-          ranges.emplace_back(std::forward_as_tuple(
-            output_component,
-            output_component + patch_space_dim - 1,
-            name,
-            DataComponentInterpretation::component_is_part_of_vector));
-
-          // increase the 'component' counter by the appropriate amount, same
-          // for 'i', since we have already dealt with all these components
-          output_component += patch_space_dim;
-          i += patch_space_dim;
-        }
-      else if ((*d)->data_component_interpretation[i] ==
-               DataComponentInterpretation::component_is_part_of_tensor)
-        {
-          const unsigned int size = patch_space_dim * patch_space_dim;
-          // ensure that there is a continuous number of next
-          // space_dim*space_dim components that all deal with tensors
-          Assert(i + size <= (*d)->n_output_variables,
-                 Exceptions::DataOutImplementation::ExcInvalidTensorDeclaration(
-                   i, (*d)->names[i]));
-          for (unsigned int dd = 1; dd < size; ++dd)
-            Assert(
-              (*d)->data_component_interpretation[i + dd] ==
-                DataComponentInterpretation::component_is_part_of_tensor,
-              Exceptions::DataOutImplementation::ExcInvalidTensorDeclaration(
-                i, (*d)->names[i]));
-
-          // all seems alright, so figure out whether there is a common name to
-          // these components. if not, leave the name empty and let the output
-          // format writer decide what to do here
-          std::string name = (*d)->names[i];
-          for (unsigned int dd = 1; dd < size; ++dd)
-            if (name != (*d)->names[i + dd])
-              {
-                name = "";
-                break;
-              }
-
-          // finally add a corresponding range
-          ranges.emplace_back(std::forward_as_tuple(
-            output_component,
-            output_component + size - 1,
-            name,
-            DataComponentInterpretation::component_is_part_of_tensor));
-
-          // increase the 'component' counter by the appropriate amount, same
-          // for 'i', since we have already dealt with all these components
-          output_component += size;
-          i += size;
-        }
-      else
-        {
-          // just move one component forward by one, or two if the vector
-          // happens to be complex-valued
-          ++i;
-          output_component += ((*d)->is_complex_valued() ? 2 : 1);
+          case DataComponentInterpretation::component_is_scalar:
+            {
+              // just move one component forward by one, or two if the component
+              // happens to be complex-valued
+              ++i;
+              output_component += ((*d)->is_complex_valued() ? 2 : 1);
+
+              break;
+            }
+
+          case DataComponentInterpretation::component_is_part_of_vector:
+            {
+              // ensure that there is a continuous number of next space_dim
+              // components that all deal with vectors
+              Assert(
+                i + patch_space_dim <= (*d)->n_output_variables,
+                Exceptions::DataOutImplementation::ExcInvalidVectorDeclaration(
+                  i, (*d)->names[i]));
+              for (unsigned int dd = 1; dd < patch_space_dim; ++dd)
+                Assert(
+                  (*d)->data_component_interpretation[i + dd] ==
+                    DataComponentInterpretation::component_is_part_of_vector,
+                  Exceptions::DataOutImplementation::
+                    ExcInvalidVectorDeclaration(i, (*d)->names[i]));
+
+              // all seems alright, so figure out whether there is a common name
+              // to these components. if not, leave the name empty and let the
+              // output format writer decide what to do here
+              std::string name = (*d)->names[i];
+              for (unsigned int dd = 1; dd < patch_space_dim; ++dd)
+                if (name != (*d)->names[i + dd])
+                  {
+                    name = "";
+                    break;
+                  }
+
+              // finally add a corresponding range
+              ranges.emplace_back(std::forward_as_tuple(
+                output_component,
+                output_component + patch_space_dim - 1,
+                name,
+                DataComponentInterpretation::component_is_part_of_vector));
+
+              // increase the 'component' counter by the appropriate amount,
+              // same for 'i', since we have already dealt with all these
+              // components
+              output_component += patch_space_dim;
+              i += patch_space_dim;
+
+              break;
+            }
+
+          case DataComponentInterpretation::component_is_part_of_tensor:
+            {
+              const unsigned int size = patch_space_dim * patch_space_dim;
+              // ensure that there is a continuous number of next
+              // space_dim*space_dim components that all deal with tensors
+              Assert(
+                i + size <= (*d)->n_output_variables,
+                Exceptions::DataOutImplementation::ExcInvalidTensorDeclaration(
+                  i, (*d)->names[i]));
+              for (unsigned int dd = 1; dd < size; ++dd)
+                Assert(
+                  (*d)->data_component_interpretation[i + dd] ==
+                    DataComponentInterpretation::component_is_part_of_tensor,
+                  Exceptions::DataOutImplementation::
+                    ExcInvalidTensorDeclaration(i, (*d)->names[i]));
+
+              // all seems alright, so figure out whether there is a common name
+              // to these components. if not, leave the name empty and let the
+              // output format writer decide what to do here
+              std::string name = (*d)->names[i];
+              for (unsigned int dd = 1; dd < size; ++dd)
+                if (name != (*d)->names[i + dd])
+                  {
+                    name = "";
+                    break;
+                  }
+
+              // finally add a corresponding range
+              ranges.emplace_back(std::forward_as_tuple(
+                output_component,
+                output_component + size - 1,
+                name,
+                DataComponentInterpretation::component_is_part_of_tensor));
+
+              // increase the 'component' counter by the appropriate amount,
+              // same for 'i', since we have already dealt with all these
+              // components
+              output_component += size;
+              i += size;
+
+              break;
+            }
+
+          default:
+            Assert(false, ExcNotImplemented());
         }
 
   // note that we do not have to traverse the list of cell data here because

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.