#include "gromacs/utility/futil.h"
#include "gromacs/utility/real.h"
#include "gromacs/utility/smalloc.h"
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
/*! \brief Shortcut macro to select modes. */
#define MODE(x) ((mode & (x)) == (x))
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
typedef struct {
t_iatom a[4];
#include <cstdlib>
#include "gromacs/math/vec.h"
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/txtdump.h"
void pr_ivec(FILE *fp, int indent, const char *title, const int vec[], int n, gmx_bool bShowNumbers)
#include "gromacs/utility/logger.h"
#include "gromacs/utility/pleasecite.h"
#include "gromacs/utility/smalloc.h"
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
#include "nbnxn_gpu_jit_support.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/snprintf.h"
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/textwriter.h"
#include "gromacs/utility/txtdump.h"
std::string IntegerOptionStorage::formatSingleValue(const int &value) const
{
- return formatString("%d", value);
+ return toString(value);
}
void IntegerOptionStorage::initConverter(ConverterType *converter)
std::string Int64OptionStorage::formatSingleValue(const gmx_int64_t &value) const
{
- return formatString("%" GMX_PRId64, value);
+ return toString(value);
}
void Int64OptionStorage::initConverter(ConverterType *converter)
std::string DoubleOptionStorage::formatSingleValue(const double &value) const
{
- return formatString("%g", value / factor_);
+ return toString(value / factor_);
}
void DoubleOptionStorage::initConverter(ConverterType *converter)
std::string FloatOptionStorage::formatSingleValue(const float &value) const
{
- return formatString("%g", value / factor_);
+ return toString(value / factor_);
}
void FloatOptionStorage::initConverter(ConverterType *converter)
#include "gromacs/topology/symtab.h"
#include "gromacs/utility/compare.h"
#include "gromacs/utility/smalloc.h"
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/txtdump.h"
const char *gtypes[egcNR+1] = {
#include <cstdio>
#include <cstring>
-#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/strconvert.h"
void cmp_int(FILE *fp, const char *s, int index, int i1, int i2)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
*/
/*! \libinternal \file
* \brief
- * Declares common utility functions for conversions from strings.
+ * Declares common utility functions for conversions to and from strings.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \author Mark Abraham <mark.j.abraham@gmail.com>
* \inlibraryapi
* \ingroup module_utility
*/
#include <string>
#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/stringutil.h"
namespace gmx
{
template <> inline
double fromString<double>(const char *str) { return doubleFromString(str); }
+/*! \brief
+ * Converts a boolean to a "true"/"false" string.
+ *
+ * Does not throw.
+ */
+static inline const char *boolToString(bool value)
+{
+ return value ? "true" : "false";
+}
+/*! \brief
+ * Returns a string containing the value of \c t.
+ *
+ * \throws std::bad_alloc if out of memory.
+ */
+static inline std::string intToString(int t)
+{
+ return formatString("%d", t);
+}
+//! \copydoc intToString(int)
+static inline std::string int64ToString(gmx_int64_t t)
+{
+ return formatString("%" GMX_PRId64, t);
+}
+//! \copydoc intToString(int)
+static inline std::string doubleToString(double t)
+{
+ return formatString("%g", t);
+}
+
+/*! \name
+ * Overloads for converting a value of a given type to a string.
+ *
+ * \throws std::bad_alloc if out of memory.
+ * \{
+ */
+static inline std::string toString(bool t) { return boolToString(t); }
+static inline std::string toString(int t) { return intToString(t); }
+static inline std::string toString(gmx_int64_t t) { return int64ToString(t); }
+static inline std::string toString(float t) { return doubleToString(t); }
+static inline std::string toString(double t) { return doubleToString(t); }
+static inline std::string toString(std::string t) { return t; }
+//! \}
+
//! \}
//! \endcond
return joinStrings(array, array + count, separator);
}
-/*! \brief
- * Converts a boolean to a "true"/"false" string.
- *
- * Does not throw.
- */
-static inline const char *boolToString(bool value)
-{
- return value ? "true" : "false";
-}
-
/*! \brief
* Splits a string to whitespace separated tokens.
*
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/filestream.h"
#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/stringstream.h"
#include "gromacs/utility/stringutil.h"
#include "gromacs/utility/textreader.h"
impl_->argc_ = static_cast<int>(newSize);
}
-namespace
-{
-
-//! Helper function for converting values to strings
-template <typename T>
-std::string value2string(T value)
-{
- std::stringstream ss;
- ss << value;
- return ss.str();
-}
-
-} // namespace
-
void CommandLine::addOption(const char *name)
{
append(name);
void CommandLine::addOption(const char *name, int value)
{
append(name);
- append(value2string(value));
+ append(gmx::toString(value));
}
void CommandLine::addOption(const char *name, double value)
{
append(name);
- append(value2string(value));
+ append(gmx::toString(value));
}
void CommandLine::merge(const CommandLine &args)