Commit 8f59898e authored by neverlord's avatar neverlord

refactoring

parent b07c74d8
......@@ -49,7 +49,7 @@
<valuelist key="GenericProjectManager.GenericMakeStep.BuildTargets" type="QVariantList">
<value type="QString">all</value>
</valuelist>
<value key="GenericProjectManager.GenericMakeStep.MakeArguments" type="QString"></value>
<value key="GenericProjectManager.GenericMakeStep.MakeArguments" type="QString">-j 2</value>
<value key="GenericProjectManager.GenericMakeStep.MakeCommand" type="QString"></value>
<value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Make</value>
<value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
......@@ -135,7 +135,7 @@
</data>
<data>
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
<value type="QString">{23902c37-f07e-47cd-bb19-c366b9f708db}</value>
<value type="QString">{07fcd197-092d-45a0-8500-3be614e6ae31}</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
......
......@@ -3,7 +3,6 @@ cppa/tuple.hpp
unit_testing/main.cpp
cppa/util/void_type.hpp
cppa/util/type_list.hpp
cppa/util/type_at.hpp
cppa/util/a_matches_b.hpp
cppa/util.hpp
cppa/util/is_one_of.hpp
......@@ -48,7 +47,6 @@ cppa/util/has_copy_member_fun.hpp
cppa/detail/intermediate.hpp
cppa/detail/invokable.hpp
cppa/invoke_rules.hpp
cppa/util/type_list_pop_back.hpp
cppa/invoke.hpp
cppa/on.hpp
unit_testing/test__serialization.cpp
......@@ -111,7 +109,6 @@ cppa/detail/default_uniform_type_info_impl.hpp
src/object.cpp
cppa/util/comparable.hpp
cppa/util/disable_if.hpp
cppa/util/if_else_type.hpp
cppa/util/wrapped_type.hpp
cppa/util/apply.hpp
cppa/primitive_variant.hpp
......@@ -153,3 +150,8 @@ src/exit_signal.cpp
cppa/to_string.hpp
src/string_serialization.cpp
cppa/from_string.hpp
cppa/util/at.hpp
cppa/util/element_at.hpp
cppa/util/if_else.hpp
cppa/util/pop_back.hpp
cppa/util/pt_dispatch.hpp
......@@ -48,7 +48,7 @@ class any_tuple
const void* at(size_t p) const;
const uniform_type_info& type_at(size_t p) const;
const uniform_type_info& type_info_at(size_t p) const;
const util::abstract_type_list& types() const;
......
......@@ -47,6 +47,8 @@
#include "cppa/util/enable_if.hpp"
#include "cppa/util/disable_if.hpp"
#include "cppa/detail/tdata.hpp"
namespace cppa {
namespace detail {
......@@ -106,7 +108,7 @@ actor_behavior* get_behavior(std::integral_constant<bool,true>,
const Arg0& arg0,
const Args&... args)
{
auto arg_tuple = std::make_tuple(arg0, args...);
detail::tdata<Arg0, Args...> arg_tuple(arg0, args...);
auto lambda = [fptr, arg_tuple]() { invoke(fptr, arg_tuple); };
return new fun_behavior<false, decltype(lambda)>(std::move(lambda));
}
......@@ -117,7 +119,7 @@ actor_behavior* get_behavior(std::integral_constant<bool,false>,
const Arg0& arg0,
const Args&... args)
{
auto arg_tuple = std::make_tuple(arg0, args...);
detail::tdata<Arg0, Args...> arg_tuple(arg0, args...);
auto lambda = [ftor, arg_tuple]() { invoke(ftor, arg_tuple); };
return new fun_behavior<false, decltype(lambda)>(std::move(lambda));
}
......
......@@ -20,7 +20,7 @@ struct abstract_tuple : ref_counted
virtual const void* at(size_t pos) const = 0;
virtual const util::abstract_type_list& types() const = 0;
virtual bool equal_to(const abstract_tuple& other) const = 0;
virtual const uniform_type_info& type_at(size_t pos) const = 0;
virtual const uniform_type_info& utype_info_at(size_t pos) const = 0;
};
......
......@@ -50,9 +50,9 @@ class decorated_tuple : public abstract_tuple
return m_decorated->at(m_mappings[pos]);
}
virtual const uniform_type_info& type_at(size_t pos) const
virtual const uniform_type_info& utype_info_at(size_t pos) const
{
return m_decorated->type_at(m_mappings[pos]);
return m_decorated->utype_info_at(m_mappings[pos]);
}
virtual const util::abstract_type_list& types() const
......
......@@ -42,7 +42,7 @@ class object_array : public detail::abstract_tuple
bool equal_to(const cppa::detail::abstract_tuple&) const;
const uniform_type_info& type_at(size_t pos) const;
const uniform_type_info& utype_info_at(size_t pos) const;
util::abstract_type_list::const_iterator begin() const;
......
......@@ -5,7 +5,7 @@
#include "cppa/primitive_type.hpp"
#include "cppa/util/if_else_type.hpp"
#include "cppa/util/if_else.hpp"
#include "cppa/util/wrapped_type.hpp"
namespace cppa { namespace detail {
......@@ -14,23 +14,23 @@ namespace cppa { namespace detail {
template<primitive_type PT>
struct ptype_to_type :
// signed integers
util::if_else_type_c<PT == pt_int8, std::int8_t,
util::if_else_type_c<PT == pt_int16, std::int16_t,
util::if_else_type_c<PT == pt_int32, std::int32_t,
util::if_else_type_c<PT == pt_int64, std::int64_t,
util::if_else_type_c<PT == pt_uint8, std::uint8_t,
util::if_else_c<PT == pt_int8, std::int8_t,
util::if_else_c<PT == pt_int16, std::int16_t,
util::if_else_c<PT == pt_int32, std::int32_t,
util::if_else_c<PT == pt_int64, std::int64_t,
util::if_else_c<PT == pt_uint8, std::uint8_t,
// unsigned integers
util::if_else_type_c<PT == pt_uint16, std::uint16_t,
util::if_else_type_c<PT == pt_uint32, std::uint32_t,
util::if_else_type_c<PT == pt_uint64, std::uint64_t,
util::if_else_c<PT == pt_uint16, std::uint16_t,
util::if_else_c<PT == pt_uint32, std::uint32_t,
util::if_else_c<PT == pt_uint64, std::uint64_t,
// floating points
util::if_else_type_c<PT == pt_float, float,
util::if_else_type_c<PT == pt_double, double,
util::if_else_type_c<PT == pt_long_double, long double,
util::if_else_c<PT == pt_float, float,
util::if_else_c<PT == pt_double, double,
util::if_else_c<PT == pt_long_double, long double,
// strings
util::if_else_type_c<PT == pt_u8string, std::string,
util::if_else_type_c<PT == pt_u16string, std::u16string,
util::if_else_type_c<PT == pt_u32string, std::u32string,
util::if_else_c<PT == pt_u8string, std::string,
util::if_else_c<PT == pt_u16string, std::u16string,
util::if_else_c<PT == pt_u32string, std::u32string,
// default case
util::wrapped_type<void> > > > > > > > > > > > > > >
{
......
#ifndef TDATA_HPP
#define TDATA_HPP
#include "cppa/get.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/detail/abstract_tuple.hpp"
namespace cppa { namespace detail {
template<typename... ElementTypes>
/*
* just like std::tuple (but derives from ref_counted?)
*/
template<typename...>
struct tdata;
template<>
......@@ -64,7 +69,7 @@ struct tdata<Head, Tail...> : tdata<Tail...>
};
template<size_t N, typename... ElementTypes>
template<size_t N, typename... Tn>
struct tdata_upcast_helper;
template<size_t N, typename Head, typename... Tail>
......@@ -79,22 +84,23 @@ struct tdata_upcast_helper<0, Head, Tail...>
typedef tdata<Head, Tail...> type;
};
template<size_t N, typename... ElementTypes>
const typename util::type_at<N, util::type_list<ElementTypes...>>::type&
tdata_get(const tdata<ElementTypes...>& tv)
} // namespace detail
template<size_t N, typename... Tn>
const typename util::at<N, Tn...>::type& get(const detail::tdata<Tn...>& tv)
{
static_assert(N < sizeof...(ElementTypes), "N >= tv.size()");
return static_cast<const typename tdata_upcast_helper<N, ElementTypes...>::type&>(tv).head;
static_assert(N < sizeof...(Tn), "N >= tv.size()");
return static_cast<const typename detail::tdata_upcast_helper<N, Tn...>::type&>(tv).head;
}
template<size_t N, typename... ElementTypes>
typename util::type_at<N, util::type_list<ElementTypes...>>::type&
tdata_get_ref(tdata<ElementTypes...>& tv)
template<size_t N, typename... Tn>
typename util::at<N, Tn...>::type& get_ref(detail::tdata<Tn...>& tv)
{
static_assert(N < sizeof...(ElementTypes), "N >= tv.size()");
return static_cast<typename tdata_upcast_helper<N, ElementTypes...>::type &>(tv).head;
static_assert(N < sizeof...(Tn), "N >= tv.size()");
return static_cast<typename detail::tdata_upcast_helper<N, Tn...>::type &>(tv).head;
}
} } // namespace cppa::detail
} // namespace cppa::detail
#endif // TDATA_HPP
......@@ -69,7 +69,7 @@ class tuple_vals : public abstract_tuple
return tdata_at(m_data, pos);
}
virtual const uniform_type_info& type_at(size_t pos) const
virtual const uniform_type_info& utype_info_at(size_t pos) const
{
return m_types.at(pos);
}
......
......@@ -3,38 +3,43 @@
#include <cstddef>
#include "cppa/util/type_at.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/type_list.hpp"
namespace cppa {
// forward declaration of detail::tdata
namespace detail { template<typename...> class tdata; }
// forward declaration of tuple
template<typename... ElementTypes>
class tuple;
template<typename...> class tuple;
// forward declaration of tuple_view
template<typename... ElementTypes>
class tuple_view;
// forward declarations of get(const tuple<...>&...)
template<size_t N, typename... Types>
const typename util::type_at<N, util::type_list<Types...>>::type&
get(const tuple<Types...>& t);
// forward declarations of get(const tuple_view<...>&...)
template<size_t N, typename... Types>
const typename util::type_at<N, util::type_list<Types...>>::type&
get(const tuple_view<Types...>& t);
// forward declarations of get_ref(tuple<...>&...)
template<size_t N, typename... Types>
typename util::type_at<N, util::type_list<Types...>>::type&
get_ref(tuple<Types...>& t);
// forward declarations of get_ref(tuple_view<...>&...)
template<size_t N, typename... Types>
typename util::type_at<N, util::type_list<Types...>>::type&
get_ref(tuple_view<Types...>& t);
template<typename...> class tuple_view;
// forward declaration of get(const detail::tdata<...>&)
template<size_t N, typename... Tn>
const typename util::at<N, Tn...>::type& get(const detail::tdata<Tn...>&);
// forward declarations of get(const tuple<...>&)
template<size_t N, typename... Tn>
const typename util::at<N, Tn...>::type& get(const tuple<Tn...>&);
// forward declarations of get(const tuple_view<...>&)
template<size_t N, typename... Tn>
const typename util::at<N, Tn...>::type& get(const tuple_view<Tn...>&);
// forward declarations of get_ref(detail::tdata<...>&)
template<size_t N, typename... Tn>
typename util::at<N, Tn...>::type& get_ref(detail::tdata<Tn...>&);
// forward declarations of get_ref(tuple<...>&)
template<size_t N, typename... Tn>
typename util::at<N, Tn...>::type& get_ref(tuple<Tn...>&);
// forward declarations of get_ref(tuple_view<...>&)
template<size_t N, typename... Tn>
typename util::at<N, Tn...>::type& get_ref(tuple_view<Tn...>&);
} // namespace cppa
......
......@@ -3,36 +3,37 @@
#include <type_traits>
#include "cppa/get.hpp"
#include "cppa/tuple.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/tuple_view.hpp"
#include "cppa/util/type_at.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/pop_back.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/element_at.hpp"
#include "cppa/util/callable_trait.hpp"
#include "cppa/util/reverse_type_list.hpp"
#include "cppa/util/type_list_pop_back.hpp"
namespace cppa { namespace detail {
template<size_t N, typename F, typename Tuple,
template<size_t N, typename F, class Tuple,
typename ArgTypeList, typename... Args>
struct invoke_helper
{
typedef typename util::reverse_type_list<ArgTypeList>::type::head_type back_type;
typedef typename util::type_at<N, Tuple>::type tuple_val_type;
typedef typename util::type_list_pop_back<ArgTypeList>::type next_list;
typedef typename util::element_at<N, Tuple>::type tuple_val_type;
typedef typename util::pop_back<ArgTypeList>::type next_list;
inline static void _(F& f, const Tuple& t, const Args&... args)
{
static_assert(std::is_convertible<tuple_val_type, back_type>::value,
"tuple element is not convertible to expected argument");
invoke_helper<N - 1, F, Tuple, next_list, tuple_val_type, Args...>
//::_(f, t, t.get<N>(), args...);
::_(f, t, get<N>(t), args...);
}
};
template<size_t N, typename F, typename Tuple, typename... Args>
template<size_t N, typename F, class Tuple, typename... Args>
struct invoke_helper<N, F, Tuple, util::type_list<>, Args...>
{
inline static void _(F& f, const Tuple&, const Args&... args)
......@@ -83,7 +84,7 @@ struct invoke_impl<false, F, Tuple<TTypes...> >
namespace cppa {
template<typename Tuple, typename F>
template<typename F, class Tuple>
void invoke(F what, const Tuple& args)
{
typedef typename std::remove_pointer<F>::type f_type;
......
......@@ -42,7 +42,7 @@ struct invoke_rule_builder
static constexpr size_t num_args = sizeof...(Args) + 1;
static_assert(num_args <= filtered_types::type_list_size,
static_assert(num_args <= filtered_types::size,
"too much arguments");
class helper_impl : public irb_helper
......
......@@ -11,6 +11,7 @@
#include "cppa/util/pt_token.hpp"
#include "cppa/util/enable_if.hpp"
#include "cppa/util/disable_if.hpp"
#include "cppa/util/pt_dispatch.hpp"
#include "cppa/util/is_primitive.hpp"
#include "cppa/detail/type_to_ptype.hpp"
......
......@@ -10,7 +10,7 @@
#include "cppa/cow_ptr.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/util/type_at.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/replace_type.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/compare_tuples.hpp"
......@@ -117,27 +117,31 @@ class tuple
tuple(const ElementTypes&... args) : m_vals(new vals_t(args...)) { }
/*
template<size_t N>
const typename util::type_at<N, element_types>::type& get() const
const typename util::at<N, ElementTypes...>::type& get() const
{
return detail::tdata_get<N>(m_vals->data());
return get<N>(m_vals->data());
}
template<size_t N>
typename util::type_at<N, element_types>::type& get_ref()
typename util::at<N, ElementTypes...>::type& get_ref()
{
return detail::tdata_get_ref<N>(m_vals->data_ref());
return get_ref<N>(m_vals->data_ref());
}
*/
size_t size() const { return m_vals->size(); }
const void* at(size_t p) const { return m_vals->at(p); }
const uniform_type_info* utype_at(size_t p) const { return m_vals->type_at(p); }
const uniform_type_info* utype_at(size_t p) const { return m_vals->utype_info_at(p); }
const util::abstract_type_list& types() const { return m_vals->types(); }
cow_ptr<vals_t> vals() const { return m_vals; }
const cow_ptr<vals_t>& vals() const { return m_vals; }
cow_ptr<vals_t>& vals_ref() { return m_vals; }
template<typename... Args>
bool equal_to(const tuple<Args...>& other) const
......@@ -150,17 +154,20 @@ class tuple
};
template<size_t N, typename... Types>
const typename util::type_at<N, util::type_list<Types...>>::type&
const typename util::at<N, Types...>::type&
get(const tuple<Types...>& t)
{
return t.get<N>();
return get<N>(t.vals()->data());
//return get<N>(m_vals->data());
//return t.get<N>();
}
template<size_t N, typename... Types>
typename util::type_at<N, util::type_list<Types...>>::type&
typename util::at<N, Types...>::type&
get_ref(tuple<Types...>& t)
{
return t.get_ref<N>();
return get_ref<N>(t.vals_ref()->data_ref());
//return t.get_ref<N>();
}
template<typename TypeList>
......
......@@ -5,6 +5,7 @@
#include "cppa/tuple.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/a_matches_b.hpp"
#include "cppa/util/compare_tuples.hpp"
......@@ -47,6 +48,8 @@ class tuple_view
const vals_t& vals() const { return m_vals; }
vals_t& vals_ref() { return m_vals; }
typedef typename element_types::head_type head_type;
typedef typename element_types::tail_type tail_type;
......@@ -54,17 +57,19 @@ class tuple_view
const element_types& types() const { return m_types; }
template<size_t N>
const typename util::type_at<N, element_types>::type& get() const
const typename util::at<N, ElementTypes...>::type& get() const
{
static_assert(N < sizeof...(ElementTypes), "N >= size()");
return *reinterpret_cast<const typename util::type_at<N, element_types>::type*>(m_vals->at(N));
typedef typename util::at<N, ElementTypes...>::type result_t;
return *reinterpret_cast<const result_t*>(m_vals->at(N));
}
template<size_t N>
typename util::type_at<N, element_types>::type& get_ref()
typename util::at<N, ElementTypes...>::type& get_ref()
{
static_assert(N < sizeof...(ElementTypes), "N >= size()");
return *reinterpret_cast<typename util::type_at<N, element_types>::type*>(m_vals->mutable_at(N));
typedef typename util::at<N, ElementTypes...>::type result_t;
return *reinterpret_cast<result_t*>(m_vals->mutable_at(N));
}
size_t size() const { return m_vals->size(); }
......@@ -77,22 +82,22 @@ class tuple_view
};
template<size_t N, typename... Types>
const typename util::type_at<N, util::type_list<Types...>>::type&
const typename util::at<N, Types...>::type&
get(const tuple_view<Types...>& t)
{
static_assert(N < sizeof...(Types), "N >= t.size()");
typedef typename util::type_at<N, util::type_list<Types...>>::type result_t;
typedef typename util::at<N, Types...>::type result_t;
return *reinterpret_cast<const result_t*>(t.vals()->at(N));
//return t.get<N>();
}
template<size_t N, typename... Types>
typename util::type_at<N, util::type_list<Types...>>::type&
typename util::at<N, Types...>::type&
get_ref(tuple_view<Types...>& t)
{
static_assert(N < sizeof...(Types), "N >= t.size()");
typedef typename util::type_at<N, util::type_list<Types...>>::type result_t;
return *reinterpret_cast<result_t*>(t.vals()->mutable_at(N));
typedef typename util::at<N, Types...>::type result_t;
return *reinterpret_cast<result_t*>(t.vals_ref()->mutable_at(N));
//return t.get_ref<N>();
}
......
......@@ -26,10 +26,8 @@
#include "cppa/util/reverse_type_list.hpp"
#include "cppa/util/single_reader_queue.hpp"
#include "cppa/util/singly_linked_list.hpp"
#include "cppa/util/type_at.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list_apply.hpp"
#include "cppa/util/type_list_pop_back.hpp"
#include "cppa/util/void_type.hpp"
#endif // UTIL_HPP
......@@ -19,7 +19,7 @@ struct abstract_type_list
virtual ~abstract_iterator();
/**
* @brief
* @brief Increases the iterator position.
* @return @c false if the iterator is at the end; otherwise @c true.
*/
virtual bool next() = 0;
......
#ifndef AT_HPP
#define AT_HPP
namespace cppa { namespace util {
template<size_t N, typename... Tn>
struct at;
template<size_t N, typename T0, typename... Tn>
struct at<N, T0, Tn...>
{
typedef typename at<N-1, Tn...>::type type;
};
template<typename T0, typename... Tn>
struct at<0, T0, Tn...>
{
typedef T0 type;
};
} } // namespace cppa::util
#endif // AT_HPP
......@@ -2,6 +2,7 @@
#define COMPARE_TUPLES_HPP
#include "cppa/get.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/is_comparable.hpp"
......@@ -10,7 +11,7 @@
namespace cppa { namespace detail {
template<size_t N, template<typename...> class Tuple, typename... Types>
const typename util::type_at<N, util::type_list<Types...>>::type&
const typename util::at<N, Types...>::type&
do_get(const Tuple<Types...>& t)
{
return ::cppa::get<N, Types...>(t);
......@@ -35,24 +36,6 @@ struct cmp_helper<0, LhsTuple, RhsTuple>
}
};
template<bool ALessB, size_t A, size_t B>
struct min_impl
{
static const size_t value = A;
};
template<size_t A, size_t B>
struct min_impl<false, A, B>
{
static const size_t value = B;
};
template<size_t A, size_t B>
struct min_
{
static const size_t value = min_impl<(A < B), A, B>::value;
};
} } // namespace cppa::detail
namespace cppa { namespace util {
......@@ -81,17 +64,19 @@ bool compare_first_elements(const LhsTuple<LhsTypes...>& lhs,
typedef util::type_list<LhsTypes...> lhs_types;
typedef util::type_list<RhsTypes...> rhs_types;
static_assert(util::eval_first_n<detail::min_<sizeof...(LhsTypes),
sizeof...(RhsTypes)>
::value,
static constexpr size_t lhs_size = sizeof...(LhsTypes);
static constexpr size_t rhs_size = sizeof...(RhsTypes);
static constexpr size_t cmp_size = (lhs_size < rhs_size)
? lhs_size
: rhs_size;
static_assert(util::eval_first_n<cmp_size,
lhs_types,
rhs_types,
util::is_comparable>::value,
"types of lhs are not comparable to the types of rhs");
return detail::cmp_helper<(detail::min_<lhs_types::type_list_size,
rhs_types::type_list_size>
::value - 1),
return detail::cmp_helper<(cmp_size - 1),
LhsTuple<LhsTypes...>,
RhsTuple<RhsTypes...>>::cmp(lhs, rhs);
}
......
......@@ -19,6 +19,4 @@ struct disable_if : disable_if_c<Trait::value, T>
} } // namespace cppa::util
#endif // DISABLE_IF_HPP
#ifndef ELEMENT_AT_HPP
#define ELEMENT_AT_HPP
#include "cppa/util/at.hpp"
namespace cppa { namespace util {
template<size_t N, class C>
struct element_at;
template<size_t N, template<typename...> class C, typename... Tn>
struct element_at<N, C<Tn...>> : at<N, Tn...>
{
};
} } // namespace cppa::util
#endif // ELEMENT_AT_HPP
......@@ -4,33 +4,23 @@
#include <cstddef>
#include <type_traits>
#include "cppa/util/type_at.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/if_else.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/element_at.hpp"
#include "cppa/util/concat_type_lists.hpp"
namespace cppa { namespace detail {
template<bool Stmt, typename IfType, typename ElseType>
struct if_t
{
typedef ElseType type;
};
template<typename IfType, typename ElseType>
struct if_t<true, IfType, ElseType>
{
typedef IfType type;
};
template<size_t N, typename List>
struct n_
{
typedef typename util::type_at<N - 1, List>::type head_type;
typedef typename util::element_at<N - 1, List>::type head_type;
typedef typename if_t<std::is_same<util::void_type, head_type>::value,
typedef typename util::if_else<std::is_same<util::void_type, head_type>,
util::type_list<>,
util::type_list<head_type>>::type
util::wrapped_type<util::type_list<head_type>>>::type
head_list;
typedef typename n_<N - 1, List>::type tail_list;
......
#ifndef IF_ELSE_TYPE_HPP
#define IF_ELSE_TYPE_HPP
#ifndef IF_ELSE_HPP
#define IF_ELSE_HPP
#include "cppa/util/wrapped_type.hpp"
namespace cppa { namespace util {
// if (IfStmt == true) type = T; else type = Else::type;
/**
* @brief A conditinal expression for types that allows
* nested statements (unlike std::conditional).
*
* @c type is defined as @p T if <tt>IfStmt == true</tt>;
* otherwise @c type is defined as @p Else::type.
*/
template<bool IfStmt, typename T, class Else>
struct if_else_type_c
struct if_else_c
{
typedef T type;
};
template<typename T, class Else>
struct if_else_type_c<false, T, Else>
struct if_else_c<false, T, Else>
{
typedef typename Else::type type;
};
// if (Stmt::value == true) type = T; else type = Else::type;
template<class Stmt, typename T, class Else>
struct if_else_type : if_else_type_c<Stmt::value, T, Else> { };
struct if_else : if_else_c<Stmt::value, T, Else> { };
} } // namespace cppa::util
#endif // IF_ELSE_TYPE_HPP
#endif // IF_ELSE_HPP
#ifndef CPPA_UTIL_TYPE_LIST_POP_BACK_HPP
#define CPPA_UTIL_TYPE_LIST_POP_BACK_HPP
#ifndef POP_BACK_HPP
#define POP_BACK_HPP
#include "cppa/util/type_list.hpp"
#include "cppa/util/reverse_type_list.hpp"
namespace cppa { namespace util {
template<typename List>
struct type_list_pop_back
template<class C>
struct pop_back;
template<typename... Tn>
struct pop_back< type_list<Tn...> >
{
typedef typename reverse_type_list<List>::type rlist;
typedef typename reverse_type_list<type_list<Tn...>>::type rlist;
typedef typename reverse_type_list<typename rlist::tail_type>::type type;
};
} } // namespace cppa::util
#endif // CPPA_UTIL_TYPE_LIST_POP_BACK_HPP
#endif // POP_BACK_HPP
#ifndef PT_DISPATCH_HPP
#define PT_DISPATCH_HPP
namespace cppa { namespace util {
/**
* @brief Creates a {@link pt_token} from the runtime value @p ptype
* and invokes @p f with this token.
* @note Does nothing if ptype == pt_null.
*/
template<typename Fun>
void pt_dispatch(primitive_type ptype, Fun&& f)
{
switch (ptype)
{
case pt_int8: f(pt_token<pt_int8>()); break;
case pt_int16: f(pt_token<pt_int16>()); break;
case pt_int32: f(pt_token<pt_int32>()); break;
case pt_int64: f(pt_token<pt_int64>()); break;
case pt_uint8: f(pt_token<pt_uint8>()); break;
case pt_uint16: f(pt_token<pt_uint16>()); break;
case pt_uint32: f(pt_token<pt_uint32>()); break;
case pt_uint64: f(pt_token<pt_uint64>()); break;
case pt_float: f(pt_token<pt_float>()); break;
case pt_double: f(pt_token<pt_double>()); break;
case pt_long_double: f(pt_token<pt_long_double>()); break;
case pt_u8string: f(pt_token<pt_u8string>()); break;
case pt_u16string: f(pt_token<pt_u16string>()); break;
case pt_u32string: f(pt_token<pt_u32string>()); break;
default: break;
}
}
} } // namespace cppa::util
#endif // PT_DISPATCH_HPP
......@@ -11,34 +11,6 @@ namespace cppa { namespace util {
template<primitive_type PT>
struct pt_token { static const primitive_type value = PT; };
/**
* @brief Creates a {@link pt_token} from the runtime value @p ptype
* and invokes @p f with this token.
* @note Does nothing if ptype == pt_null.
*/
template<typename Fun>
void pt_dispatch(primitive_type ptype, Fun&& f)
{
switch (ptype)
{
case pt_int8: f(pt_token<pt_int8>()); break;
case pt_int16: f(pt_token<pt_int16>()); break;
case pt_int32: f(pt_token<pt_int32>()); break;
case pt_int64: f(pt_token<pt_int64>()); break;
case pt_uint8: f(pt_token<pt_uint8>()); break;
case pt_uint16: f(pt_token<pt_uint16>()); break;
case pt_uint32: f(pt_token<pt_uint32>()); break;
case pt_uint64: f(pt_token<pt_uint64>()); break;
case pt_float: f(pt_token<pt_float>()); break;
case pt_double: f(pt_token<pt_double>()); break;
case pt_long_double: f(pt_token<pt_long_double>()); break;
case pt_u8string: f(pt_token<pt_u8string>()); break;
case pt_u16string: f(pt_token<pt_u16string>()); break;
case pt_u32string: f(pt_token<pt_u32string>()); break;
default: break;
}
}
} } // namespace cppa::util
#endif // PT_TOKEN_HPP
......@@ -4,8 +4,8 @@
namespace cppa { namespace util {
/**
* @brief Like std::remove_reference but prohibits void and removes const
* references.
* @brief Like std::remove_reference but prohibits void and
* also removes const references.
*/
template<typename T>
struct rm_ref { typedef T type; };
......@@ -16,9 +16,6 @@ struct rm_ref<const T&> { typedef T type; };
template<typename T>
struct rm_ref<T&> { typedef T type; };
template<typename T>
struct rm_ref<T&&> { typedef T type; };
template<>
struct rm_ref<void> { };
......
#ifndef CPPA_UTIL_TYPE_AT_HPP
#define CPPA_UTIL_TYPE_AT_HPP
// size_t
#include <cstddef>
#include "cppa/util/type_list.hpp"
namespace cppa { namespace util {
/*
template<size_t N, typename TypeList>
struct type_at
{
typedef typename type_at<N-1, typename TypeList::tail_type>::type type;
};
template<typename TypeList>
struct type_at<0, TypeList>
{
typedef typename TypeList::head_type type;
};
*/
template<size_t N, class TypeList>
struct type_at;
template<size_t N, template<typename...> class TypeList, typename T0, typename... Tn>
struct type_at< N, TypeList<T0,Tn...> >
{
// use type_list to avoid instantiations of TypeList parameter
typedef typename type_at< N-1, type_list<Tn...> >::type type;
};
template<template<typename...> class TypeList, typename T0, typename... Tn>
struct type_at< 0, TypeList<T0,Tn...> >
{
typedef T0 type;
};
template<size_t N, template<typename...> class TypeList>
struct type_at< N, TypeList<> >
{
typedef void_type type;
};
} } // namespace cppa::util
#endif // CPPA_UTIL_TYPE_AT_HPP
......@@ -59,7 +59,7 @@ struct type_list<>
{
typedef void_type head_type;
typedef type_list<> tail_type;
static const size_t type_list_size = 0;
static const size_t size = 0;
};
template<typename Head, typename... Tail>
......@@ -70,7 +70,7 @@ struct type_list<Head, Tail...> : abstract_type_list
typedef type_list<Tail...> tail_type;
static const size_t type_list_size = sizeof...(Tail) + 1;
static const size_t size = sizeof...(Tail) + 1;
type_list()
{
......@@ -79,7 +79,7 @@ struct type_list<Head, Tail...> : abstract_type_list
virtual const_iterator begin() const
{
return new type_list_iterator(m_arr, m_arr + type_list_size);
return new type_list_iterator(m_arr, m_arr + size);
}
virtual const uniform_type_info& at(size_t pos) const
......@@ -96,7 +96,7 @@ struct type_list<Head, Tail...> : abstract_type_list
static void init(const uniform_type_info** what)
{
what[0] = uniform_typeid(typeid(typename TypeList::head_type));
if (TypeList::type_list_size > 1)
if (TypeList::size > 1)
{
++what;
init<typename TypeList::tail_type>(what);
......@@ -105,7 +105,7 @@ struct type_list<Head, Tail...> : abstract_type_list
private:
const uniform_type_info* m_arr[type_list_size];
const uniform_type_info* m_arr[size];
};
......
......@@ -47,7 +47,7 @@ struct empty_tuple : cppa::detail::abstract_tuple
throw std::range_error("empty_tuple::at()");
}
virtual const cppa::uniform_type_info& type_at(size_t) const
virtual const cppa::uniform_type_info& utype_info_at(size_t) const
{
throw std::range_error("empty_tuple::type_at()");
}
......@@ -109,9 +109,9 @@ const void* any_tuple::at(size_t p) const
return m_vals->at(p);
}
const uniform_type_info& any_tuple::type_at(size_t p) const
const uniform_type_info& any_tuple::type_info_at(size_t p) const
{
return m_vals->type_at(p);
return m_vals->utype_info_at(p);
}
const util::abstract_type_list& any_tuple::types() const
......
......@@ -57,8 +57,8 @@ bool object_array::equal_to(const cppa::detail::abstract_tuple& ut) const
{
for (size_t i = 0; i < size(); ++i)
{
const uniform_type_info& utype = type_at(i);
if (utype == ut.type_at(i))
const uniform_type_info& utype = utype_info_at(i);
if (utype == ut.utype_info_at(i))
{
if (!utype.equal(at(i), ut.at(i))) return false;
}
......@@ -72,7 +72,7 @@ bool object_array::equal_to(const cppa::detail::abstract_tuple& ut) const
return false;
}
const uniform_type_info& object_array::type_at(size_t pos) const
const uniform_type_info& object_array::utype_info_at(size_t pos) const
{
return m_elements[pos].type();
}
......
......@@ -360,7 +360,7 @@ class any_tuple_tinfo : public util::abstract_uniform_type_info<any_tuple>
sink->begin_sequence(atup.size());
for (size_t i = 0; i < atup.size(); ++i)
{
atup.type_at(i).serialize(atup.at(i), sink);
atup.type_info_at(i).serialize(atup.at(i), sink);
}
sink->end_sequence();
sink->end_object();
......
......@@ -45,7 +45,6 @@
#include "cppa/util/enable_if.hpp"
#include "cppa/util/disable_if.hpp"
#include "cppa/util/is_iterable.hpp"
#include "cppa/util/if_else_type.hpp"
#include "cppa/util/wrapped_type.hpp"
#include "cppa/util/is_primitive.hpp"
#include "cppa/util/abstract_uniform_type_info.hpp"
......
......@@ -68,11 +68,11 @@ size_t test__tuple()
// any_tuple ut1 = tv0;
CPPA_CHECK(t6.get<0>() == 0);
CPPA_CHECK(tv2.get<0>() == t1.get<0>());
CPPA_CHECK(tv2.get<1>() == t1.get<3>());
CPPA_CHECK(get<0>(t6) == 0);
CPPA_CHECK(get<0>(tv2) == get<0>(t1));
CPPA_CHECK(get<1>(tv2) == get<3>(t1));
CPPA_CHECK(tv2.get<1>() == "Hello World");
CPPA_CHECK(get<1>(tv2) == "Hello World");
{
tuple<int> t1_sub1(42);
......@@ -94,8 +94,8 @@ size_t test__tuple()
CPPA_CHECK(tv3_mappings[1] == 3);
}
CPPA_CHECK(tv3.get<0>() == t1.get<2>());
CPPA_CHECK(tv3.get<1>() == t1.get<3>());
CPPA_CHECK(get<0>(tv3) == get<2>(t1));
CPPA_CHECK(get<1>(tv3) == get<3>(t1));
CPPA_CHECK(!(tv2 == tv3));
......@@ -111,21 +111,21 @@ size_t test__tuple()
// CPPA_CHECK(ut0 == t1);
CPPA_CHECK(tv0.get<0>() == .2f);
CPPA_CHECK(tv0.get<1>() == 2);
CPPA_CHECK(get<0>(tv0) == .2f);
CPPA_CHECK(get<1>(tv0) == 2);
CPPA_CHECK(tv1.get<0>() == 2);
CPPA_CHECK(get<0>(tv1) == 2);
CPPA_CHECK((tv1.get<0>() == tv0.get<1>()));
CPPA_CHECK((&(tv1.get<0>()) == &(tv0.get<1>())));
CPPA_CHECK((get<0>(tv1) == get<1>(tv0)));
CPPA_CHECK((&(get<0>(tv1)) == &(get<1>(tv0))));
// force detaching of tv1 from tv0 (and t1)
tv1.get_ref<0>() = 20;
get_ref<0>(tv1) = 20;
CPPA_CHECK(tv0.get<1>() == 2);
CPPA_CHECK(tv1.get<0>() == 20);
CPPA_CHECK((&(tv1.get<0>()) != &(tv0.get<1>())));
CPPA_CHECK((&(t1.get<1>()) == &(tv0.get<0>())));
CPPA_CHECK(get<1>(tv0) == 2);
CPPA_CHECK(get<0>(tv1) == 20);
CPPA_CHECK((&(get<0>(tv1)) != &(get<1>(tv0))));
CPPA_CHECK((&(get<1>(t1)) == &(get<0>(tv0))));
bool l1_invoked = false;
bool l2_invoked = false;
......@@ -137,21 +137,21 @@ size_t test__tuple()
auto l1 = [&](int v0, float v1, int v2, const std::string& v3) {
l1_invoked = true;
CPPA_CHECK((t1.get<0>() == v0));
CPPA_CHECK((t1.get<1>() == v1));
CPPA_CHECK((t1.get<2>() == v2));
CPPA_CHECK((t1.get<3>() == v3));
CPPA_CHECK((get<0>(t1) == v0));
CPPA_CHECK((get<1>(t1) == v1));
CPPA_CHECK((get<2>(t1) == v2));
CPPA_CHECK((get<3>(t1) == v3));
};
auto l2 = [&](float v0, int v1) {
l2_invoked = true;
CPPA_CHECK((tv0.get<0>() == v0));
CPPA_CHECK((tv0.get<1>() == v1));
CPPA_CHECK((get<0>(tv0) == v0));
CPPA_CHECK((get<1>(tv0) == v1));
};
auto l3 = [&](const std::string& v0) {
l3_invoked = true;
CPPA_CHECK((t2.get<0>() == v0));
CPPA_CHECK((get<0>(t2) == v0));
};
invoke(l1, t1);
......@@ -221,13 +221,13 @@ size_t test__tuple()
// test detaching of tuples
auto t1_copy = t1;
CPPA_CHECK((&(t1_copy.get<0>()) == &(t1.get<0>())));
t1_copy.get_ref<0>() = 24; // this detaches t4 from t1
CPPA_CHECK((&(t1_copy.get<0>()) != &(t1.get<0>())));
CPPA_CHECK(t1_copy.get<0>() != t1.get<0>());
CPPA_CHECK(t1_copy.get<1>() == t1.get<1>());
CPPA_CHECK(t1_copy.get<2>() == t1.get<2>());
CPPA_CHECK(t1_copy.get<3>() == t1.get<3>());
CPPA_CHECK((&(get<0>(t1_copy)) == &(get<0>(t1))));
get_ref<0>(t1_copy) = 24; // this detaches t4 from t1
CPPA_CHECK((&(get<0>(t1_copy)) != &(get<0>(t1))));
CPPA_CHECK(get<0>(t1_copy) != get<0>(t1));
CPPA_CHECK(get<1>(t1_copy) == get<1>(t1));
CPPA_CHECK(get<2>(t1_copy) == get<2>(t1));
CPPA_CHECK(get<3>(t1_copy) == get<3>(t1));
CPPA_CHECK(t1 == t4);
return CPPA_TEST_RESULT;
......
......@@ -6,6 +6,8 @@
#include "test.hpp"
#include "cppa/util.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/element_at.hpp"
#include "cppa/uniform_type_info.hpp"
using std::cout;
......@@ -26,15 +28,15 @@ size_t test__type_list()
typedef type_list<int, float, std::string> l1;
typedef reverse_type_list<l1>::type r1;
CPPA_CHECK((is_same<int, type_at<0, l1>::type>::value));
CPPA_CHECK((is_same<float, type_at<1, l1>::type>::value));
CPPA_CHECK((is_same<std::string, type_at<2, l1>::type>::value));
CPPA_CHECK((is_same<int, element_at<0, l1>::type>::value));
CPPA_CHECK((is_same<float, element_at<1, l1>::type>::value));
CPPA_CHECK((is_same<std::string, element_at<2, l1>::type>::value));
CPPA_CHECK_EQUAL(l1::type_list_size, 3);
CPPA_CHECK_EQUAL(l1::type_list_size, r1::type_list_size);
CPPA_CHECK((is_same<type_at<0, l1>::type, type_at<2, r1>::type>::value));
CPPA_CHECK((is_same<type_at<1, l1>::type, type_at<1, r1>::type>::value));
CPPA_CHECK((is_same<type_at<2, l1>::type, type_at<0, r1>::type>::value));
CPPA_CHECK_EQUAL(l1::size, 3);
CPPA_CHECK_EQUAL(l1::size, r1::size);
CPPA_CHECK((is_same<element_at<0, l1>::type, element_at<2, r1>::type>::value));
CPPA_CHECK((is_same<element_at<1, l1>::type, element_at<1, r1>::type>::value));
CPPA_CHECK((is_same<element_at<2, l1>::type, element_at<0, r1>::type>::value));
typedef concat_type_lists<type_list<int>, l1>::type l2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment