From c1538c2f78429a69651ff6ed5bb970f6cd75ae91 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 22 May 2024 23:42:56 -0400 Subject: [PATCH] move varstyle array definition to Variable class so it can be used in a more general way --- src/info.cpp | 8 +------- src/variable.cpp | 6 ++++++ src/variable.h | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index 2b87452d72..43409fca67 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -110,12 +110,6 @@ static const int STYLES = ATOM_STYLES | INTEGRATE_STYLES | MINIMIZE_STYLES using namespace LAMMPS_NS; -// must match enumerator in variable.h -static const char *varstyles[] = { - "index", "loop", "world", "universe", "uloop", "string", "getenv", - "file", "atomfile", "format", "equal", "atom", "vector", "python", - "timer", "internal", "(unknown)"}; - static const char *mapstyles[] = { "none", "array", "hash", "yes" }; static const char *commstyles[] = { "brick", "tiled" }; @@ -1401,7 +1395,7 @@ std::string Info::get_variable_info(int num) { std::string text; int ndata = 1; text = fmt::format("Variable[{:3d}]: {:16} style = {:16} def =", num, - std::string(names[num]) + ',', std::string(varstyles[style[num]]) + ','); + std::string(names[num]) + ',', Variable::varstyles[style[num]] + ','); if (style[num] == Variable::INTERNAL) { text += fmt::format("{:.8}\n",input->variable->dvalue[num]); return text; diff --git a/src/variable.cpp b/src/variable.cpp index be9239c027..032789f535 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -54,6 +54,12 @@ static constexpr int MAXLINE = 256; static constexpr int CHUNK = 1024; static constexpr int MAXFUNCARG = 6; +// must match enumerator in variable.h +const std::vector Variable::varstyles = { + "index", "loop", "world", "universe", "uloop", "string", "getenv", + "file", "atomfile", "format", "equal", "atom", "vector", "python", + "timer", "internal", "(unknown)"}; + static inline double MYROUND(double a) { return ((a - floor(a)) >= 0.5) ? ceil(a) : floor(a); } enum{ARG,OP}; diff --git a/src/variable.h b/src/variable.h index 8acfa5bcc7..aa2111aa6b 100644 --- a/src/variable.h +++ b/src/variable.h @@ -56,7 +56,7 @@ class Variable : protected Pointers { int nvar; // # of defined variables char **names; // name of each variable - // must match "varstyles" array in info.cpp + // must match "varstyles" array in variables.cpp, UNKNOWN must be last. enum { INDEX, LOOP, @@ -73,9 +73,11 @@ class Variable : protected Pointers { VECTOR, PYTHON, TIMER, - INTERNAL + INTERNAL, + UNKNOWN }; static constexpr int VALUELENGTH = 64; + static const std::vector varstyles; private: int me;