use dynamic cast instead of c-style cast when casting from base type to derived class

This commit is contained in:
Axel Kohlmeyer
2022-04-10 18:18:06 -04:00
parent 39b316729b
commit 200b4f13c7
262 changed files with 669 additions and 676 deletions

View File

@ -247,8 +247,8 @@ void FixAdapt::post_constructor()
if (diamflag && atom->radius_flag) {
id_fix_diam = utils::strdup(id + std::string("_FIX_STORE_DIAM"));
fix_diam = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 1",
id_fix_diam,group->names[igroup]));
fix_diam = dynamic_cast<FixStore *>( modify->add_fix(fmt::format("{} {} STORE peratom 1 1",
id_fix_diam,group->names[igroup])));
if (fix_diam->restart_reset) fix_diam->restart_reset = 0;
else {
double *vec = fix_diam->vstore;
@ -265,8 +265,8 @@ void FixAdapt::post_constructor()
if (chgflag && atom->q_flag) {
id_fix_chg = utils::strdup(id + std::string("_FIX_STORE_CHG"));
fix_chg = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 1",
id_fix_chg,group->names[igroup]));
fix_chg = dynamic_cast<FixStore *>( modify->add_fix(fmt::format("{} {} STORE peratom 1 1",
id_fix_chg,group->names[igroup])));
if (fix_chg->restart_reset) fix_chg->restart_reset = 0;
else {
double *vec = fix_chg->vstore;
@ -348,7 +348,7 @@ void FixAdapt::init()
// if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style
if (utils::strmatch(force->pair_style,"^hybrid")) {
PairHybrid *pair = (PairHybrid *) force->pair;
auto pair = dynamic_cast<PairHybrid *>( force->pair);
for (i = ad->ilo; i <= ad->ihi; i++)
for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
if (!pair->check_ijtype(i,j,pstyle))
@ -431,16 +431,16 @@ void FixAdapt::init()
if (id_fix_diam) {
int ifix = modify->find_fix(id_fix_diam);
if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID");
fix_diam = (FixStore *) modify->fix[ifix];
fix_diam = dynamic_cast<FixStore *>( modify->fix[ifix]);
}
if (id_fix_chg) {
int ifix = modify->find_fix(id_fix_chg);
if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID");
fix_chg = (FixStore *) modify->fix[ifix];
fix_chg = dynamic_cast<FixStore *>( modify->fix[ifix]);
}
if (utils::strmatch(update->integrate_style,"^respa"))
nlevels_respa = ((Respa *) update->integrate)->nlevels;
nlevels_respa = (dynamic_cast<Respa *>( update->integrate))->nlevels;
}
/* ---------------------------------------------------------------------- */