Skip to content
Snippets Groups Projects
Commit be4a92eb authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

mapbox::variant was replaced with boost::variant, since we anyway depend on boost

parent df5568f4
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,7 @@ MultiOption::variant_t& MultiOption::value() ...@@ -41,7 +41,7 @@ MultiOption::variant_t& MultiOption::value()
return m_value; return m_value;
} }
MultiOption::variant_t &MultiOption::defaultValue() MultiOption::variant_t& MultiOption::defaultValue()
{ {
return m_default_value; return m_default_value;
} }
...@@ -17,20 +17,20 @@ ...@@ -17,20 +17,20 @@
#define MULTIOPTION_H #define MULTIOPTION_H
#include "WinDllMacros.h" #include "WinDllMacros.h"
#include <variant.hpp> #include <boost/variant.hpp>
#include <variant_io.hpp>
#include <string> #include <string>
//! @class MultiOption //! @class MultiOption
//! @ingroup fitting_internal //! @ingroup fitting_internal
//! @brief The MultiOption class is intended to store a single option for minimization //! @brief The MultiOption class is intended to store a single option for minimization
//! algorithm. Int, double, string values are available. //! algorithm. Int, double, string values are available.
//! Relies on https://github.com/mapbox/variant, will be switched to std::variant in C++-17. //! Relies on boost::variant, will be switched to std::variant in C++-17.
//! (before was https://github.com/mapbox/variant).
class BA_CORE_API_ MultiOption class BA_CORE_API_ MultiOption
{ {
public: public:
using variant_t = mapbox::util::variant<int, double, std::string>; using variant_t = boost::variant<int, double, std::string>;
explicit MultiOption(const std::string &name = std::string()); explicit MultiOption(const std::string &name = std::string());
...@@ -74,14 +74,14 @@ MultiOption::MultiOption(const std::string &name, const T &t, const std::string ...@@ -74,14 +74,14 @@ MultiOption::MultiOption(const std::string &name, const T &t, const std::string
template<typename T> template<typename T>
T MultiOption::get() const T MultiOption::get() const
{ {
return m_value.get<T>(); return boost::get<T>(m_value);
} }
template<typename T> template<typename T>
T MultiOption::getDefault() const T MultiOption::getDefault() const
{ {
return m_default_value.get<T>(); return boost::get<T>(m_default_value);
} }
#endif // MINIMIZEROPTION_H #endif
#ifndef MAPBOX_UTIL_RECURSIVE_WRAPPER_HPP
#define MAPBOX_UTIL_RECURSIVE_WRAPPER_HPP
// Based on variant/recursive_wrapper.hpp from boost.
//
// Original license:
//
// Copyright (c) 2002-2003
// Eric Friedman, Itay Maman
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cassert>
#include <utility>
namespace mapbox {
namespace util {
template <typename T>
class recursive_wrapper
{
T* p_;
void assign(T const& rhs)
{
this->get() = rhs;
}
public:
using type = T;
/**
* Default constructor default initializes the internally stored value.
* For POD types this means nothing is done and the storage is
* uninitialized.
*
* @throws std::bad_alloc if there is insufficient memory for an object
* of type T.
* @throws any exception thrown by the default constructur of T.
*/
recursive_wrapper()
: p_(new T){}
~recursive_wrapper() noexcept { delete p_; }
recursive_wrapper(recursive_wrapper const& operand)
: p_(new T(operand.get())) {}
recursive_wrapper(T const& operand)
: p_(new T(operand)) {}
recursive_wrapper(recursive_wrapper&& operand)
: p_(new T(std::move(operand.get()))) {}
recursive_wrapper(T&& operand)
: p_(new T(std::move(operand))) {}
inline recursive_wrapper& operator=(recursive_wrapper const& rhs)
{
assign(rhs.get());
return *this;
}
inline recursive_wrapper& operator=(T const& rhs)
{
assign(rhs);
return *this;
}
inline void swap(recursive_wrapper& operand) noexcept
{
T* temp = operand.p_;
operand.p_ = p_;
p_ = temp;
}
recursive_wrapper& operator=(recursive_wrapper&& rhs) noexcept
{
swap(rhs);
return *this;
}
recursive_wrapper& operator=(T&& rhs)
{
get() = std::move(rhs);
return *this;
}
T& get()
{
assert(p_);
return *get_pointer();
}
T const& get() const
{
assert(p_);
return *get_pointer();
}
T* get_pointer() { return p_; }
const T* get_pointer() const { return p_; }
operator T const&() const { return this->get(); }
operator T&() { return this->get(); }
}; // class recursive_wrapper
template <typename T>
inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) noexcept
{
lhs.swap(rhs);
}
} // namespace util
} // namespace mapbox
#endif // MAPBOX_UTIL_RECURSIVE_WRAPPER_HPP
This diff is collapsed.
#ifndef MAPBOX_UTIL_VARIANT_IO_HPP
#define MAPBOX_UTIL_VARIANT_IO_HPP
#include <iosfwd>
#include <variant.hpp>
namespace mapbox {
namespace util {
namespace detail {
// operator<< helper
template <typename Out>
class printer
{
public:
explicit printer(Out& out)
: out_(out) {}
printer& operator=(printer const&) = delete;
// visitor
template <typename T>
void operator()(T const& operand) const
{
out_ << operand;
}
private:
Out& out_;
};
}
// operator<<
template <typename CharT, typename Traits, typename... Types>
VARIANT_INLINE std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& out, variant<Types...> const& rhs)
{
detail::printer<std::basic_ostream<CharT, Traits>> visitor(out);
apply_visitor(visitor, rhs);
return out;
}
} // namespace util
} // namespace mapbox
#endif // MAPBOX_UTIL_VARIANT_IO_HPP
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "FitParameter.h" #include "FitParameter.h"
#include "FitProgressInfo.h" #include "FitProgressInfo.h"
#include "FitSuite.h" #include "FitSuite.h"
#include "FitParameterSet.h" #include "FitSuiteParameters.h"
#include "GUIHelpers.h" #include "GUIHelpers.h"
#include "IntensityDataItem.h" #include "IntensityDataItem.h"
#include <QDebug> #include <QDebug>
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define MULTIOPTIONTEST_H #define MULTIOPTIONTEST_H
#include "MultiOption.h" #include "MultiOption.h"
#include <variant.hpp>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
...@@ -18,16 +17,19 @@ TEST_F(MultiOptionTest, Variant) ...@@ -18,16 +17,19 @@ TEST_F(MultiOptionTest, Variant)
MultiOption::variant_t v1(1); MultiOption::variant_t v1(1);
EXPECT_EQ(0, v1.which()); EXPECT_EQ(0, v1.which());
EXPECT_EQ(1, v1.get<int>()); // EXPECT_EQ(1, v1.get<int>());
EXPECT_EQ(1, boost::get<int>(v1));
v1 = 2.0; v1 = 2.0;
EXPECT_EQ(1, v1.which()); EXPECT_EQ(1, v1.which());
EXPECT_EQ(2.0, v1.get<double>()); //EXPECT_EQ(2.0, v1.get<double>());
EXPECT_EQ(2.0, boost::get<double>(v1));
const std::string text("xxx"); const std::string text("xxx");
v1 = text; v1 = text;
EXPECT_EQ(2, v1.which()); EXPECT_EQ(2, v1.which());
EXPECT_EQ(text, v1.get<std::string>()); // EXPECT_EQ(text, v1.get<std::string>());
EXPECT_EQ(text, boost::get<std::string>(v1));
} }
TEST_F(MultiOptionTest, Construction) TEST_F(MultiOptionTest, Construction)
...@@ -39,7 +41,6 @@ TEST_F(MultiOptionTest, Construction) ...@@ -39,7 +41,6 @@ TEST_F(MultiOptionTest, Construction)
EXPECT_EQ(name, opt.name()); EXPECT_EQ(name, opt.name());
EXPECT_EQ(description, opt.description()); EXPECT_EQ(description, opt.description());
EXPECT_EQ(double_value, opt.value().get<double>());
EXPECT_EQ(double_value, opt.get<double>()); EXPECT_EQ(double_value, opt.get<double>());
EXPECT_EQ(double_value, opt.getDefault<double>()); EXPECT_EQ(double_value, opt.getDefault<double>());
...@@ -60,7 +61,6 @@ TEST_F(MultiOptionTest, Copying) ...@@ -60,7 +61,6 @@ TEST_F(MultiOptionTest, Copying)
MultiOption copy(opt); MultiOption copy(opt);
EXPECT_EQ(name, copy.name()); EXPECT_EQ(name, copy.name());
EXPECT_EQ(description, copy.description()); EXPECT_EQ(description, copy.description());
EXPECT_EQ(double_value, copy.value().get<double>());
EXPECT_EQ(double_value, copy.get<double>()); EXPECT_EQ(double_value, copy.get<double>());
EXPECT_EQ(double_value, copy.getDefault<double>()); EXPECT_EQ(double_value, copy.getDefault<double>());
} }
...@@ -80,7 +80,6 @@ TEST_F(MultiOptionTest, Assignment) ...@@ -80,7 +80,6 @@ TEST_F(MultiOptionTest, Assignment)
EXPECT_EQ(name, copy.name()); EXPECT_EQ(name, copy.name());
EXPECT_EQ(description, copy.description()); EXPECT_EQ(description, copy.description());
EXPECT_EQ(double_value, copy.value().get<double>());
EXPECT_EQ(double_value, copy.get<double>()); EXPECT_EQ(double_value, copy.get<double>());
EXPECT_EQ(double_value, copy.getDefault<double>()); EXPECT_EQ(double_value, copy.getDefault<double>());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment