/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
{
genericOptionFormatter_.setColumnFirstLineOffset(1, 1);
}
+
// TODO: Better handling of multiple long values
std::string values;
for (int i = 0; i < option.valueCount(); ++i)
values.append(option.formatValue(i));
}
genericOptionFormatter_.addColumnLine(2, values);
+
std::string description(context.substituteMarkup(option.description()));
const DoubleOptionInfo *doubleOption = option.toType<DoubleOptionInfo>();
if (doubleOption != NULL && doubleOption->isTime())
{
description = replaceAll(description, "%t", common_.timeUnit);
}
+ const StringOptionInfo *stringOption = option.toType<StringOptionInfo>();
+ if (stringOption != NULL && stringOption->isEnumerated())
+ {
+ const std::vector<std::string> &allowedValues
+ = stringOption->allowedValues();
+ description.append(": ");
+ for (size_t i = 0; i < allowedValues.size(); ++i)
+ {
+ if (i > 0)
+ {
+ description.append(i + 1 < allowedValues.size()
+ ? ", " : ", or ");
+ }
+ description.append(allowedValues[i]);
+ }
+ }
genericOptionFormatter_.addColumnLine(3, description);
if (values.length() > 6U)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
{
name_ = settings.name_;
}
- descr_ = settings.createDescription();
+ if (settings.descr_ != NULL)
+ {
+ descr_ = settings.descr_;
+ }
setFlag(efOption_ClearOnNextSet);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
*/
virtual AbstractOptionStoragePointer createStorage() const = 0;
- /*! \brief
- * Creates the description string for the option.
- *
- * \returns Description string for the option.
- *
- * This function is virtual to allow derived classes to customize the
- * description programmatically, e.g., by adding the list of allowed
- * values.
- * The default implementation simply returns the user-provided
- * description.
- */
- virtual std::string createDescription() const
- { return descr_ ? descr_ : ""; }
-
//! Sets the description for the option.
void setDescription(const char *descr) { descr_ = descr; }
//! Sets a flag for the option.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
{
}
+StringOptionStorage &StringOptionInfo::option()
+{
+ return static_cast<StringOptionStorage &>(OptionInfo::option());
+}
+
+const StringOptionStorage &StringOptionInfo::option() const
+{
+ return static_cast<const StringOptionStorage &>(OptionInfo::option());
+}
+
+bool StringOptionInfo::isEnumerated() const
+{
+ return !allowedValues().empty();
+}
+
+const std::vector<std::string> &StringOptionInfo::allowedValues() const
+{
+ return option().allowedValues();
+}
+
/********************************************************************
* StringOption
*/
return AbstractOptionStoragePointer(new StringOptionStorage(*this));
}
-std::string StringOption::createDescription() const
-{
- std::string value(MyBase::createDescription());
-
- if (enumValues_ != NULL)
- {
- value.append(": ");
- for (int i = 0; enumValues_[i] != NULL; ++i)
- {
- value.append(enumValues_[i]);
- if (enumValues_[i + 1] != NULL)
- {
- value.append(enumValues_[i + 2] != NULL ? ", " : ", or ");
- }
- }
- }
- return value;
-}
-
} // namespace gmx
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
private:
//! Creates a StringOptionStorage object.
virtual AbstractOptionStoragePointer createStorage() const;
- virtual std::string createDescription() const;
const char *const *enumValues_;
int defaultEnumIndex_;
public:
//! Creates an option info object for the given option.
explicit StringOptionInfo(StringOptionStorage *option);
+
+ /*! \brief
+ * Whether this option accepts an enumerated set of values.
+ *
+ * Returns true if StringOption::enumValues() was used when creating
+ * this option.
+ */
+ bool isEnumerated() const;
+ /*! \brief
+ * Returns the set of allowed values for this option.
+ *
+ * Returns an empty vector if isEnumerated() returns false.
+ */
+ const std::vector<std::string> &allowedValues() const;
+
+ private:
+ StringOptionStorage &option();
+ const StringOptionStorage &option() const;
};
/*!\}*/
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
virtual const char *typeString() const { return allowed_.empty() ? "string" : "enum"; }
virtual std::string formatSingleValue(const std::string &value) const;
+ //! \copydoc StringOptionInfo::allowedValues()
+ const ValueList &allowedValues() const { return allowed_; }
+
private:
virtual void convertValue(const std::string &value);
virtual void refreshValues();