From 34ff7aa1fe8f3744e29d6ca9c824f35845ee6ede Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 4 Jun 2020 11:18:33 -0400 Subject: [PATCH] Add convenience functions to PotentialFileReader --- src/potential_file_reader.cpp | 54 +++++++++++++++++++++++++++++++++++ src/potential_file_reader.h | 9 ++++++ 2 files changed, 63 insertions(+) diff --git a/src/potential_file_reader.cpp b/src/potential_file_reader.cpp index da5b254309..aff1ce2f01 100644 --- a/src/potential_file_reader.cpp +++ b/src/potential_file_reader.cpp @@ -51,6 +51,10 @@ PotentialFileReader::~PotentialFileReader() { delete reader; } +void PotentialFileReader::ignore_comments(bool value) { + reader->ignore_comments = value; +} + void PotentialFileReader::skip_line() { try { reader->skip_line(); @@ -76,6 +80,56 @@ void PotentialFileReader::next_dvector(int n, double * list) { } } +double PotentialFileReader::next_double() { + try { + char * line = reader->next_line(1); + return ValueTokenizer(line).next_double(); + } catch (FileReaderException & e) { + error->one(FLERR, e.what()); + } + return 0.0; +} + +int PotentialFileReader::next_int() { + try { + char * line = reader->next_line(1); + return ValueTokenizer(line).next_int(); + } catch (FileReaderException & e) { + error->one(FLERR, e.what()); + } + return 0; +} + +tagint PotentialFileReader::next_tagint() { + try { + char * line = reader->next_line(1); + return ValueTokenizer(line).next_tagint(); + } catch (FileReaderException & e) { + error->one(FLERR, e.what()); + } + return 0; +} + +bigint PotentialFileReader::next_bigint() { + try { + char * line = reader->next_line(1); + return ValueTokenizer(line).next_bigint(); + } catch (FileReaderException & e) { + error->one(FLERR, e.what()); + } + return 0; +} + +std::string PotentialFileReader::next_string() { + try { + char * line = reader->next_line(1); + return ValueTokenizer(line).next_string(); + } catch (FileReaderException & e) { + error->one(FLERR, e.what()); + } + return ""; +} + /* ---------------------------------------------------------------------- open a potential file as specified by name if fails, search in dir specified by env variable LAMMPS_POTENTIALS diff --git a/src/potential_file_reader.h b/src/potential_file_reader.h index d2861c0a18..53d397ea31 100644 --- a/src/potential_file_reader.h +++ b/src/potential_file_reader.h @@ -38,9 +38,18 @@ namespace LAMMPS_NS PotentialFileReader(class LAMMPS *lmp, const std::string &filename, const std::string &potential_name); virtual ~PotentialFileReader(); + void ignore_comments(bool value); + void skip_line(); char * next_line(int nparams = 0); void next_dvector(int n, double * list); + + // convenience functions + double next_double(); + int next_int(); + tagint next_tagint(); + bigint next_bigint(); + std::string next_string(); }; } // namespace LAMMPS_NS