From: Wolfgang Bangerth Date: Wed, 14 Feb 2018 00:45:48 +0000 (-0700) Subject: Use std::uint8_t as the underlying data type for CellId. X-Git-Tag: v9.0.0-rc1~392^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24f81a48379b68a3ae3dce3943450a534617bf6a;p=dealii.git Use std::uint8_t as the underlying data type for CellId. --- diff --git a/include/deal.II/grid/cell_id.h b/include/deal.II/grid/cell_id.h index cc62c5b793..48a04cb797 100644 --- a/include/deal.II/grid/cell_id.h +++ b/include/deal.II/grid/cell_id.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef DEAL_II_WITH_P4EST #include @@ -76,10 +77,11 @@ public: * each entry denotes which child to pick from one refinement level to the * next, starting with the coarse cell, until we get to the cell represented * by the current object. Therefore, each entry should be a number between 0 - * and the number of children of a cell in the current space dimension. + * and the number of children of a cell in the current space dimension (i.e., + * GeometryInfo::max_children_per_cell). */ CellId(const unsigned int coarse_cell_id, - const std::vector &child_indices); + const std::vector &child_indices); /** * Construct a CellId object with a given @p coarse_cell_id and array of @@ -88,12 +90,13 @@ public: * each entry denotes which child to pick from one refinement level to the * next, starting with the coarse cell, until we get to the cell represented * by the current object. Therefore, each entry should be a number between 0 - * and the number of children of a cell in the current space dimension. - * @p child_indices shall have at least @p n_child_indices valid entries. + * and the number of children of a cell in the current space dimension (i.e., + * GeometryInfo::max_children_per_cell). The array + * @p child_indices must have at least @p n_child_indices valid entries. */ - CellId(const unsigned int coarse_cell_id, - const unsigned int n_child_indices, - const unsigned char *child_indices); + CellId(const unsigned int coarse_cell_id, + const unsigned int n_child_indices, + const std::uint8_t *child_indices); /** * Construct a CellId object with a given binary representation that was @@ -170,9 +173,9 @@ private: * the array can be extended. */ #ifdef DEAL_II_WITH_P4EST - std::array::max_level> child_indices; + std::array::max_level> child_indices; #else - std::array child_indices; + std::array child_indices; #endif friend std::istream &operator>> (std::istream &is, CellId &cid); @@ -192,10 +195,10 @@ std::ostream &operator<< (std::ostream &os, os << cid.coarse_cell_id << '_' << cid.n_child_indices << ':'; for (unsigned int i=0; i(cid.child_indices[i] + '0'); + // just have one digit, so we could write them as one character + // objects. it's probably clearer to write them as one-digit characters + // starting at '0' + os << static_cast('0' + cid.child_indices[i]); return os; } @@ -232,11 +235,11 @@ std::istream &operator>> (std::istream &is, is >> dummy; Assert(dummy==':', ExcMessage("invalid CellId")); - char value; + unsigned char value; for (unsigned int i=0; i> value; cid.child_indices[i] = value-'0'; } diff --git a/source/grid/cell_id.cc b/source/grid/cell_id.cc index 33736bd4a3..983ccf9b8a 100644 --- a/source/grid/cell_id.cc +++ b/source/grid/cell_id.cc @@ -38,7 +38,7 @@ CellId::CellId() CellId::CellId(const unsigned int coarse_cell_id, - const std::vector &id) + const std::vector &id) : coarse_cell_id(coarse_cell_id), n_child_indices(id.size()) @@ -50,9 +50,9 @@ CellId::CellId(const unsigned int coarse_cell_id, -CellId::CellId(const unsigned int coarse_cell_id, - const unsigned int n_child_indices, - const unsigned char *id) +CellId::CellId(const unsigned int coarse_cell_id, + const unsigned int n_child_indices, + const std::uint8_t *id) : coarse_cell_id(coarse_cell_id), n_child_indices(n_child_indices)