diff --git a/src/info.cpp b/src/info.cpp index dfd901fc35..22cb432acc 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -735,10 +735,11 @@ void Info::dump_styles(FILE * out) fprintf(out, "\nDump styles:\n"); vector styles; -#define DUMP_CLASS -#define DumpStyle(key,Class) styles.push_back(#key); -#include "style_dump.h" -#undef DUMP_CLASS + + for(Output::DumpCreatorMap::iterator it = output->dump_map->begin(); it != output->dump_map->end(); ++it) { + styles.push_back(it->first); + } + print_columns(out, styles); fprintf(out, "\n\n\n"); } diff --git a/src/output.cpp b/src/output.cpp index 073171735f..df7c33e101 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -89,6 +89,15 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) restart1 = restart2a = restart2b = NULL; var_restart_single = var_restart_double = NULL; restart = NULL; + + dump_map = new DumpCreatorMap(); + +#define DUMP_CLASS +#define DumpStyle(key,Class) \ + (*dump_map)[#key] = &dump_creator; +#include "style_dump.h" +#undef DumpStyle +#undef DUMP_CLASS } /* ---------------------------------------------------------------------- @@ -115,6 +124,8 @@ Output::~Output() delete [] var_restart_single; delete [] var_restart_double; delete restart; + + delete dump_map; } /* ---------------------------------------------------------------------- */ @@ -571,14 +582,10 @@ void Output::add_dump(int narg, char **arg) // create the Dump - if (0) return; // dummy line to enable else-if macro expansion - -#define DUMP_CLASS -#define DumpStyle(key,Class) \ - else if (strcmp(arg[2],#key) == 0) dump[ndump] = new Class(lmp,narg,arg); -#include "style_dump.h" -#undef DUMP_CLASS - + if (dump_map->find(arg[2]) != dump_map->end()) { + DumpCreator dump_creator = (*dump_map)[arg[2]]; + dump[ndump] = dump_creator(lmp, narg, arg); + } else error->all(FLERR,"Unknown dump style"); every_dump[ndump] = force->inumeric(FLERR,arg[3]); @@ -588,6 +595,16 @@ void Output::add_dump(int narg, char **arg) ndump++; } +/* ---------------------------------------------------------------------- + one instance per dump style in style_dump.h +------------------------------------------------------------------------- */ + +template +Dump *Output::dump_creator(LAMMPS *lmp, int narg, char ** arg) +{ + return new T(lmp, narg, arg); +} + /* ---------------------------------------------------------------------- modify parameters of a Dump ------------------------------------------------------------------------- */ diff --git a/src/output.h b/src/output.h index 6bbd92a259..cc282cbedd 100644 --- a/src/output.h +++ b/src/output.h @@ -15,6 +15,8 @@ #define LMP_OUTPUT_H #include "pointers.h" +#include +#include namespace LAMMPS_NS { @@ -57,6 +59,11 @@ class Output : protected Pointers { char *restart2a,*restart2b; // names of double restart files class WriteRestart *restart; // class for writing restart files + + typedef Dump *(*DumpCreator)(LAMMPS *,int,char**); + typedef std::map DumpCreatorMap; + DumpCreatorMap *dump_map; + Output(class LAMMPS *); ~Output(); void init(); @@ -75,6 +82,9 @@ class Output : protected Pointers { void create_restart(int, char **); // create Restart and restart files void memory_usage(); // print out memory usage + + private: + template static Dump *dump_creator(LAMMPS *, int, char **); }; }