remove make factory function templates from class and make them static functions

This commit is contained in:
Axel Kohlmeyer
2022-02-11 16:00:12 -05:00
parent ce83ca1efd
commit 04cff0b47b
4 changed files with 46 additions and 89 deletions

View File

@ -36,6 +36,39 @@
using namespace LAMMPS_NS;
// templates for factory functions:
// there will be one instance for each style keyword in the style_xxx.h file
template <typename T> static Pair *pair_creator(LAMMPS *lmp)
{
return new T(lmp);
}
template <typename T> static Bond *bond_creator(LAMMPS *lmp)
{
return new T(lmp);
}
template <typename T> static Angle *angle_creator(LAMMPS *lmp)
{
return new T(lmp);
}
template <typename T> static Dihedral *dihedral_creator(LAMMPS *lmp)
{
return new T(lmp);
}
template <typename T> static Improper *improper_creator(LAMMPS *lmp)
{
return new T(lmp);
}
template <typename T> static KSpace *kspace_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ---------------------------------------------------------------------- */
Force::Force(LAMMPS *lmp) : Pointers(lmp)
@ -280,16 +313,6 @@ Pair *Force::new_pair(const std::string &style, int trysuffix, int &sflag)
return nullptr;
}
/* ----------------------------------------------------------------------
one instance per pair style in style_pair.h
------------------------------------------------------------------------- */
template <typename T>
Pair *Force::pair_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ----------------------------------------------------------------------
return ptr to Pair class if matches word or matches hybrid sub-style
if exact, then style name must be exact match to word
@ -391,16 +414,6 @@ Bond *Force::new_bond(const std::string &style, int trysuffix, int &sflag)
return nullptr;
}
/* ----------------------------------------------------------------------
one instance per bond style in style_bond.h
------------------------------------------------------------------------- */
template <typename T>
Bond *Force::bond_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ----------------------------------------------------------------------
return ptr to current bond class or hybrid sub-class if matches style
------------------------------------------------------------------------- */
@ -468,16 +481,6 @@ Angle *Force::new_angle(const std::string &style, int trysuffix, int &sflag)
return nullptr;
}
/* ----------------------------------------------------------------------
one instance per angle style in style_angle.h
------------------------------------------------------------------------- */
template <typename T>
Angle *Force::angle_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ----------------------------------------------------------------------
return ptr to current angle class or hybrid sub-class if matches style
------------------------------------------------------------------------- */
@ -545,16 +548,6 @@ Dihedral *Force::new_dihedral(const std::string &style, int trysuffix, int &sfla
return nullptr;
}
/* ----------------------------------------------------------------------
one instance per dihedral style in style_dihedral.h
------------------------------------------------------------------------- */
template <typename T>
Dihedral *Force::dihedral_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ----------------------------------------------------------------------
return ptr to current angle class or hybrid sub-class if matches style
------------------------------------------------------------------------- */
@ -622,16 +615,6 @@ Improper *Force::new_improper(const std::string &style, int trysuffix, int &sfla
return nullptr;
}
/* ----------------------------------------------------------------------
one instance per improper style in style_improper.h
------------------------------------------------------------------------- */
template <typename T>
Improper *Force::improper_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ----------------------------------------------------------------------
return ptr to current improper class or hybrid sub-class if matches style
------------------------------------------------------------------------- */
@ -699,16 +682,6 @@ KSpace *Force::new_kspace(const std::string &style, int trysuffix, int &sflag)
return nullptr;
}
/* ----------------------------------------------------------------------
one instance per kspace style in style_kspace.h
------------------------------------------------------------------------- */
template <typename T>
KSpace *Force::kspace_creator(LAMMPS *lmp)
{
return new T(lmp);
}
/* ----------------------------------------------------------------------
return ptr to Kspace class if matches word
if exact, then style name must be exact match to word

View File

@ -153,12 +153,6 @@ class Force : protected Pointers {
private:
void create_factories();
template <typename T> static Pair *pair_creator(LAMMPS *);
template <typename T> static Bond *bond_creator(LAMMPS *);
template <typename T> static Angle *angle_creator(LAMMPS *);
template <typename T> static Dihedral *dihedral_creator(LAMMPS *);
template <typename T> static Improper *improper_creator(LAMMPS *);
template <typename T> static KSpace *kspace_creator(LAMMPS *);
};
} // namespace LAMMPS_NS

View File

@ -37,6 +37,19 @@ using namespace FixConst;
#define DELTA 4
#define BIG 1.0e20
// templates for factory functions:
// there will be one instance for each style keyword in the style_xxx.h file
template <typename T> static Fix *fix_creator(LAMMPS *lmp, int narg, char **arg)
{
return new T(lmp,narg,arg);
}
template <typename T> static Compute *compute_creator(LAMMPS *lmp, int narg, char **arg)
{
return new T(lmp,narg,arg);
}
/* ---------------------------------------------------------------------- */
Modify::Modify(LAMMPS *lmp) : Pointers(lmp)
@ -1024,16 +1037,6 @@ Fix *Modify::replace_fix(const std::string &oldfix, const std::string &fixcmd, i
return replace_fix(oldfix.c_str(),args.size(),newarg.data(),trysuffix);
}
/* ----------------------------------------------------------------------
one instance per fix in style_fix.h
------------------------------------------------------------------------- */
template <typename T>
Fix *Modify::fix_creator(LAMMPS *lmp, int narg, char **arg)
{
return new T(lmp,narg,arg);
}
/* ----------------------------------------------------------------------
modify a Fix's parameters
------------------------------------------------------------------------- */
@ -1310,17 +1313,6 @@ Compute *Modify::add_compute(const std::string &computecmd, int trysuffix)
return add_compute(args.size(),newarg.data(),trysuffix);
}
/* ----------------------------------------------------------------------
one instance per compute in style_compute.h
------------------------------------------------------------------------- */
template <typename T>
Compute *Modify::compute_creator(LAMMPS *lmp, int narg, char **arg)
{
return new T(lmp,narg,arg);
}
/* ----------------------------------------------------------------------
modify a Compute's parameters
------------------------------------------------------------------------- */

View File

@ -201,8 +201,6 @@ class Modify : protected Pointers {
protected:
void create_factories();
template <typename T> static Compute *compute_creator(LAMMPS *, int, char **);
template <typename T> static Fix *fix_creator(LAMMPS *, int, char **);
};
} // namespace LAMMPS_NS