From 5a1644544b5b49cb5e8bebd4995ceadcbf2add2a Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 13 Feb 2018 12:58:37 -0700 Subject: [PATCH] Use std::uint8_t for refinement cases. --- include/deal.II/base/geometry_info.h | 40 ++++++++++--------- .../deal.II/grid/tria_accessor.templates.h | 10 ++--- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/include/deal.II/base/geometry_info.h b/include/deal.II/base/geometry_info.h index 8a22206905..9c7c05ddef 100644 --- a/include/deal.II/base/geometry_info.h +++ b/include/deal.II/base/geometry_info.h @@ -21,6 +21,10 @@ #include #include +#include + + + DEAL_II_NAMESPACE_OPEN #ifndef DOXYGEN @@ -335,7 +339,7 @@ struct RefinementPossibilities /** * Perform isotropic refinement. */ - isotropic_refinement = static_cast(-1) + isotropic_refinement = static_cast(-1) }; }; @@ -606,20 +610,20 @@ public: * a bit field. To avoid implicit conversions to and from integral values, * this constructor is marked as explicit. */ - explicit RefinementCase (const unsigned char refinement_case); + explicit RefinementCase (const std::uint8_t refinement_case); /** * Return the numeric value stored by this class. While the presence of this * operator might seem dangerous, it is useful in cases where one would like * to have code like switch (refinement_flag)... case * RefinementCase::cut_x: ... , which can be written as - * switch (static_cast@(refinement_flag). + * switch (static_cast@(refinement_flag). * Another application is to use an object of the current type as an index * into an array; however, this use is deprecated as it assumes a certain * mapping from the symbolic flags defined in the RefinementPossibilities * base class to actual numerical values (the array indices). */ - operator unsigned char () const; + operator std::uint8_t () const; /** * Return the union of the refinement flags represented by the current @@ -677,7 +681,7 @@ private: * Store the refinement case as a bit field with as many bits as are * necessary in any given dimension. */ -unsigned char value : +std::uint8_t value : (dim > 0 ? dim : 1); }; @@ -721,7 +725,7 @@ namespace internal /** * Refine isotropically. */ - case_isotropic = static_cast(-1) + case_isotropic = static_cast(-1) }; }; @@ -976,13 +980,13 @@ namespace internal * this operator might seem dangerous, it is useful in cases where one * would like to have code like switch (subface_case)... case * SubfaceCase::case_x: ... , which can be written as switch - * (static_cast@(subface_case). Another application + * (static_cast@(subface_case). Another application * is to use an object of the current type as an index into an array; * however, this use is deprecated as it assumes a certain mapping from * the symbolic flags defined in the SubfacePossibilities base class to * actual numerical values (the array indices). */ - operator unsigned char () const; + operator std::uint8_t () const; /** * Return the amount of memory occupied by an object of this type. @@ -1002,7 +1006,7 @@ namespace internal * Store the refinement case as a bit field with as many bits as are * necessary in any given dimension. */ - unsigned char value : + std::uint8_t value : (dim == 3 ? 4 : 1); }; @@ -2349,7 +2353,7 @@ namespace internal template inline - SubfaceCase::operator unsigned char () const + SubfaceCase::operator std::uint8_t () const { return value; } @@ -2364,7 +2368,7 @@ RefinementCase RefinementCase::cut_axis (const unsigned int) { Assert (false, ExcInternalError()); - return static_cast(-1); + return static_cast(-1); } @@ -2441,7 +2445,7 @@ RefinementCase (const typename RefinementPossibilities::Possibilities refin template inline -RefinementCase::RefinementCase (const unsigned char refinement_case) +RefinementCase::RefinementCase (const std::uint8_t refinement_case) : value (refinement_case) { @@ -2458,7 +2462,7 @@ RefinementCase::RefinementCase (const unsigned char refinement_case) template inline -RefinementCase::operator unsigned char () const +RefinementCase::operator std::uint8_t () const { return value; } @@ -2470,7 +2474,7 @@ inline RefinementCase RefinementCase::operator | (const RefinementCase &r) const { - return RefinementCase(static_cast (value | r.value)); + return RefinementCase(static_cast (value | r.value)); } @@ -2480,7 +2484,7 @@ inline RefinementCase RefinementCase::operator & (const RefinementCase &r) const { - return RefinementCase(static_cast (value & r.value)); + return RefinementCase(static_cast (value & r.value)); } @@ -2490,7 +2494,7 @@ inline RefinementCase RefinementCase::operator ~ () const { - return RefinementCase(static_cast ( + return RefinementCase(static_cast ( (~value) & RefinementPossibilities::isotropic_refinement)); } @@ -2514,8 +2518,8 @@ void RefinementCase::serialize (Archive &ar, const unsigned int) { // serialization can't deal with bitfields, so copy from/to a full sized - // unsigned char - unsigned char uchar_value = value; + // std::uint8_t + std::uint8_t uchar_value = value; ar &uchar_value; value = uchar_value; } diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 582546d793..136bac339e 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -1460,7 +1460,7 @@ isotropic_child_index (const unsigned int i) const case 2: { const RefinementCase<2> - this_refinement_case (static_cast(refinement_case())); + this_refinement_case (static_cast(refinement_case())); Assert (this_refinement_case != RefinementCase<2>::no_refinement, TriaAccessorExceptions::ExcCellHasNoChildren()); @@ -1513,8 +1513,8 @@ TriaAccessor::refinement_case() const // which this part of // the code is dead // anyway) - static_cast(RefinementCase<1>::cut_x) : - static_cast(RefinementCase<1>::no_refinement))); + static_cast(RefinementCase<1>::cut_x) : + static_cast(RefinementCase<1>::no_refinement))); default: Assert (static_cast (this->present_index) < @@ -1567,7 +1567,7 @@ isotropic_child (const unsigned int i) const case 2: { const RefinementCase<2> - this_refinement_case (static_cast(refinement_case())); + this_refinement_case (static_cast(refinement_case())); Assert (this_refinement_case != RefinementCase<2>::no_refinement, TriaAccessorExceptions::ExcCellHasNoChildren()); @@ -3447,7 +3447,7 @@ CellAccessor<3>::subface_case(const unsigned int face_no) const Assert(active(), TriaAccessorExceptions::ExcCellNotActive()); Assert(face_no::faces_per_cell, ExcIndexRange(face_no,0,GeometryInfo<3>::faces_per_cell)); - switch (static_cast (face(face_no)->refinement_case())) + switch (static_cast (face(face_no)->refinement_case())) { case RefinementCase<3>::no_refinement: return dealii::internal::SubfaceCase<3>::case_none; -- 2.39.5