/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2019, 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.
#include "gromacs/options/abstractoptionstorage.h"
#include "gromacs/options/optionflags.h"
+#include "gromacs/utility/any.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/variant.h"
#include "basicoptionstorage.h"
bSetValuesHadErrors_ = false;
}
-void AbstractOptionStorage::appendValue(const Variant &value)
+void AbstractOptionStorage::appendValue(const Any &value)
{
GMX_RELEASE_ASSERT(bInSet_, "startSet() not called");
try
return description;
}
-std::vector<Variant> OptionInfo::defaultValues() const
+std::vector<Any> OptionInfo::defaultValues() const
{
return option().defaultValues();
}
return option().defaultValuesAsStrings();
}
-std::vector<Variant> OptionInfo::normalizeValues(const std::vector<Variant> &values) const
+std::vector<Any> OptionInfo::normalizeValues(const std::vector<Any> &values) const
{
return option().normalizeValues(values);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2019, 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.
class AbstractOptionStorage;
template <typename T> class OptionStorageTemplate;
class OptionManagerContainer;
-class Variant;
+class Any;
namespace internal
{
* Returns the default value(s) of the option.
*
* The returned values should all be of the same type, but returning
- * each as a separate variant is currently simpler.
+ * each as a separate any is currently simpler.
*
* Currently, this can only be called before option values have been
* assigned.
*/
- std::vector<Variant> defaultValues() const;
+ std::vector<Any> defaultValues() const;
/*! \brief
* Returns the default value(s) of the option as strings.
*
* value of the option, and the current value in the option is not
* changed.
*/
- std::vector<Variant> normalizeValues(const std::vector<Variant> &values) const;
+ std::vector<Any> normalizeValues(const std::vector<Any> &values) const;
protected:
/*! \cond libapi */
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2014,2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015,2016,2019, 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.
class AbstractOption;
class OptionInfo;
class Options;
-class Variant;
+class Any;
/*! \libinternal \brief
* Abstract base class for converting, validating, and storing option values.
*/
virtual int valueCount() const = 0;
//! \copydoc OptionInfo::defaultValues()
- virtual std::vector<Variant> defaultValues() const = 0;
+ virtual std::vector<Any> defaultValues() const = 0;
//! \copydoc OptionInfo::defaultValuesAsStrings()
virtual std::vector<std::string> defaultValuesAsStrings() const = 0;
//! \copydoc OptionInfo::normalizeValues()
- virtual std::vector<Variant> normalizeValues(const std::vector<Variant> &values) const = 0;
+ virtual std::vector<Any> normalizeValues(const std::vector<Any> &values) const = 0;
/*! \brief
* Starts adding values from a new source for the option.
* This method should only be called between startSet() and
* finishSet().
*/
- void appendValue(const Variant &value);
+ void appendValue(const Any &value);
/*! \brief
* Performs validation and/or actions once a set of values has been
* added.
*
* \see OptionStorageTemplate::convertValue()
*/
- virtual void convertValue(const Variant &value) = 0;
+ virtual void convertValue(const Any &value) = 0;
/*! \brief
* Performs validation and/or actions once a set of values has been
* added.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
return allowed_[value];
}
-Variant EnumOptionStorage::normalizeValue(const int &value) const
+Any EnumOptionStorage::normalizeValue(const int &value) const
{
- return Variant::create<std::string>(formatSingleValue(value));
+ return Any::create<std::string>(formatSingleValue(value));
}
void EnumOptionStorage::initConverter(ConverterType *converter)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
std::string typeString() const override { return "enum"; }
std::string formatExtraDescription() const override;
std::string formatSingleValue(const int &value) const override;
- Variant normalizeValue(const int &value) const override;
+ Any normalizeValue(const int &value) const override;
//! \copydoc EnumOptionInfo::allowedValues()
const std::vector<std::string> &allowedValues() const { return allowed_; }
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2019, 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.
#include "gromacs/options/abstractoptionstorage.h"
#include "gromacs/options/options.h"
+#include "gromacs/utility/any.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/variant.h"
#include "options-impl.h"
void OptionsAssigner::appendValue(const std::string &value)
{
- appendValue(Variant(value));
+ appendValue(Any(value));
}
-void OptionsAssigner::appendValue(const Variant &value)
+void OptionsAssigner::appendValue(const Any &value)
{
AbstractOptionStorage *option = impl_->currentOption_;
GMX_RELEASE_ASSERT(option != nullptr, "startOption() not called");
if (impl_->currentValueCount_ == 0)
{
// Should not throw, otherwise something is wrong.
- option->appendValue(Variant::create<bool>(!impl_->reverseBoolean_));
+ option->appendValue(Any::create<bool>(!impl_->reverseBoolean_));
}
else if (impl_->reverseBoolean_)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2019, 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.
{
class Options;
-class Variant;
+class Any;
/*! \libinternal \brief
* Decorator class for assigning values to Options.
* OptionStorageTemplate::convertValue() method of the storage class
* implementing the option where the value is assigned to.
*/
- void appendValue(const Variant &value);
+ void appendValue(const Any &value);
/*! \brief
* Appends a value to the value list of the current option.
*
* \param[in] value Value to assign.
*
- * See appendValue(const Variant &) for more details.
+ * See appendValue(const Any &) for more details.
*/
void appendValue(const std::string &value);
/*! \brief
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
#include "gromacs/options/abstractoption.h"
#include "gromacs/options/abstractoptionstorage.h"
#include "gromacs/options/valuestore.h"
+#include "gromacs/utility/any.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/variant.h"
#include "valueconverter.h"
//! \copydoc gmx::AbstractOptionStorage::valueCount()
int valueCount() const override { return store_->valueCount(); }
//! \copydoc gmx::AbstractOptionStorage::defaultValues()
- std::vector<Variant> defaultValues() const override;
+ std::vector<Any> defaultValues() const override;
/*! \copydoc gmx::AbstractOptionStorage::defaultValuesAsStrings()
*
* OptionStorageTemplate implements handling of defaultValueIfSet()
* should be considered whether the implementation can be made strongly
* exception safe.
*/
- void convertValue(const Variant &value) override = 0;
+ void convertValue(const Any &value) override = 0;
/*! \brief
* Processes values for a set after all have been converted.
*
/*! \brief
* Provides derived classes access to the current list of values.
*
- * The non-const variant should only be used from processAll() in
+ * The non-const any should only be used from processAll() in
* derived classes if necessary.
*/
ArrayRef<T> values() { return store_->values(); }
{
}
- std::vector<Variant>
- normalizeValues(const std::vector<Variant> &values) const override
+ std::vector<Any>
+ normalizeValues(const std::vector<Any> &values) const override
{
const_cast<MyBase *>(this)->ensureConverterInitialized();
- std::vector<Variant> result;
+ std::vector<Any> result;
result.reserve(values.size());
for (const auto &value : values)
{
* This can be overridden to serialize a different type than `T`
* when using the option with KeyValueTreeObject.
*/
- virtual Variant normalizeValue(const T &value) const
+ virtual Any normalizeValue(const T &value) const
{
- return Variant::create<T>(processValue(value));
+ return Any::create<T>(processValue(value));
}
private:
- void convertValue(const Variant &variant) override
+ void convertValue(const Any &any) override
{
ensureConverterInitialized();
- this->addValue(processValue(converter_.convert(variant)));
+ this->addValue(processValue(converter_.convert(any)));
}
void ensureConverterInitialized()
{
template <typename T>
-std::vector<Variant> OptionStorageTemplate<T>::defaultValues() const
+std::vector<Any> OptionStorageTemplate<T>::defaultValues() const
{
- std::vector<Variant> result;
+ std::vector<Any> result;
if (hasFlag(efOption_NoDefaultValue))
{
return result;
"Current option implementation can only provide default values before assignment");
for (const auto &value : values())
{
- result.push_back(Variant::create<T>(value));
+ result.push_back(Any::create<T>(value));
}
return normalizeValues(result);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2016,2018,2019, 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.
{
return "";
}
- std::vector<gmx::Variant>
- normalizeValues(const std::vector<gmx::Variant> &values) const override
+ std::vector<gmx::Any>
+ normalizeValues(const std::vector<gmx::Any> &values) const override
{
return values;
}
- void convertValue(const gmx::Variant &value) override
+ void convertValue(const gmx::Any &value) override
{
convertValue(value.cast<std::string>());
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2019, 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.
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/options.h"
#include "gromacs/options/optionsection.h"
+#include "gromacs/utility/any.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/stringutil.h"
-#include "gromacs/utility/variant.h"
#include "testutils/testasserts.h"
gmx::OptionsAssigner assigner(&options);
EXPECT_NO_THROW(assigner.start());
ASSERT_NO_THROW(assigner.startOption("p"));
- ASSERT_NO_THROW(assigner.appendValue(gmx::Variant::create<float>(2.7)));
+ ASSERT_NO_THROW(assigner.appendValue(gmx::Any::create<float>(2.7)));
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.finish());
EXPECT_NO_THROW(options.finish());
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
assigner_.startOption(prop.key().c_str());
try
{
- assigner_.appendValue(prop.value().asVariant());
+ assigner_.appendValue(prop.value().asAny());
}
catch (UserInputError &ex)
{
assigner_.startOption(key.c_str());
for (const KeyValueTreeValue &value : array.values())
{
- assigner_.appendValue(value.asVariant());
+ assigner_.appendValue(value.asAny());
}
assigner_.finishOption();
}
const std::string &name = option.name();
if (currentSourceObject_ == nullptr || !currentSourceObject_->keyExists(name))
{
- std::vector<Variant> values = option.defaultValues();
+ std::vector<Any> values = option.defaultValues();
if (values.size() == 1)
{
currentObjectBuilder_.addRawValue(name, std::move(values[0]));
else if (values.size() > 1)
{
auto arrayBuilder = currentObjectBuilder_.addArray(name);
- for (Variant &value : values)
+ for (Any &value : values)
{
arrayBuilder.addRawValue(std::move(value));
}
{
const KeyValueTreeValue &value = (*currentSourceObject_)[name];
GMX_RELEASE_ASSERT(!value.isObject(), "Value objects not supported in this context");
- std::vector<Variant> values;
+ std::vector<Any> values;
if (value.isArray())
{
for (const auto &arrayValue : value.asArray().values())
{
GMX_RELEASE_ASSERT(!value.isObject() && !value.isArray(),
"Complex values not supported in this context");
- values.push_back(arrayValue.asVariant());
+ values.push_back(arrayValue.asAny());
}
}
else
{
- values.push_back(value.asVariant());
+ values.push_back(value.asAny());
}
values = option.normalizeValues(values);
if (values.empty())
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2019, 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.
#include <map>
#include <typeindex>
+#include "gromacs/utility/any.h"
#include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/variant.h"
namespace gmx
{
/*! \libinternal \brief
- * Helper for converting from Variant to a given type.
+ * Helper for converting from Any to a given type.
*
* \tparam OutType Type this converter converts to.
*
* Default-constructed converter only supports identity mapping from the a
- * Variant holding `OutType`. To add support for additional input types,
+ * Any holding `OutType`. To add support for additional input types,
* provide conversion functions with addConverter(). To use a non-identity
* mapping for an `OutType` -> `OutType` conversion, provide an alternative
* conversion from `OutType` with addConverter().
{
public:
/*! \brief
- * Converts a Variant value to the output type.
+ * Converts a Any value to the output type.
*
* \returns Converted value.
- * \throws InvalidInputError If the input Variant has a type that is
+ * \throws InvalidInputError If the input Any has a type that is
* not recognized by any conversion.
*/
- OutType convert(const Variant &value) const
+ OutType convert(const Any &value) const
{
std::type_index type(value.type());
auto iter = converters_.find(type);
void addConverter(std::function<OutType(const InType &)> func)
{
converters_[std::type_index(typeid(InType))] =
- [func] (const Variant &value)
+ [func] (const Any &value)
{
return func(value.cast<InType>());
};
void addCastConversion()
{
converters_[std::type_index(typeid(InType))] =
- [] (const Variant &value)
+ [] (const Any &value)
{
return static_cast<OutType>(value.cast<InType>());
};
}
private:
- typedef std::function<OutType(const Variant &value)> ConversionFunction;
+ typedef std::function<OutType(const Any &value)> ConversionFunction;
std::map<std::type_index, ConversionFunction> converters_;
};
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2016,2018,2019, 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.
OptionInfo &optionInfo() override { return info_; }
std::string typeString() const override { return "file"; }
int valueCount() const override { return 0; }
- std::vector<Variant> defaultValues() const override { return {}; }
+ std::vector<Any> defaultValues() const override { return {}; }
std::vector<std::string> defaultValuesAsStrings() const override { return {}; }
- std::vector<Variant>
- normalizeValues(const std::vector<Variant> &values) const override { return values; }
+ std::vector<Any>
+ normalizeValues(const std::vector<Any> &values) const override { return values; }
private:
void clearSet() override;
- void convertValue(const Variant &value) override;
+ void convertValue(const Any &value) override;
void processSet() override;
void processAll() override {}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
}
-std::vector<Variant>
-SelectionOptionStorage::normalizeValues(const std::vector<Variant> & /*values*/) const
+std::vector<Any>
+SelectionOptionStorage::normalizeValues(const std::vector<Any> & /*values*/) const
{
GMX_THROW(NotImplementedError("Selection options not supported in this context"));
}
}
-void SelectionOptionStorage::convertValue(const Variant &value)
+void SelectionOptionStorage::convertValue(const Any &value)
{
manager_.convertOptionValue(this, value.cast<std::string>(), false);
}
bValueParsed_ = false;
}
-void SelectionFileOptionStorage::convertValue(const Variant &value)
+void SelectionFileOptionStorage::convertValue(const Any &value)
{
if (bValueParsed_)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2018,2019, 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.
OptionInfo &optionInfo() override { return info_; }
std::string typeString() const override { return "selection"; }
std::string formatSingleValue(const Selection &value) const override;
- std::vector<Variant>
- normalizeValues(const std::vector<Variant> &values) const override;
+ std::vector<Any>
+ normalizeValues(const std::vector<Any> &values) const override;
/*! \brief
* Adds selections to the storage.
void setSelectionFlag(SelectionFlag flag, bool bSet);
private:
- void convertValue(const Variant &value) override;
+ void convertValue(const Any &value) override;
void processSetValues(ValueList *values) override;
void processAll() override;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019, 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.
*/
/*! \internal \file
* \brief
- * Implements functionality from variant.h.
+ * Implements functionality from any.h.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_utility
*/
#include "gmxpre.h"
-#include "variant.h"
+#include "any.h"
#include <string>
{
//! \cond libapi
-std::string simpleValueToString(const Variant &value)
+std::string simpleValueToString(const Any &value)
{
if (value.isType<bool>())
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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 gmx::Variant.
+ * Declares gmx::Any.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \inlibraryapi
* \ingroup module_utility
*/
-#ifndef GMX_UTILITY_VARIANT_H
-#define GMX_UTILITY_VARIANT_H
+#ifndef GMX_UTILITY_ANY_H
+#define GMX_UTILITY_ANY_H
#include <memory>
#include <string>
/*! \libinternal \brief
* Represents a dynamically typed value of an arbitrary type.
*
- * To create a variant, either initialize it as empty, or with the create()
+ * To create a any, either initialize it as empty, or with the create()
* method (or the equivalent constructor, if the type parameter can be deduced
* and is clear to the reader from the context).
*
- * To query the type of the contents in the variant, use isEmpty(), type(), and
+ * To query the type of the contents in the any, use isEmpty(), type(), and
* isType().
*
* To access the value, you need to know the type as a compile-time constant
*
* \ingroup module_utility
*/
-class Variant
+class Any
{
public:
/*! \brief
- * Creates a variant that holds the given value.
+ * Creates a any that holds the given value.
*
* \throws std::bad_alloc if out of memory.
*
* contrary to the templated constructor.
*/
template <typename T>
- static Variant create(const T &value) { return Variant(value); }
+ static Any create(const T &value) { return Any(value); }
/*! \brief
- * Creates a variant that holds the given value.
+ * Creates a any that holds the given value.
*
* \throws std::bad_alloc if out of memory.
*
* method avoids copying when move-construction is possible.
*/
template <typename T>
- static Variant create(T &&value) { return Variant(std::forward<T>(value)); }
+ static Any create(T &&value) { return Any(std::forward<T>(value)); }
- //! Creates an empty variant value.
- Variant() {}
+ //! Creates an empty any value.
+ Any() {}
/*! \brief
- * Creates a variant that holds the given value.
+ * Creates a any that holds the given value.
*
* \throws std::bad_alloc if out of memory.
*/
- template <typename T, typename = typename std::enable_if<!std::is_same<T, Variant>::value>::type>
- explicit Variant(T &&value)
+ template <typename T, typename = typename std::enable_if<!std::is_same<T, Any>::value>::type>
+ explicit Any(T &&value)
: content_(new Content<typename std::decay<T>::type>(std::forward<T>(value)))
{
}
/*! \brief
- * Creates a deep copy of a variant.
+ * Creates a deep copy of a any.
*
* \throws std::bad_alloc if out of memory.
*/
- Variant(const Variant &other) : content_(other.cloneContent()) {}
- //! Move-constructs a variant.
- Variant(Variant &&other) noexcept : content_(std::move(other.content_)) {}
+ Any(const Any &other) : content_(other.cloneContent()) {}
+ //! Move-constructs a any.
+ Any(Any &&other) noexcept : content_(std::move(other.content_)) {}
/*! \brief
- * Assigns the variant.
+ * Assigns the any.
*
* \throws std::bad_alloc if out of memory.
*/
- Variant &operator=(const Variant &other)
+ Any &operator=(const Any &other)
{
content_ = other.cloneContent();
return *this;
}
- //! Move-assigns the variant.
- Variant &operator=(Variant &&other) noexcept
+ //! Move-assigns the any.
+ Any &operator=(Any &&other) noexcept
{
content_ = std::move(other.content_);
return *this;
/*! \brief
* Gets the value when the type is known.
*
- * \tparam T Type to get (which must match what the variant stores).
+ * \tparam T Type to get (which must match what the any stores).
*
- * Asserts if the variant is empty or does not contain the requested type.
+ * Asserts if the any is empty or does not contain the requested type.
*/
template <typename T>
const T &cast() const
/*! \brief
* Gets the value when the type is known as a modifiable reference.
*
- * \tparam T Type to get (which must match what the variant stores).
+ * \tparam T Type to get (which must match what the any stores).
*
- * Asserts if the variant is empty or does not contain the requested type.
+ * Asserts if the any is empty or does not contain the requested type.
*/
template <typename T>
T &castRef()
//! \cond libapi
/*! \brief
- * Converts a Variant value to a string.
+ * Converts a Any value to a string.
*
* As the name suggests, only some types of "simple" values (such as int) are
* supported. Asserts for unsupported types.
*
* \ingroup module_utility
*/
-std::string simpleValueToString(const Variant &value);
+std::string simpleValueToString(const Any &value);
//! \endcond
} // namespace gmx
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
#include <utility>
#include <vector>
+#include "gromacs/utility/any.h"
#include "gromacs/utility/real.h"
-#include "gromacs/utility/variant.h"
namespace gmx
{
template <typename T>
const T &cast() const { return value_.cast<T>(); }
- //! Returns the raw Variant value (always possible).
- const Variant &asVariant() const { return value_; }
+ //! Returns the raw Any value (always possible).
+ const Any &asAny() const { return value_; }
private:
- explicit KeyValueTreeValue(Variant &&value) : value_(std::move(value)) {}
+ explicit KeyValueTreeValue(Any &&value) : value_(std::move(value)) {}
- Variant value_;
+ Any value_;
friend class KeyValueTreeBuilder;
friend class KeyValueTreeObjectBuilder;
static inline std::string
simpleValueToString(const KeyValueTreeValue &value)
{
- return simpleValueToString(value.asVariant());
+ return simpleValueToString(value.asAny());
}
//! \endcond
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2019, 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.
#include <utility>
#include <vector>
+#include "gromacs/utility/any.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/keyvaluetree.h"
-#include "gromacs/utility/variant.h"
namespace gmx
{
template <typename T>
static KeyValueTreeValue createValue(const T &value)
{
- return KeyValueTreeValue(Variant::create<T>(value));
+ return KeyValueTreeValue(Any::create<T>(value));
}
/*! \brief
* Helper function for other builders to create default-constructed
template <typename T>
static KeyValueTreeValue createValue()
{
- return KeyValueTreeValue(Variant::create<T>(T()));
+ return KeyValueTreeValue(Any::create<T>(T()));
}
KeyValueTreeObject root_;
template <typename T>
void setValue(const T &value)
{
- value_ = Variant::create<T>(value);
+ value_ = Any::create<T>(value);
}
- //! Assigns a Variant value to the built value.
- void setVariantValue(Variant &&value)
+ //! Assigns a Any value to the built value.
+ void setAnyValue(Any &&value)
{
value_ = std::move(value);
}
KeyValueTreeValue build() { return KeyValueTreeValue(std::move(value_)); }
private:
- Variant value_;
+ Any value_;
};
class KeyValueTreeArrayBuilderBase
{
}
- //! Appends a raw Variant value to the array.
- KeyValueTreeValue &addRawValue(Variant &&value)
+ //! Appends a raw Any value to the array.
+ KeyValueTreeValue &addRawValue(Any &&value)
{
KeyValueTreeValueBuilder builder;
- builder.setVariantValue(std::move(value));
+ builder.setAnyValue(std::move(value));
array_->values_.push_back(builder.build());
return array_->values_.back();
}
{
addProperty(key, std::move(value));
}
- //! Adds a property with given key from a Variant value.
- void addRawValue(const std::string &key, Variant &&value)
+ //! Adds a property with given key from a Any value.
+ void addRawValue(const std::string &key, Any &&value)
{
addProperty(key, KeyValueTreeValue(std::move(value)));
}
inline KeyValueTreeObjectBuilder KeyValueTreeValueBuilder::createObject()
{
- value_ = Variant::create<KeyValueTreeObject>(KeyValueTreeObject());
+ value_ = Any::create<KeyValueTreeObject>(KeyValueTreeObject());
return KeyValueTreeObjectBuilder(&value_.castRef<KeyValueTreeObject>());
}
inline KeyValueTreeArrayBuilder KeyValueTreeValueBuilder::createArray()
{
- value_ = Variant::create<KeyValueTreeArray>(KeyValueTreeArray());
+ value_ = Any::create<KeyValueTreeArray>(KeyValueTreeArray());
return KeyValueTreeArrayBuilder(&value_.castRef<KeyValueTreeArray>());
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
data_->keyMatchRule_ = true;
}
-void KeyValueTreeTransformRuleBuilder::addTransformToVariant(
- const std::function<Variant(const Variant &)> &transform)
+void KeyValueTreeTransformRuleBuilder::addTransformToAny(
+ const std::function<Any(const Any &)> &transform)
{
data_->transform_ =
[transform] (KeyValueTreeValueBuilder *builder, const KeyValueTreeValue &value)
{
- builder->setVariantValue(transform(value.asVariant()));
+ builder->setAnyValue(transform(value.asAny()));
};
}
void KeyValueTreeTransformRuleBuilder::addTransformToObject(
- const std::function<void(KeyValueTreeObjectBuilder *, const Variant &)> &transform)
+ const std::function<void(KeyValueTreeObjectBuilder *, const Any &)> &transform)
{
data_->transform_ =
[transform] (KeyValueTreeValueBuilder *builder, const KeyValueTreeValue &value)
{
KeyValueTreeObjectBuilder obj = builder->createObject();
- transform(&obj, value.asVariant());
+ transform(&obj, value.asAny());
};
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
#include <typeindex>
#include <vector>
+#include "gromacs/utility/any.h"
#include "gromacs/utility/classhelpers.h"
#include "gromacs/utility/keyvaluetree.h"
-#include "gromacs/utility/variant.h"
namespace gmx
{
*/
void transformWith(std::function<ToType(const FromType &)> transform)
{
- builder_->addTransformToVariant(
- [transform] (const Variant &value)
+ builder_->addTransformToAny(
+ [transform] (const Any &value)
{
- return Variant::create<ToType>(transform(value.cast<FromType>()));
+ return Any::create<ToType>(transform(value.cast<FromType>()));
});
}
};
void transformWith(std::function<void(KeyValueTreeObjectBuilder *, const FromType &)> transform)
{
builder_->addTransformToObject(
- [transform] (KeyValueTreeObjectBuilder *builder, const Variant &value)
+ [transform] (KeyValueTreeObjectBuilder *builder, const Any &value)
{
transform(builder, value.cast<FromType>());
});
void setExpectedType(const std::type_index &type);
void setToPath(const KeyValueTreePath &path);
void setKeyMatchType(StringCompareType keyMatchType);
- void addTransformToVariant(const std::function<Variant(const Variant &)> &transform);
- void addTransformToObject(const std::function<void(KeyValueTreeObjectBuilder *, const Variant &)> &transform);
+ void addTransformToAny(const std::function<Any(const Any &)> &transform);
+ void addTransformToObject(const std::function<void(KeyValueTreeObjectBuilder *, const Any &)> &transform);
class Data;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/ioptionscontainer.h"
+#include "gromacs/utility/any.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/real.h"
#include "gromacs/utility/stringutil.h"
-#include "gromacs/utility/variant.h"
#include "testutils/refdata-checkers.h"
#include "testutils/refdata-impl.h"
}
-void TestReferenceChecker::checkVariant(const Variant &variant, const char *id)
+void TestReferenceChecker::checkAny(const Any &any, const char *id)
{
- if (variant.isType<bool>())
+ if (any.isType<bool>())
{
- checkBoolean(variant.cast<bool>(), id);
+ checkBoolean(any.cast<bool>(), id);
}
- else if (variant.isType<int>())
+ else if (any.isType<int>())
{
- checkInteger(variant.cast<int>(), id);
+ checkInteger(any.cast<int>(), id);
}
- else if (variant.isType<int64_t>())
+ else if (any.isType<int64_t>())
{
- checkInt64(variant.cast<int64_t>(), id);
+ checkInt64(any.cast<int64_t>(), id);
}
- else if (variant.isType<float>())
+ else if (any.isType<float>())
{
- checkFloat(variant.cast<float>(), id);
+ checkFloat(any.cast<float>(), id);
}
- else if (variant.isType<double>())
+ else if (any.isType<double>())
{
- checkDouble(variant.cast<double>(), id);
+ checkDouble(any.cast<double>(), id);
}
- else if (variant.isType<std::string>())
+ else if (any.isType<std::string>())
{
- checkString(variant.cast<std::string>(), id);
+ checkString(any.cast<std::string>(), id);
}
else
{
- GMX_THROW(TestException("Unsupported variant type"));
+ GMX_THROW(TestException("Unsupported any type"));
}
}
}
else
{
- checkVariant(value.asVariant(), id);
+ checkAny(value.asAny(), id);
}
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
class IOptionsContainer;
class KeyValueTreeObject;
class KeyValueTreeValue;
-class Variant;
+class Any;
namespace test
{
void checkVector(const double value[3], const char *id);
//! Check a single floating-point value from a string.
void checkRealFromString(const std::string &value, const char *id);
- //! Checks a variant value that contains a supported simple type.
- void checkVariant(const Variant &value, const char *id);
+ //! Checks a any value that contains a supported simple type.
+ void checkAny(const Any &value, const char *id);
//! Checks a key-value tree rooted at a object.
void checkKeyValueTreeObject(const KeyValueTreeObject &tree, const char *id);
//! Checks a generic key-value tree value.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2019, 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.
#include <gtest/gtest.h>
#include <gtest/gtest-spi.h>
+#include "gromacs/utility/any.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/keyvaluetreebuilder.h"
-#include "gromacs/utility/variant.h"
#include "testutils/testasserts.h"
#include "testutils/testexceptions.h"
}
-TEST(ReferenceDataTest, HandlesVariants)
+TEST(ReferenceDataTest, HandlesAnys)
{
- using gmx::Variant;
+ using gmx::Any;
{
TestReferenceData data(gmx::test::erefdataUpdateAll);
TestReferenceChecker checker(data.rootChecker());
- checker.checkVariant(Variant::create<bool>(true), "bool");
- checker.checkVariant(Variant::create<int>(1), "int");
- checker.checkVariant(Variant::create<double>(3.5), "real");
- checker.checkVariant(Variant::create<std::string>("foo"), "str");
+ checker.checkAny(Any::create<bool>(true), "bool");
+ checker.checkAny(Any::create<int>(1), "int");
+ checker.checkAny(Any::create<double>(3.5), "real");
+ checker.checkAny(Any::create<std::string>("foo"), "str");
}
{
TestReferenceData data(gmx::test::erefdataCompare);
TestReferenceChecker checker(data.rootChecker());
- checker.checkVariant(Variant::create<bool>(true), "bool");
- checker.checkVariant(Variant::create<int>(1), "int");
- checker.checkVariant(Variant::create<double>(3.5), "real");
- checker.checkVariant(Variant::create<std::string>("foo"), "str");
+ checker.checkAny(Any::create<bool>(true), "bool");
+ checker.checkAny(Any::create<int>(1), "int");
+ checker.checkAny(Any::create<double>(3.5), "real");
+ checker.checkAny(Any::create<std::string>("foo"), "str");
}
}
}
-TEST(ReferenceDataTest, HandlesVariantsWithIncorrectValue)
+TEST(ReferenceDataTest, HandlesAnysWithIncorrectValue)
{
- using gmx::Variant;
+ using gmx::Any;
{
TestReferenceData data(gmx::test::erefdataUpdateAll);
TestReferenceChecker checker(data.rootChecker());
- checker.checkVariant(Variant::create<bool>(true), "bool");
- checker.checkVariant(Variant::create<int>(1), "int");
- checker.checkVariant(Variant::create<double>(3.5), "real");
- checker.checkVariant(Variant::create<std::string>("foo"), "str");
+ checker.checkAny(Any::create<bool>(true), "bool");
+ checker.checkAny(Any::create<int>(1), "int");
+ checker.checkAny(Any::create<double>(3.5), "real");
+ checker.checkAny(Any::create<std::string>("foo"), "str");
}
{
TestReferenceData data(gmx::test::erefdataCompare);
TestReferenceChecker checker(data.rootChecker());
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<bool>(false), "bool"), "");
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<int>(2), "int"), "");
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<double>(2.5), "real"), "");
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<std::string>("bar"), "str"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<bool>(false), "bool"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<int>(2), "int"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<double>(2.5), "real"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<std::string>("bar"), "str"), "");
}
}
-TEST(ReferenceDataTest, HandlesVariantsWithIncorrectType)
+TEST(ReferenceDataTest, HandlesAnysWithIncorrectType)
{
- using gmx::Variant;
+ using gmx::Any;
{
TestReferenceData data(gmx::test::erefdataUpdateAll);
TestReferenceChecker checker(data.rootChecker());
- checker.checkVariant(Variant::create<bool>(true), "bool");
- checker.checkVariant(Variant::create<int>(1), "int");
- checker.checkVariant(Variant::create<double>(3.5), "real");
+ checker.checkAny(Any::create<bool>(true), "bool");
+ checker.checkAny(Any::create<int>(1), "int");
+ checker.checkAny(Any::create<double>(3.5), "real");
}
{
TestReferenceData data(gmx::test::erefdataCompare);
TestReferenceChecker checker(data.rootChecker());
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<int>(1), "bool"), "");
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<bool>(true), "int"), "");
- EXPECT_NONFATAL_FAILURE(checker.checkVariant(Variant::create<int>(2), "real"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<int>(1), "bool"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<bool>(true), "int"), "");
+ EXPECT_NONFATAL_FAILURE(checker.checkAny(Any::create<int>(2), "real"), "");
}
}