eina-cxx: Moved variant to eina C++

This commit is contained in:
Felipe Magno de Almeida 2016-08-15 14:47:00 -03:00
parent f9401c16f0
commit dbed78ad3b
6 changed files with 42 additions and 23 deletions

View File

@ -94,11 +94,11 @@ generate(const Eolian_Class* klass, eolian_cxx::options_type const& opts)
variant_function = [&] (efl::eolian::grammar::attributes::type_def const& type)
{
if(efl::eolian::grammar::attributes::klass_name const*
name = efl::eolian::grammar::attributes::get<efl::eolian::grammar::attributes::klass_name>
name = efl::eina::get<efl::eolian::grammar::attributes::klass_name>
(&type.original_type))
klass_name_function(*name);
else if(efl::eolian::grammar::attributes::complex_type_def const*
complex = efl::eolian::grammar::attributes::get<efl::eolian::grammar::attributes::complex_type_def>
complex = efl::eina::get<efl::eolian::grammar::attributes::complex_type_def>
(&type.original_type))
complex_function(*complex);
};

View File

@ -27,6 +27,7 @@
#include <eina_future.hh>
#include <eina_deleter.hh>
#include <eina_copy_traits.hh>
#include <eina_variant.hh>
/**
* @page eina_cxx_main Eina C++ (BETA)

View File

@ -1,5 +1,5 @@
#ifndef EOLIAN_CXX_VARIANT_HH_
#define EOLIAN_CXX_VARIANT_HH_
#ifndef EINA_VARIANT_HH_
#define EINA_VARIANT_HH_
#include <cstddef>
#include <algorithm>
@ -7,10 +7,34 @@
#include <type_traits>
#include <tuple>
#include "grammar/meta.hpp"
namespace efl { namespace eina {
namespace efl { namespace eolian { namespace grammar { namespace attributes {
namespace _impl {
template <typename T, typename U, typename...Others>
struct is_one_of : std::conditional<std::is_same<T, U>::value
, std::is_same<T, U>
, is_one_of<T, Others...> >::type::type
{};
template <typename T, typename U>
struct is_one_of<T, U> : std::is_same<T, U>
{};
template <std::size_t size, typename T, typename U, typename...Args>
struct find_impl : find_impl<size+1, T, Args...>
{};
template <std::size_t size, typename T, typename...Args>
struct find_impl<size, T, T, Args...> : std::integral_constant<std::size_t, size> {};
template <typename T, typename U, typename...Args>
struct find : find_impl<0u, T, U, Args...>
{};
}
template <std::size_t N, std::size_t L, typename Tuple>
struct call_visitor
{
@ -133,9 +157,9 @@ struct variant
template <typename T>
variant(T object,
typename std::enable_if<meta::is_one_of
typename std::enable_if<_impl::is_one_of
<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value>::type* = 0)
: type(meta::find<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value)
: type(_impl::find<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value)
{
construct(object);
}
@ -212,11 +236,7 @@ private:
new (&buffer) T(std::move(object));
}
typedef typename std::aligned_storage
<
meta::max<sizeof(Args)...>::value
, meta::max<std::alignment_of<Args>::value...>::value
>::type buffer_type;
typedef typename std::aligned_union<1, Args...>::type buffer_type;
friend bool operator==(variant<Args...> const& lhs, variant<Args...> const& rhs)
{
@ -239,19 +259,19 @@ inline bool operator!=(variant<Args...>const& lhs, variant<Args...> const& rhs)
}
template <typename T, typename...Args>
T* get(variant<Args...>* variant, typename std::enable_if<meta::is_one_of
T* get(variant<Args...>* variant, typename std::enable_if<_impl::is_one_of
<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value>::type* = 0)
{
return variant->visit(get_visitor<T>{});
}
template <typename T, typename...Args>
T const* get(variant<Args...>const* variant, typename std::enable_if<meta::is_one_of
T const* get(variant<Args...>const* variant, typename std::enable_if<_impl::is_one_of
<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value>::type* = 0)
{
return variant->visit(get_visitor<T const>{});
}
template <typename T, typename...Args>
T& get(variant<Args...>& variant, typename std::enable_if<meta::is_one_of
T& get(variant<Args...>& variant, typename std::enable_if<_impl::is_one_of
<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value>::type* = 0)
{
T* p = variant.visit(get_visitor<T>{});
@ -261,7 +281,7 @@ T& get(variant<Args...>& variant, typename std::enable_if<meta::is_one_of
throw std::logic_error("");
}
template <typename T, typename...Args>
T const& get(variant<Args...>const& variant, typename std::enable_if<meta::is_one_of
T const& get(variant<Args...>const& variant, typename std::enable_if<_impl::is_one_of
<typename std::remove_cv<typename std::remove_reference<T>::type>::type, Args...>::value>::type* = 0)
{
T const* p = variant.visit(get_visitor<T const>{});
@ -271,6 +291,6 @@ T const& get(variant<Args...>const& variant, typename std::enable_if<meta::is_on
throw std::logic_error("");
}
} } } }
} }
#endif

View File

@ -3,7 +3,6 @@
#include "grammar/generator.hpp"
#include "grammar/meta.hpp"
#include "grammar/variant.hpp"
namespace efl { namespace eolian { namespace grammar {
@ -11,7 +10,7 @@ template <typename L, typename R>
struct alternative_generator
{
template <typename OutputIterator, typename...Args, typename Context>
bool generate(OutputIterator /*sink*/, attributes::variant<Args...> const& /*attribute*/, Context const& /*context*/) const
bool generate(OutputIterator /*sink*/, eina::variant<Args...> const& /*attribute*/, Context const& /*context*/) const
{
// return grammar::alternative_sequence(left, right, sink, attribute);
return false;

View File

@ -2,7 +2,6 @@
#define EOLIAN_CXX_KLASS_DEF_HH
#include "grammar/type_traits.hpp"
#include "grammar/variant.hpp"
#include "grammar/attributes.hpp"
#include "grammar/qualifier_def.hpp"
#include "grammar/string.hpp"
@ -201,7 +200,7 @@ inline bool operator!=(complex_type_def const& lhs, complex_type_def const& rhs)
struct type_def
{
typedef attributes::variant<klass_name, regular_type_def, complex_type_def> variant_type;
typedef eina::variant<klass_name, regular_type_def, complex_type_def> variant_type;
variant_type original_type;
std::string c_type;

View File

@ -305,7 +305,7 @@ struct visitor_generate
if(v.empty())
return true;
else if(attributes::complex_type_def const* complex
= attributes::get<attributes::complex_type_def>(&v))
= eina::get<attributes::complex_type_def>(&v))
return default_match(*complex);
else
return v.visit(*this);