remove .c_str() in several places because it is no longer neede

This commit is contained in:
Axel Kohlmeyer
2020-06-05 12:11:54 -04:00
parent c7ef89dc4a
commit 04d7eacc2f
5 changed files with 17 additions and 19 deletions

View File

@ -137,7 +137,7 @@ void lammps_open(int argc, char **argv, MPI_Comm communicator, void **ptr)
*ptr = (void *) lmp; *ptr = (void *) lmp;
} }
catch(LAMMPSException & e) { catch(LAMMPSException & e) {
fprintf(stderr, "LAMMPS Exception: %s", e.message.c_str()); fmt::print(stderr, "LAMMPS Exception: {}", e.message);
*ptr = (void *) NULL; *ptr = (void *) NULL;
} }
#else #else
@ -172,7 +172,7 @@ void lammps_open_no_mpi(int argc, char **argv, void **ptr)
*ptr = (void *) lmp; *ptr = (void *) lmp;
} }
catch(LAMMPSException & e) { catch(LAMMPSException & e) {
fprintf(stderr, "LAMMPS Exception: %s", e.message.c_str()); fmt::print(stderr, "LAMMPS Exception: {}", e.message);
*ptr = (void*) NULL; *ptr = (void*) NULL;
} }
#else #else

View File

@ -155,7 +155,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size,
errmsg += filename; errmsg += filename;
errmsg += "'"; errmsg += "'";
if (error) error->one(srcname,srcline,errmsg.c_str()); if (error) error->one(srcname,srcline,errmsg);
if (s) *s = '\0'; // truncate string to empty in case error is NULL if (s) *s = '\0'; // truncate string to empty in case error is NULL
} }
return; return;
@ -184,7 +184,7 @@ void utils::sfread(const char *srcname, int srcline, void *s, size_t size,
errmsg += filename; errmsg += filename;
errmsg += "'"; errmsg += "'";
if (error) error->one(srcname,srcline,errmsg.c_str()); if (error) error->one(srcname,srcline,errmsg);
} }
return; return;
} }
@ -238,9 +238,9 @@ double utils::numeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return atof(str); return atof(str);
@ -273,9 +273,9 @@ int utils::inumeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return atoi(str); return atoi(str);
@ -308,9 +308,9 @@ bigint utils::bnumeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return ATOBIGINT(str); return ATOBIGINT(str);
@ -343,9 +343,9 @@ tagint utils::tnumeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return ATOTAGINT(str); return ATOTAGINT(str);

View File

@ -123,7 +123,7 @@ void WriteData::command(int narg, char **arg)
if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost); if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost);
} }
write(file.c_str()); write(file);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -131,7 +131,7 @@ void WriteData::command(int narg, char **arg)
might later let it be directly called within run/minimize loop might later let it be directly called within run/minimize loop
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void WriteData::write(const char *file) void WriteData::write(const std::string &file)
{ {
// special case where reneighboring is not done in integrator // special case where reneighboring is not done in integrator
// on timestep data file is written (due to build_once being set) // on timestep data file is written (due to build_once being set)
@ -187,7 +187,7 @@ void WriteData::write(const char *file)
// open data file // open data file
if (me == 0) { if (me == 0) {
fp = fopen(file,"w"); fp = fopen(file.c_str(),"w");
if (fp == NULL) if (fp == NULL)
error->one(FLERR,fmt::format("Cannot open data file {}: {}", error->one(FLERR,fmt::format("Cannot open data file {}: {}",
file, utils::getsyserror())); file, utils::getsyserror()));

View File

@ -21,6 +21,7 @@ CommandStyle(write_data,WriteData)
#define LMP_WRITE_DATA_H #define LMP_WRITE_DATA_H
#include "pointers.h" #include "pointers.h"
#include <string>
namespace LAMMPS_NS { namespace LAMMPS_NS {
@ -28,7 +29,7 @@ class WriteData : protected Pointers {
public: public:
WriteData(class LAMMPS *); WriteData(class LAMMPS *);
void command(int, char **); void command(int, char **);
void write(const char *); void write(const std::string &);
private: private:
int me,nprocs; int me,nprocs;

View File

@ -293,9 +293,6 @@ void WriteRestart::write(std::string file)
std::string multiname = file; std::string multiname = file;
multiname.replace(multiname.find("%"),1,fmt::format("{}",icluster)); multiname.replace(multiname.find("%"),1,fmt::format("{}",icluster));
fp = fopen(multiname.c_str(),"wb");
if (fp == NULL)
error->one(FLERR,fmt::format("Cannot open restart file {}",multiname).c_str());
if (filewriter) { if (filewriter) {
fp = fopen(multiname.c_str(),"wb"); fp = fopen(multiname.c_str(),"wb");