]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move the get/set_bit() functions into namespace Utilities.
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 3 Feb 2021 18:14:07 +0000 (11:14 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 5 Feb 2021 16:24:56 +0000 (09:24 -0700)
include/deal.II/base/utilities.h
include/deal.II/grid/reference_cell.h
include/deal.II/grid/tria_accessor.templates.h

index b5453144929eaafb2a426273ac5e9bda25004a50..a7fda7316af997b9de21275784bf2e8c3cbd2e6d 100644 (file)
@@ -690,6 +690,20 @@ namespace Utilities
          T (&unpacked_object)[N],
          const bool allow_compression = true);
 
+  /**
+   * Check if the bit at position @p n in @p number is set.
+   */
+  bool
+  get_bit(const unsigned char number, const unsigned int n);
+
+
+  /**
+   * Set the bit at position @p n in @p number to value @p x.
+   */
+  void
+  set_bit(unsigned char &number, const unsigned int n, const bool x);
+
+
   /**
    * Convert an object of type `std::unique_ptr<From>` to an object of
    * type `std::unique_ptr<To>`, where it is assumed that we can cast
@@ -1336,6 +1350,32 @@ namespace Utilities
 
 
 
+  inline bool
+  get_bit(const unsigned char number, const unsigned int n)
+  {
+    AssertIndexRange(n, 8);
+
+    // source:
+    // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit
+    // "Checking a bit"
+    return (number >> n) & 1U;
+  }
+
+
+
+  inline void
+  set_bit(unsigned char &number, const unsigned int n, const bool x)
+  {
+    AssertIndexRange(n, 8);
+
+    // source:
+    // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit
+    // "Changing the nth bit to x"
+    number ^= (-static_cast<unsigned char>(x) ^ number) & (1U << n);
+  }
+
+
+
   template <typename Integer>
   std::vector<Integer>
   reverse_permutation(const std::vector<Integer> &permutation)
index e8a64b167edbfed6691b207304e8bb620bb5dc6f..f4c7f0bd6ab00512b635bcb635c1a263ccbb82d4 100644 (file)
@@ -21,6 +21,7 @@
 #include <deal.II/base/array_view.h>
 #include <deal.II/base/geometry_info.h>
 #include <deal.II/base/tensor.h>
+#include <deal.II/base/utilities.h>
 
 
 DEAL_II_NAMESPACE_OPEN
@@ -766,36 +767,6 @@ get_default_linear_mapping(const Triangulation<dim, spacedim> &triangulation);
 
 namespace internal
 {
-  /**
-   * Check if the bit at position @p n in @p number is set.
-   */
-  inline static bool
-  get_bit(const unsigned char number, const unsigned int n)
-  {
-    AssertIndexRange(n, 8);
-
-    // source:
-    // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit
-    // "Checking a bit"
-    return (number >> n) & 1U;
-  }
-
-
-
-  /**
-   * Set the bit at position @p n in @p number to value @p x.
-   */
-  inline static void
-  set_bit(unsigned char &number, const unsigned int n, const bool x)
-  {
-    AssertIndexRange(n, 8);
-
-    // source:
-    // https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit
-    // "Changing the nth bit to x"
-    number ^= (-static_cast<unsigned char>(x) ^ number) & (1U << n);
-  }
-
   /**
    * A namespace for geometric information on reference cells.
    */
@@ -1070,9 +1041,9 @@ namespace internal
         return GeometryInfo<dim>::face_to_cell_lines(
           face,
           line,
-          get_bit(face_orientation, 0),
-          get_bit(face_orientation, 2),
-          get_bit(face_orientation, 1));
+          Utilities::get_bit(face_orientation, 0),
+          Utilities::get_bit(face_orientation, 2),
+          Utilities::get_bit(face_orientation, 1));
       }
 
       unsigned int
@@ -1083,9 +1054,9 @@ namespace internal
         return GeometryInfo<dim>::face_to_cell_vertices(
           face,
           vertex,
-          get_bit(face_orientation, 0),
-          get_bit(face_orientation, 2),
-          get_bit(face_orientation, 1));
+          Utilities::get_bit(face_orientation, 0),
+          Utilities::get_bit(face_orientation, 2),
+          Utilities::get_bit(face_orientation, 1));
       }
     };
 
