enable and apply clang-format

This commit is contained in:
Axel Kohlmeyer
2022-03-18 00:06:28 -04:00
parent 6d38ce5284
commit 32612d3f5b
7 changed files with 631 additions and 647 deletions

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -14,20 +13,20 @@
#include "angle.h"
#include "atom.h"
#include "atom_masks.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "math_const.h"
#include "suffix.h"
#include "atom_masks.h"
#include "memory.h"
#include "error.h"
#include "suffix.h"
using namespace LAMMPS_NS;
using namespace MathConst;
/* ---------------------------------------------------------------------- */
Angle::Angle(LAMMPS *lmp) : Pointers(lmp)
Angle::Angle(LAMMPS *_lmp) : Pointers(_lmp)
{
energy = 0.0;
virial[0] = virial[1] = virial[2] = virial[3] = virial[4] = virial[5] = 0.0;
@ -67,8 +66,7 @@ Angle::~Angle()
void Angle::init()
{
if (!allocated && atom->nangletypes)
error->all(FLERR,"Angle coeffs are not set");
if (!allocated && atom->nangletypes) error->all(FLERR, "Angle coeffs are not set");
for (int i = 1; i <= atom->nangletypes; i++)
if (setflag[i] == 0) error->all(FLERR, "All angle coeffs are not set");
@ -104,11 +102,9 @@ void Angle::ev_setup(int eflag, int vflag, int alloc)
vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR);
vflag_atom = vflag & VIRIAL_ATOM;
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL)
vflag_atom = 1;
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1;
cvflag_atom = 0;
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL)
cvflag_atom = 1;
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1;
vflag_either = vflag_global || vflag_atom || cvflag_atom;
// reallocate per-atom arrays if necessary
@ -138,7 +134,8 @@ void Angle::ev_setup(int eflag, int vflag, int alloc)
// zero accumulators
if (eflag_global) energy = 0.0;
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
if (vflag_global)
for (i = 0; i < 6; i++) virial[i] = 0.0;
if (eflag_atom && alloc) {
n = atom->nlocal;
if (force->newton_bond) n += atom->nghost;
@ -179,16 +176,16 @@ void Angle::ev_setup(int eflag, int vflag, int alloc)
virial = r1F1 + r2F2 + r3F3 = (r1-r2) F1 + (r3-r2) F3 = del1*f1 + del2*f3
------------------------------------------------------------------------- */
void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond,
double eangle, double *f1, double *f3,
double delx1, double dely1, double delz1,
double delx2, double dely2, double delz2)
void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond, double eangle, double *f1,
double *f3, double delx1, double dely1, double delz1, double delx2,
double dely2, double delz2)
{
double eanglethird, v[6];
if (eflag_either) {
if (eflag_global) {
if (newton_bond) energy += eangle;
if (newton_bond)
energy += eangle;
else {
eanglethird = THIRD * eangle;
if (i < nlocal) energy += eanglethird;

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -33,7 +32,7 @@ enum{NONE,LINEAR,SPLINE};
a particular bond style can override this
------------------------------------------------------------------------- */
Bond::Bond(LAMMPS *lmp) : Pointers(lmp)
Bond::Bond(LAMMPS *_lmp) : Pointers(_lmp)
{
energy = 0.0;
virial[0] = virial[1] = virial[2] = virial[3] = virial[4] = virial[5] = 0.0;
@ -70,8 +69,7 @@ Bond::~Bond()
void Bond::init()
{
if (!allocated && atom->nbondtypes)
error->all(FLERR,"Bond coeffs are not set");
if (!allocated && atom->nbondtypes) error->all(FLERR, "Bond coeffs are not set");
for (int i = 1; i <= atom->nbondtypes; i++)
if (setflag[i] == 0) error->all(FLERR, "All bond coeffs are not set");
init_style();
@ -125,7 +123,8 @@ void Bond::ev_setup(int eflag, int vflag, int alloc)
// zero accumulators
if (eflag_global) energy = 0.0;
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
if (vflag_global)
for (i = 0; i < 6; i++) virial[i] = 0.0;
if (eflag_atom && alloc) {
n = atom->nlocal;
if (force->newton_bond) n += atom->nghost;
@ -149,15 +148,15 @@ void Bond::ev_setup(int eflag, int vflag, int alloc)
tally energy and virial into global and per-atom accumulators
------------------------------------------------------------------------- */
void Bond::ev_tally(int i, int j, int nlocal, int newton_bond,
double ebond, double fbond,
void Bond::ev_tally(int i, int j, int nlocal, int newton_bond, double ebond, double fbond,
double delx, double dely, double delz)
{
double ebondhalf, v[6];
if (eflag_either) {
if (eflag_global) {
if (newton_bond) energy += ebond;
if (newton_bond)
energy += ebond;
else {
ebondhalf = 0.5 * ebond;
if (i < nlocal) energy += ebondhalf;
@ -254,7 +253,6 @@ void Bond::write_file(int narg, char **arg)
if (inner <= 0.0 || inner >= outer)
error->all(FLERR, "Invalid rlo/rhi values in bond_write command");
double r0 = equilibrium_distance(btype);
// open file in append mode if exists
@ -280,11 +278,12 @@ void Bond::write_file(int narg, char **arg)
utils::logmesg(lmp, "Appending to table file {} with DATE: {}\n", table_file, date);
fp = fopen(table_file.c_str(), "a");
} else {
utils::logmesg(lmp,"Creating table file {} with DATE: {}\n",
table_file, utils::current_date());
utils::logmesg(lmp, "Creating table file {} with DATE: {}\n", table_file,
utils::current_date());
fp = fopen(table_file.c_str(), "w");
if (fp) fmt::print(fp,"# DATE: {} UNITS: {} Created by bond_write\n",
utils::current_date(), update->unit_style);
if (fp)
fmt::print(fp, "# DATE: {} UNITS: {} Created by bond_write\n", utils::current_date(),
update->unit_style);
}
if (fp == nullptr)
error->one(FLERR, "Cannot open bond_write file {}: {}", arg[4], utils::getsyserror());
@ -304,8 +303,8 @@ void Bond::write_file(int narg, char **arg)
// evaluate energy and force at each of N distances
// note that Bond::single() takes r**2 and returns f/r.
fprintf(fp,"# Bond potential %s for bond type %d: i,r,energy,force\n",
force->bond_style,btype);
fprintf(fp, "# Bond potential %s for bond type %d: i,r,energy,force\n", force->bond_style,
btype);
fprintf(fp, "\n%s\nN %d EQ %.15g\n\n", arg[5], n, r0);
const double dr = (outer - inner) / static_cast<double>(n - 1);
@ -332,8 +331,7 @@ double Bond::memory_usage()
-------------------------------------------------------------------------- */
void Bond::reinit()
{
if (!reinitflag)
error->all(FLERR,"Fix adapt interface to this bond style not supported");
if (!reinitflag) error->all(FLERR, "Fix adapt interface to this bond style not supported");
init();
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -14,11 +13,11 @@
#include "dihedral.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "atom_masks.h"
#include "memory.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "memory.h"
#include "suffix.h"
#include "update.h"
@ -29,7 +28,7 @@ using namespace LAMMPS_NS;
DihedralCharmm will override this
------------------------------------------------------------------------- */
Dihedral::Dihedral(LAMMPS *lmp) : Pointers(lmp)
Dihedral::Dihedral(LAMMPS *_lmp) : Pointers(_lmp)
{
energy = 0.0;
writedata = 0;
@ -68,8 +67,7 @@ Dihedral::~Dihedral()
void Dihedral::init()
{
if (!allocated && atom->ndihedraltypes)
error->all(FLERR,"Dihedral coeffs are not set");
if (!allocated && atom->ndihedraltypes) error->all(FLERR, "Dihedral coeffs are not set");
for (int i = 1; i <= atom->ndihedraltypes; i++)
if (setflag[i] == 0) error->all(FLERR, "All dihedral coeffs are not set");
init_style();
@ -104,11 +102,9 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc)
vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR);
vflag_atom = vflag & VIRIAL_ATOM;
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL)
vflag_atom = 1;
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1;
cvflag_atom = 0;
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL)
cvflag_atom = 1;
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1;
vflag_either = vflag_global || vflag_atom || cvflag_atom;
// reallocate per-atom arrays if necessary
@ -138,7 +134,8 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc)
// zero accumulators
if (eflag_global) energy = 0.0;
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
if (vflag_global)
for (i = 0; i < 6; i++) virial[i] = 0.0;
if (eflag_atom && alloc) {
n = atom->nlocal;
if (force->newton_bond) n += atom->nghost;
@ -181,18 +178,17 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc)
= vb1*f1 + vb2*f3 + (vb3+vb2)*f4
------------------------------------------------------------------------- */
void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
int nlocal, int newton_bond,
double edihedral, double *f1, double *f3, double *f4,
double vb1x, double vb1y, double vb1z,
double vb2x, double vb2y, double vb2z,
void Dihedral::ev_tally(int i1, int i2, int i3, int i4, int nlocal, int newton_bond,
double edihedral, double *f1, double *f3, double *f4, double vb1x,
double vb1y, double vb1z, double vb2x, double vb2y, double vb2z,
double vb3x, double vb3y, double vb3z)
{
double edihedralquarter, v[6];
if (eflag_either) {
if (eflag_global) {
if (newton_bond) energy += edihedral;
if (newton_bond)
energy += edihedral;
else {
edihedralquarter = 0.25 * edihedral;
if (i1 < nlocal) energy += edihedralquarter;
@ -390,21 +386,19 @@ void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
/* ---------------------------------------------------------------------- */
void Dihedral::problem(const char *filename, int lineno,
int i1, int i2, int i3, int i4)
void Dihedral::problem(const char *filename, int lineno, int i1, int i2, int i3, int i4)
{
const auto x = atom->x;
auto warn = fmt::format("Dihedral problem: {} {} {} {} {} {}\n",
comm->me, update->ntimestep, atom->tag[i1],
atom->tag[i2], atom->tag[i3], atom->tag[i4]);
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n",
comm->me,x[i1][0],x[i1][1],x[i1][2]);
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n",
comm->me,x[i2][0],x[i2][1],x[i2][2]);
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n",
comm->me,x[i3][0],x[i3][1],x[i3][2]);
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}",
comm->me,x[i4][0],x[i4][1],x[i4][2]);
auto warn = fmt::format("Dihedral problem: {} {} {} {} {} {}\n", comm->me, update->ntimestep,
atom->tag[i1], atom->tag[i2], atom->tag[i3], atom->tag[i4]);
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i1][0], x[i1][1],
x[i1][2]);
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i2][0], x[i2][1],
x[i2][2]);
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i3][0], x[i3][1],
x[i3][2]);
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}", comm->me, x[i4][0], x[i4][1],
x[i4][2]);
error->warning(filename, lineno, warn);
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -27,7 +26,7 @@ using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
Improper::Improper(LAMMPS *lmp) : Pointers(lmp)
Improper::Improper(LAMMPS *_lmp) : Pointers(_lmp)
{
energy = 0.0;
writedata = 0;
@ -66,8 +65,7 @@ Improper::~Improper()
void Improper::init()
{
if (!allocated && atom->nimpropertypes)
error->all(FLERR,"Improper coeffs are not set");
if (!allocated && atom->nimpropertypes) error->all(FLERR, "Improper coeffs are not set");
for (int i = 1; i <= atom->nimpropertypes; i++)
if (setflag[i] == 0) error->all(FLERR, "All improper coeffs are not set");
@ -103,11 +101,9 @@ void Improper::ev_setup(int eflag, int vflag, int alloc)
vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR);
vflag_atom = vflag & VIRIAL_ATOM;
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL)
vflag_atom = 1;
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1;
cvflag_atom = 0;
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL)
cvflag_atom = 1;
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1;
vflag_either = vflag_global || vflag_atom || cvflag_atom;
// reallocate per-atom arrays if necessary
@ -137,7 +133,8 @@ void Improper::ev_setup(int eflag, int vflag, int alloc)
// zero accumulators
if (eflag_global) energy = 0.0;
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
if (vflag_global)
for (i = 0; i < 6; i++) virial[i] = 0.0;
if (eflag_atom && alloc) {
n = atom->nlocal;
if (force->newton_bond) n += atom->nghost;
@ -180,18 +177,17 @@ void Improper::ev_setup(int eflag, int vflag, int alloc)
= vb1*f1 + vb2*f3 + (vb3+vb2)*f4
------------------------------------------------------------------------- */
void Improper::ev_tally(int i1, int i2, int i3, int i4,
int nlocal, int newton_bond,
double eimproper, double *f1, double *f3, double *f4,
double vb1x, double vb1y, double vb1z,
double vb2x, double vb2y, double vb2z,
void Improper::ev_tally(int i1, int i2, int i3, int i4, int nlocal, int newton_bond,
double eimproper, double *f1, double *f3, double *f4, double vb1x,
double vb1y, double vb1z, double vb2x, double vb2y, double vb2z,
double vb3x, double vb3y, double vb3z)
{
double eimproperquarter, v[6];
if (eflag_either) {
if (eflag_global) {
if (newton_bond) energy += eimproper;
if (newton_bond)
energy += eimproper;
else {
eimproperquarter = 0.25 * eimproper;
if (i1 < nlocal) energy += eimproperquarter;
@ -389,22 +385,19 @@ void Improper::ev_tally(int i1, int i2, int i3, int i4,
/* ---------------------------------------------------------------------- */
void Improper::problem(const char *filename, int lineno,
int i1, int i2, int i3, int i4)
void Improper::problem(const char *filename, int lineno, int i1, int i2, int i3, int i4)
{
const auto x = atom->x;
auto warn = fmt::format("Improper problem: {} {} {} {} {} {}\n",
comm->me, update->ntimestep, atom->tag[i1],
atom->tag[i2], atom->tag[i3], atom->tag[i4]);
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n",
comm->me,x[i1][0],x[i1][1],x[i1][2]);
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n",
comm->me,x[i2][0],x[i2][1],x[i2][2]);
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n",
comm->me,x[i3][0],x[i3][1],x[i3][2]);
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}",
comm->me,x[i4][0],x[i4][1],x[i4][2]);
auto warn = fmt::format("Improper problem: {} {} {} {} {} {}\n", comm->me, update->ntimestep,
atom->tag[i1], atom->tag[i2], atom->tag[i3], atom->tag[i4]);
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i1][0], x[i1][1],
x[i1][2]);
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i2][0], x[i2][1],
x[i2][2]);
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i3][0], x[i3][1],
x[i3][2]);
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}", comm->me, x[i4][0], x[i4][1],
x[i4][2]);
error->warning(filename, lineno, warn);
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -22,15 +21,14 @@
using namespace LAMMPS_NS;
TableFileReader::TableFileReader(LAMMPS *lmp,
const std::string &filename,
const std::string &type,
TableFileReader::TableFileReader(LAMMPS *lmp, const std::string &filename, const std::string &type,
const int auto_convert) :
PotentialFileReader(lmp, filename, type + " table", auto_convert)
{
}
char *TableFileReader::find_section_start(const std::string &keyword) {
char *TableFileReader::find_section_start(const std::string &keyword)
{
char *line = nullptr;
while ((line = reader->next_line())) {
ValueTokenizer values(line);

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -24,7 +23,7 @@ using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
Timer::Timer(LAMMPS *lmp) : Pointers(lmp)
Timer::Timer(LAMMPS *_lmp) : Pointers(_lmp)
{
_level = NORMAL;
_sync = OFF;
@ -175,8 +174,7 @@ void Timer::print_timeout(FILE *fp)
s = (s - seconds) / 60;
const int minutes = s % 60;
const int hours = (s - minutes) / 60;
fprintf(fp," Walltime left : %d:%02d:%02d.%02d\n",
hours,minutes,seconds,hs);
fprintf(fp, " Walltime left : %d:%02d:%02d.%02d\n", hours, minutes, seconds, hs);
}
}
@ -192,8 +190,7 @@ bool Timer::_check_timeout()
_nextcheck += _checkfreq;
return false;
} else {
if (comm->me == 0)
error->warning(FLERR,"Wall time limit reached");
if (comm->me == 0) error->warning(FLERR, "Wall time limit reached");
_timeout = 0.0;
return true;
}
@ -231,15 +228,17 @@ void Timer::modify_params(int narg, char **arg)
++iarg;
if (iarg < narg) {
_timeout = utils::timespec2seconds(arg[iarg]);
} else error->all(FLERR,"Illegal timer command");
} else
error->all(FLERR, "Illegal timer command");
} else if (strcmp(arg[iarg], "every") == 0) {
++iarg;
if (iarg < narg) {
_checkfreq = utils::inumeric(FLERR, arg[iarg], false, lmp);
if (_checkfreq <= 0)
if (_checkfreq <= 0) error->all(FLERR, "Illegal timer command");
} else
error->all(FLERR, "Illegal timer command");
} else
error->all(FLERR, "Illegal timer command");
} else error->all(FLERR,"Illegal timer command");
} else error->all(FLERR,"Illegal timer command");
++iarg;
}
@ -253,7 +252,7 @@ void Timer::modify_params(int narg, char **arg)
timeout = fmt::format("{:%H:%M:%S}", fmt::gmtime(tv));
}
utils::logmesg(lmp,"New timer settings: style={} mode={} timeout={}\n",
timer_style[_level],timer_mode[_sync],timeout);
utils::logmesg(lmp, "New timer settings: style={} mode={} timeout={}\n", timer_style[_level],
timer_mode[_sync], timeout);
}
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -17,14 +16,15 @@
------------------------------------------------------------------------- */
#include "tokenizer.h"
#include "utils.h"
#include "fmt/format.h"
#include "utils.h"
#include <utility>
using namespace LAMMPS_NS;
TokenizerException::TokenizerException(const std::string &msg, const std::string &token) {
TokenizerException::TokenizerException(const std::string &msg, const std::string &token)
{
if (token.empty()) {
message = msg;
} else {
@ -93,7 +93,8 @@ void Tokenizer::swap(Tokenizer& other)
/*! Re-position the tokenizer state to the first word,
* i.e. the first non-separator character */
void Tokenizer::reset() {
void Tokenizer::reset()
{
start = text.find_first_not_of(separators);
}
@ -101,14 +102,16 @@ void Tokenizer::reset() {
*
* \param str string to be searched for
* \return true if string was found, false if not */
bool Tokenizer::contains(const std::string &str) const {
bool Tokenizer::contains(const std::string &str) const
{
return text.find(str) != std::string::npos;
}
/*! Skip over a given number of tokens
*
* \param n number of tokens to skip over */
void Tokenizer::skip(int n) {
void Tokenizer::skip(int n)
{
for (int i = 0; i < n; ++i) {
if (!has_next()) throw TokenizerException("No more tokens", "");
@ -125,14 +128,16 @@ void Tokenizer::skip(int n) {
/*! Indicate whether more tokens are available
*
* \return true if there are more tokens, false if not */
bool Tokenizer::has_next() const {
bool Tokenizer::has_next() const
{
return start != std::string::npos;
}
/*! Retrieve next token.
*
* \return string with the next token */
std::string Tokenizer::next() {
std::string Tokenizer::next()
{
if (!has_next()) throw TokenizerException("No more tokens", "");
size_t end = text.find_first_of(separators, start);
@ -151,18 +156,18 @@ std::string Tokenizer::next() {
/*! Count number of tokens in text.
*
* \return number of counted tokens */
size_t Tokenizer::count() {
size_t Tokenizer::count()
{
// lazy evaluation
if (ntokens == std::string::npos) {
ntokens = utils::count_words(text, separators);
}
if (ntokens == std::string::npos) { ntokens = utils::count_words(text, separators); }
return ntokens;
}
/*! Retrieve the entire text converted to an STL vector of tokens.
*
* \return The STL vector */
std::vector<std::string> Tokenizer::as_vector() {
std::vector<std::string> Tokenizer::as_vector()
{
// store current state
size_t current = start;
@ -171,9 +176,7 @@ std::vector<std::string> Tokenizer::as_vector() {
// generate vector
std::vector<std::string> tokens;
while (has_next()) {
tokens.emplace_back(next());
}
while (has_next()) { tokens.emplace_back(next()); }
// restore state
start = current;
@ -195,11 +198,12 @@ std::vector<std::string> Tokenizer::as_vector() {
*
* \see Tokenizer InvalidIntegerException InvalidFloatException */
ValueTokenizer::ValueTokenizer(const std::string &str, const std::string &separators) : tokens(str, separators) {
ValueTokenizer::ValueTokenizer(const std::string &str, const std::string &separators) :
tokens(str, separators)
{
}
ValueTokenizer::ValueTokenizer(ValueTokenizer &&rhs) : tokens(std::move(rhs.tokens)) {
}
ValueTokenizer::ValueTokenizer(ValueTokenizer &&rhs) : tokens(std::move(rhs.tokens)) {}
ValueTokenizer &ValueTokenizer::operator=(const ValueTokenizer &other)
{
@ -223,7 +227,8 @@ void ValueTokenizer::swap(ValueTokenizer& other)
/*! Indicate whether more tokens are available
*
* \return true if there are more tokens, false if not */
bool ValueTokenizer::has_next() const {
bool ValueTokenizer::has_next() const
{
return tokens.has_next();
}
@ -231,71 +236,71 @@ bool ValueTokenizer::has_next() const {
*
* \param value string with value to be searched for
* \return true if string was found, false if not */
bool ValueTokenizer::contains(const std::string &value) const {
bool ValueTokenizer::contains(const std::string &value) const
{
return tokens.contains(value);
}
/*! Retrieve next token
*
* \return string with next token */
std::string ValueTokenizer::next_string() {
std::string ValueTokenizer::next_string()
{
return tokens.next();
}
/*! Retrieve next token and convert to int
*
* \return value of next token */
int ValueTokenizer::next_int() {
int ValueTokenizer::next_int()
{
std::string current = tokens.next();
if (!utils::is_integer(current)) {
throw InvalidIntegerException(current);
}
if (!utils::is_integer(current)) { throw InvalidIntegerException(current); }
return atoi(current.c_str());
}
/*! Retrieve next token and convert to bigint
*
* \return value of next token */
bigint ValueTokenizer::next_bigint() {
bigint ValueTokenizer::next_bigint()
{
std::string current = tokens.next();
if (!utils::is_integer(current)) {
throw InvalidIntegerException(current);
}
if (!utils::is_integer(current)) { throw InvalidIntegerException(current); }
return ATOBIGINT(current.c_str());
}
/*! Retrieve next token and convert to tagint
*
* \return value of next token */
tagint ValueTokenizer::next_tagint() {
tagint ValueTokenizer::next_tagint()
{
std::string current = tokens.next();
if (!utils::is_integer(current)) {
throw InvalidIntegerException(current);
}
if (!utils::is_integer(current)) { throw InvalidIntegerException(current); }
return ATOTAGINT(current.c_str());
}
/*! Retrieve next token and convert to double
*
* \return value of next token */
double ValueTokenizer::next_double() {
double ValueTokenizer::next_double()
{
std::string current = tokens.next();
if (!utils::is_double(current)) {
throw InvalidFloatException(current);
}
if (!utils::is_double(current)) { throw InvalidFloatException(current); }
return atof(current.c_str());
}
/*! Skip over a given number of tokens
*
* \param n number of tokens to skip over */
void ValueTokenizer::skip(int n) {
void ValueTokenizer::skip(int n)
{
tokens.skip(n);
}
/*! Count number of tokens in text.
*
* \return number of counted tokens */
size_t ValueTokenizer::count() {
size_t ValueTokenizer::count()
{
return tokens.count();
}