generalize meta command processing. make better use of std::string class
This commit is contained in:
150
src/input.cpp
150
src/input.cpp
@ -749,77 +749,78 @@ int Input::execute_command()
|
|||||||
{
|
{
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
|
|
||||||
if (!strcmp(command,"clear")) clear();
|
std::string mycmd = command;
|
||||||
else if (!strcmp(command,"echo")) echo();
|
if (mycmd == "clear") clear();
|
||||||
else if (!strcmp(command,"if")) ifthenelse();
|
else if (mycmd == "echo") echo();
|
||||||
else if (!strcmp(command,"include")) include();
|
else if (mycmd == "if") ifthenelse();
|
||||||
else if (!strcmp(command,"jump")) jump();
|
else if (mycmd == "include") include();
|
||||||
else if (!strcmp(command,"label")) label();
|
else if (mycmd == "jump") jump();
|
||||||
else if (!strcmp(command,"log")) log();
|
else if (mycmd == "label") label();
|
||||||
else if (!strcmp(command,"next")) next_command();
|
else if (mycmd == "log") log();
|
||||||
else if (!strcmp(command,"partition")) partition();
|
else if (mycmd == "next") next_command();
|
||||||
else if (!strcmp(command,"print")) print();
|
else if (mycmd == "partition") partition();
|
||||||
else if (!strcmp(command,"python")) python();
|
else if (mycmd == "print") print();
|
||||||
else if (!strcmp(command,"quit")) quit();
|
else if (mycmd == "python") python();
|
||||||
else if (!strcmp(command,"shell")) shell();
|
else if (mycmd == "quit") quit();
|
||||||
else if (!strcmp(command,"variable")) variable_command();
|
else if (mycmd == "shell") shell();
|
||||||
|
else if (mycmd == "variable") variable_command();
|
||||||
|
|
||||||
else if (!strcmp(command,"angle_coeff")) angle_coeff();
|
else if (mycmd == "angle_coeff") angle_coeff();
|
||||||
else if (!strcmp(command,"angle_style")) angle_style();
|
else if (mycmd == "angle_style") angle_style();
|
||||||
else if (!strcmp(command,"atom_modify")) atom_modify();
|
else if (mycmd == "atom_modify") atom_modify();
|
||||||
else if (!strcmp(command,"atom_style")) atom_style();
|
else if (mycmd == "atom_style") atom_style();
|
||||||
else if (!strcmp(command,"bond_coeff")) bond_coeff();
|
else if (mycmd == "bond_coeff") bond_coeff();
|
||||||
else if (!strcmp(command,"bond_style")) bond_style();
|
else if (mycmd == "bond_style") bond_style();
|
||||||
else if (!strcmp(command,"bond_write")) bond_write();
|
else if (mycmd == "bond_write") bond_write();
|
||||||
else if (!strcmp(command,"boundary")) boundary();
|
else if (mycmd == "boundary") boundary();
|
||||||
else if (!strcmp(command,"box")) box();
|
else if (mycmd == "box") box();
|
||||||
else if (!strcmp(command,"comm_modify")) comm_modify();
|
else if (mycmd == "comm_modify") comm_modify();
|
||||||
else if (!strcmp(command,"comm_style")) comm_style();
|
else if (mycmd == "comm_style") comm_style();
|
||||||
else if (!strcmp(command,"compute")) compute();
|
else if (mycmd == "compute") compute();
|
||||||
else if (!strcmp(command,"compute_modify")) compute_modify();
|
else if (mycmd == "compute_modify") compute_modify();
|
||||||
else if (!strcmp(command,"dielectric")) dielectric();
|
else if (mycmd == "dielectric") dielectric();
|
||||||
else if (!strcmp(command,"dihedral_coeff")) dihedral_coeff();
|
else if (mycmd == "dihedral_coeff") dihedral_coeff();
|
||||||
else if (!strcmp(command,"dihedral_style")) dihedral_style();
|
else if (mycmd == "dihedral_style") dihedral_style();
|
||||||
else if (!strcmp(command,"dimension")) dimension();
|
else if (mycmd == "dimension") dimension();
|
||||||
else if (!strcmp(command,"dump")) dump();
|
else if (mycmd == "dump") dump();
|
||||||
else if (!strcmp(command,"dump_modify")) dump_modify();
|
else if (mycmd == "dump_modify") dump_modify();
|
||||||
else if (!strcmp(command,"fix")) fix();
|
else if (mycmd == "fix") fix();
|
||||||
else if (!strcmp(command,"fix_modify")) fix_modify();
|
else if (mycmd == "fix_modify") fix_modify();
|
||||||
else if (!strcmp(command,"group")) group_command();
|
else if (mycmd == "group") group_command();
|
||||||
else if (!strcmp(command,"improper_coeff")) improper_coeff();
|
else if (mycmd == "improper_coeff") improper_coeff();
|
||||||
else if (!strcmp(command,"improper_style")) improper_style();
|
else if (mycmd == "improper_style") improper_style();
|
||||||
else if (!strcmp(command,"kspace_modify")) kspace_modify();
|
else if (mycmd == "kspace_modify") kspace_modify();
|
||||||
else if (!strcmp(command,"kspace_style")) kspace_style();
|
else if (mycmd == "kspace_style") kspace_style();
|
||||||
else if (!strcmp(command,"labelmap")) labelmap();
|
else if (mycmd == "labelmap") labelmap();
|
||||||
else if (!strcmp(command,"lattice")) lattice();
|
else if (mycmd == "lattice") lattice();
|
||||||
else if (!strcmp(command,"mass")) mass();
|
else if (mycmd == "mass") mass();
|
||||||
else if (!strcmp(command,"min_modify")) min_modify();
|
else if (mycmd == "min_modify") min_modify();
|
||||||
else if (!strcmp(command,"min_style")) min_style();
|
else if (mycmd == "min_style") min_style();
|
||||||
else if (!strcmp(command,"molecule")) molecule();
|
else if (mycmd == "molecule") molecule();
|
||||||
else if (!strcmp(command,"neigh_modify")) neigh_modify();
|
else if (mycmd == "neigh_modify") neigh_modify();
|
||||||
else if (!strcmp(command,"neighbor")) neighbor_command();
|
else if (mycmd == "neighbor") neighbor_command();
|
||||||
else if (!strcmp(command,"newton")) newton();
|
else if (mycmd == "newton") newton();
|
||||||
else if (!strcmp(command,"package")) package();
|
else if (mycmd == "package") package();
|
||||||
else if (!strcmp(command,"pair_coeff")) pair_coeff();
|
else if (mycmd == "pair_coeff") pair_coeff();
|
||||||
else if (!strcmp(command,"pair_modify")) pair_modify();
|
else if (mycmd == "pair_modify") pair_modify();
|
||||||
else if (!strcmp(command,"pair_style")) pair_style();
|
else if (mycmd == "pair_style") pair_style();
|
||||||
else if (!strcmp(command,"pair_write")) pair_write();
|
else if (mycmd == "pair_write") pair_write();
|
||||||
else if (!strcmp(command,"processors")) processors();
|
else if (mycmd == "processors") processors();
|
||||||
else if (!strcmp(command,"region")) region();
|
else if (mycmd == "region") region();
|
||||||
else if (!strcmp(command,"reset_timestep")) reset_timestep();
|
else if (mycmd == "reset_timestep") reset_timestep();
|
||||||
else if (!strcmp(command,"restart")) restart();
|
else if (mycmd == "restart") restart();
|
||||||
else if (!strcmp(command,"run_style")) run_style();
|
else if (mycmd == "run_style") run_style();
|
||||||
else if (!strcmp(command,"special_bonds")) special_bonds();
|
else if (mycmd == "special_bonds") special_bonds();
|
||||||
else if (!strcmp(command,"suffix")) suffix();
|
else if (mycmd == "suffix") suffix();
|
||||||
else if (!strcmp(command,"thermo")) thermo();
|
else if (mycmd == "thermo") thermo();
|
||||||
else if (!strcmp(command,"thermo_modify")) thermo_modify();
|
else if (mycmd == "thermo_modify") thermo_modify();
|
||||||
else if (!strcmp(command,"thermo_style")) thermo_style();
|
else if (mycmd == "thermo_style") thermo_style();
|
||||||
else if (!strcmp(command,"timestep")) timestep();
|
else if (mycmd == "timestep") timestep();
|
||||||
else if (!strcmp(command,"timer")) timer_command();
|
else if (mycmd == "timer") timer_command();
|
||||||
else if (!strcmp(command,"uncompute")) uncompute();
|
else if (mycmd == "uncompute") uncompute();
|
||||||
else if (!strcmp(command,"undump")) undump();
|
else if (mycmd == "undump") undump();
|
||||||
else if (!strcmp(command,"unfix")) unfix();
|
else if (mycmd == "unfix") unfix();
|
||||||
else if (!strcmp(command,"units")) units();
|
else if (mycmd == "units") units();
|
||||||
|
|
||||||
else flag = 0;
|
else flag = 0;
|
||||||
|
|
||||||
@ -830,13 +831,12 @@ int Input::execute_command()
|
|||||||
// process "meta-commands", i.e. commands that may have sub-commands
|
// process "meta-commands", i.e. commands that may have sub-commands
|
||||||
// they return 1 if there was a match and 0 if not
|
// they return 1 if there was a match and 0 if not
|
||||||
|
|
||||||
if (!strcmp(command,"reset")) flag = reset();
|
if (mycmd == "reset") flag = meta(mycmd);
|
||||||
if (flag) return 0;
|
if (flag) return 0;
|
||||||
|
|
||||||
// invoke commands added via style_command.h
|
// invoke commands added via style_command.h
|
||||||
// try suffixed version first
|
// try suffixed version first
|
||||||
|
|
||||||
std::string mycmd = command;
|
|
||||||
if (lmp->suffix_enable && lmp->non_pair_suffix()) {
|
if (lmp->suffix_enable && lmp->non_pair_suffix()) {
|
||||||
mycmd = command + std::string("/") + lmp->non_pair_suffix();
|
mycmd = command + std::string("/") + lmp->non_pair_suffix();
|
||||||
if (command_map->find(mycmd) == command_map->end()) {
|
if (command_map->find(mycmd) == command_map->end()) {
|
||||||
@ -1997,13 +1997,13 @@ void Input::units()
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
one function for each meta command
|
function for meta commands
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int Input::reset()
|
int Input::meta(const std::string &prefix)
|
||||||
{
|
{
|
||||||
auto mycmd = fmt::format("reset_{}", arg[0]);
|
auto mycmd = fmt::format("{}_{}", prefix, arg[0]);
|
||||||
if (command_map->find(mycmd) != command_map->end()) {
|
if (command_map->find(mycmd) != command_map->end()) {
|
||||||
CommandCreator &command_creator = (*command_map)[mycmd];
|
CommandCreator &command_creator = (*command_map)[mycmd];
|
||||||
Command *cmd = command_creator(lmp);
|
Command *cmd = command_creator(lmp);
|
||||||
|
|||||||
@ -70,6 +70,8 @@ class Input : protected Pointers {
|
|||||||
void reallocate(char *&, int &, int); // reallocate a char string
|
void reallocate(char *&, int &, int); // reallocate a char string
|
||||||
int execute_command(); // execute a single command
|
int execute_command(); // execute a single command
|
||||||
|
|
||||||
|
int meta(const std::string &); // process meta-commands
|
||||||
|
|
||||||
void clear(); // input script commands
|
void clear(); // input script commands
|
||||||
void echo();
|
void echo();
|
||||||
void ifthenelse();
|
void ifthenelse();
|
||||||
@ -142,8 +144,6 @@ class Input : protected Pointers {
|
|||||||
void undump();
|
void undump();
|
||||||
void unfix();
|
void unfix();
|
||||||
void units();
|
void units();
|
||||||
|
|
||||||
int reset(); // meta-commands
|
|
||||||
};
|
};
|
||||||
} // namespace LAMMPS_NS
|
} // namespace LAMMPS_NS
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user