@@ -1506,9 +1477,9 @@ namespace internal
           {
             return GeometryInfo<3>::standard_to_real_face_line(
               line,
-              get_bit(face_orientation, 0),
-              get_bit(face_orientation, 2),
-              get_bit(face_orientation, 1));
+              Utilities::get_bit(face_orientation, 0),
+              Utilities::get_bit(face_orientation, 2),
+              Utilities::get_bit(face_orientation, 1));
           }
         else // TRI
           {
@@ -1556,9 +1527,9 @@ namespace internal
           {
             return GeometryInfo<3>::standard_to_real_face_vertex(
               vertex,
-              get_bit(face_orientation, 0),
-              get_bit(face_orientation, 2),
-              get_bit(face_orientation, 1));
+              Utilities::get_bit(face_orientation, 0),
+              Utilities::get_bit(face_orientation, 2),
+              Utilities::get_bit(face_orientation, 1));
           }
         else // Tri
           {
@@ -1680,9 +1651,9 @@ namespace internal
           {
             return GeometryInfo<3>::standard_to_real_face_line(
               line,
-              get_bit(face_orientation, 0),
-              get_bit(face_orientation, 2),
-              get_bit(face_orientation, 1));
+              Utilities::get_bit(face_orientation, 0),
+              Utilities::get_bit(face_orientation, 2),
+              Utilities::get_bit(face_orientation, 1));
           }
         else // TRI
           {
@@ -1730,9 +1701,9 @@ namespace internal
           {
             return GeometryInfo<3>::standard_to_real_face_vertex(
               vertex,
-              get_bit(face_orientation, 0),
-              get_bit(face_orientation, 2),
-              get_bit(face_orientation, 1));
+              Utilities::get_bit(face_orientation, 0),
+              Utilities::get_bit(face_orientation, 2),
+              Utilities::get_bit(face_orientation, 1));
           }
         else // TRI
           {
@@ -1827,9 +1798,9 @@ namespace internal
 
         return GeometryInfo<3>::standard_to_real_face_line(
           line,
-          get_bit(face_orientation, 0),
-          get_bit(face_orientation, 2),
-          get_bit(face_orientation, 1));
+          Utilities::get_bit(face_orientation, 0),
+          Utilities::get_bit(face_orientation, 2),
+          Utilities::get_bit(face_orientation, 1));
       }
 
       bool
@@ -1852,9 +1823,10 @@ namespace internal
             {false, false}},
            {{true, false}, {false, true}}}};
 
-        const bool face_orientation = get_bit(face_orientation_raw, 0);
-        const bool face_flip        = get_bit(face_orientation_raw, 2);
-        const bool face_rotation    = get_bit(face_orientation_raw, 1);
+        const bool face_orientation =
+          Utilities::get_bit(face_orientation_raw, 0);
+        const bool face_flip     = Utilities::get_bit(face_orientation_raw, 2);
+        const bool face_rotation = Utilities::get_bit(face_orientation_raw, 1);
 
         return (
           static_cast<bool>(line_orientation) ==
@@ -1879,9 +1851,9 @@ namespace internal
 
         return GeometryInfo<3>::standard_to_real_face_vertex(
           vertex,
-          get_bit(face_orientation, 0),
-          get_bit(face_orientation, 2),
-          get_bit(face_orientation, 1));
+          Utilities::get_bit(face_orientation, 0),
+          Utilities::get_bit(face_orientation, 2),
+          Utilities::get_bit(face_orientation, 1));
       }
 
       dealii::ReferenceCell
index a274e69e7aa2d89dee08956c831d3ac5479809c9..0030fbe8e46cd77c08c3005d9c3ac7825c60839e 100644 (file)
@@ -689,7 +689,7 @@ namespace internal
       face_orientation(const TriaAccessor<3, 3, 3> &accessor,
                        const unsigned int           face)
       {
-        return internal::get_bit(
+        return Utilities::get_bit(
           accessor.tria->levels[accessor.present_level]->face_orientations
             [accessor.present_index * GeometryInfo<3>::faces_per_cell + face],
           0 /*=orientation_bit*/);
@@ -739,7 +739,7 @@ namespace internal
                    ->face_orientations.size(),
                ExcInternalError());
 
-        return internal::get_bit(
+        return Utilities::get_bit(
           accessor.tria->levels[accessor.present_level]->face_orientations
             [accessor.present_index * GeometryInfo<3>::faces_per_cell + face],
           2 /*=flip_bit*/);
@@ -775,7 +775,7 @@ namespace internal
                    ->face_orientations.size(),
                ExcInternalError());
 
-        return internal::get_bit(
+        return Utilities::get_bit(
           accessor.tria->levels[accessor.present_level]->face_orientations
             [accessor.present_index * GeometryInfo<3>::faces_per_cell + face],
           1 /*=rotation_bit*/);
@@ -873,7 +873,7 @@ namespace internal
                  accessor.tria->levels[accessor.present_level]
                    ->face_orientations.size(),
                ExcInternalError());
-        internal::set_bit(
+        Utilities::set_bit(
           accessor.tria->levels[accessor.present_level]->face_orientations
             [accessor.present_index * GeometryInfo<3>::faces_per_cell + face],
           0 /*=orientation_bit*/,
@@ -906,7 +906,7 @@ namespace internal
                    ->face_orientations.size(),
                ExcInternalError());
 
-        internal::set_bit(
+        Utilities::set_bit(
           accessor.tria->levels[accessor.present_level]->face_orientations
             [accessor.present_index * GeometryInfo<3>::faces_per_cell + face],
           2 /*=flip_bit*/,
@@ -939,7 +939,7 @@ namespace internal
                    ->face_orientations.size(),
                ExcInternalError());
 
-        internal::set_bit(
+        Utilities::set_bit(
           accessor.tria->levels[accessor.present_level]->face_orientations
             [accessor.present_index * GeometryInfo<3>::faces_per_cell + face],
           1 /*=rotation_bit*/,

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.