Commit db48145f authored by Dominik Charousset's avatar Dominik Charousset

maintenance

parent 6cbdec38
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "cppa/cow_tuple.hpp" #include "cppa/cow_tuple.hpp"
#include "cppa/util/rm_ref.hpp" #include "cppa/util/rm_ref.hpp"
#include "cppa/util/comparable.hpp"
#include "cppa/util/is_iterable.hpp" #include "cppa/util/is_iterable.hpp"
#include "cppa/detail/tuple_view.hpp" #include "cppa/detail/tuple_view.hpp"
...@@ -55,6 +56,7 @@ class any_tuple { ...@@ -55,6 +56,7 @@ class any_tuple {
public: public:
typedef cow_ptr<detail::abstract_tuple> value_ptr;
typedef detail::abstract_tuple::const_iterator const_iterator; typedef detail::abstract_tuple::const_iterator const_iterator;
/** /**
...@@ -74,8 +76,6 @@ class any_tuple { ...@@ -74,8 +76,6 @@ class any_tuple {
template<typename... Args> template<typename... Args>
any_tuple(cow_tuple<Args...>&& t) : m_vals(std::move(t.m_vals)) { } any_tuple(cow_tuple<Args...>&& t) : m_vals(std::move(t.m_vals)) { }
explicit any_tuple(detail::abstract_tuple*);
/** /**
* @brief Move constructor. * @brief Move constructor.
*/ */
...@@ -143,9 +143,9 @@ class any_tuple { ...@@ -143,9 +143,9 @@ class any_tuple {
inline const_iterator end() const { return m_vals->end(); } inline const_iterator end() const { return m_vals->end(); }
inline cow_ptr<detail::abstract_tuple>& vals() { return m_vals; } inline value_ptr& vals() { return m_vals; }
inline const cow_ptr<detail::abstract_tuple>& vals() const { return m_vals; } inline const value_ptr& vals() const { return m_vals; }
inline const cow_ptr<detail::abstract_tuple>& cvals() const { return m_vals; } inline const value_ptr& cvals() const { return m_vals; }
inline const std::type_info* type_token() const { inline const std::type_info* type_token() const {
return m_vals->type_token(); return m_vals->type_token();
...@@ -162,7 +162,7 @@ class any_tuple { ...@@ -162,7 +162,7 @@ class any_tuple {
typename util::rm_ref<T>::type typename util::rm_ref<T>::type
>::value >::value
>::type* = 0) { >::type* = 0) {
static constexpr bool can_optimize = std::is_reference<T>::value static constexpr bool can_optimize = std::is_reference<T>::value
&& !std::is_const<T>::value; && !std::is_const<T>::value;
std::integral_constant<bool, can_optimize> token; std::integral_constant<bool, can_optimize> token;
return any_tuple{container_view(std::forward<T>(value), token)}; return any_tuple{container_view(std::forward<T>(value), token)};
...@@ -179,66 +179,63 @@ class any_tuple { ...@@ -179,66 +179,63 @@ class any_tuple {
typedef typename detail::implicit_conversions<vtype>::type converted; typedef typename detail::implicit_conversions<vtype>::type converted;
static_assert(util::is_legal_tuple_type<converted>::value, static_assert(util::is_legal_tuple_type<converted>::value,
"T is not a valid tuple type"); "T is not a valid tuple type");
typedef typename std::remove_reference<T>::type plain_type;
static constexpr bool can_optimize = static constexpr bool can_optimize =
std::is_same<converted, vtype>::value std::is_same<converted, vtype>::value
&& std::is_reference<T>::value && std::is_reference<T>::value
&& !std::is_const<typename std::remove_reference<T>::type>::value; && !std::is_const<plain_type>::value;
std::integral_constant<bool, can_optimize> token; std::integral_constant<bool, can_optimize> token;
return any_tuple{simple_view(std::forward<T>(value), token)}; return any_tuple{simple_view(std::forward<T>(value), token)};
} }
void force_detach() { inline void force_detach() { m_vals.detach(); }
m_vals.detach();
}
void reset(); void reset();
explicit any_tuple(detail::abstract_tuple*);
private: private:
cow_ptr<detail::abstract_tuple> m_vals; value_ptr m_vals;
explicit any_tuple(const cow_ptr<detail::abstract_tuple>& vals); explicit any_tuple(const value_ptr& vals);
typedef detail::abstract_tuple* tup_ptr; typedef detail::abstract_tuple* abstract_ptr;
template<typename T> template<typename T>
static inline tup_ptr simple_view(T& value, static inline abstract_ptr simple_view(T& value, std::true_type) {
std::integral_constant<bool, true>) {
return new detail::tuple_view<T>(&value); return new detail::tuple_view<T>(&value);
} }
template<typename First, typename Second> template<typename First, typename Second>
static inline tup_ptr simple_view(std::pair<First, Second>& p, static inline abstract_ptr simple_view(std::pair<First, Second>& p,
std::integral_constant<bool, true>) { std::true_type) {
return new detail::tuple_view<First, Second>(&p.first, &p.second); return new detail::tuple_view<First, Second>(&p.first, &p.second);
} }
template<typename T> template<typename T>
static inline tup_ptr simple_view(T&& value, static inline abstract_ptr simple_view(T&& value, std::false_type) {
std::integral_constant<bool, false>) {
typedef typename util::rm_ref<T>::type vtype; typedef typename util::rm_ref<T>::type vtype;
typedef typename detail::implicit_conversions<vtype>::type converted; typedef typename detail::implicit_conversions<vtype>::type converted;
return new detail::tuple_vals<converted>(std::forward<T>(value)); return new detail::tuple_vals<converted>(std::forward<T>(value));
} }
template<typename First, typename Second> template<typename First, typename Second>
static inline any_tuple view(std::pair<First, Second> p, static inline any_tuple view(std::pair<First, Second> p, std::false_type) {
std::integral_constant<bool, false>) {
return new detail::tuple_vals<First, Second>(std::move(p.first), return new detail::tuple_vals<First, Second>(std::move(p.first),
std::move(p.second)); std::move(p.second));
} }
template<typename T> template<typename T>
static inline detail::abstract_tuple* container_view(T& value, static inline abstract_ptr container_view(T& value, std::true_type) {
std::integral_constant<bool, true>) {
return new detail::container_tuple_view<T>(&value); return new detail::container_tuple_view<T>(&value);
} }
template<typename T> template<typename T>
static inline detail::abstract_tuple* container_view(T&& value, static inline abstract_ptr container_view(T&& value, std::false_type) {
std::integral_constant<bool, false>) {
typedef typename util::rm_ref<T>::type ctype; typedef typename util::rm_ref<T>::type ctype;
return new detail::container_tuple_view<T>(new ctype(std::forward<T>(value)), true); auto cptr = new ctype(std::forward<T>(value));
return new detail::container_tuple_view<T>(cptr, true);
} }
}; };
......
...@@ -87,10 +87,10 @@ class abstract_tuple : public ref_counted { ...@@ -87,10 +87,10 @@ class abstract_tuple : public ref_counted {
typedef tuple_iterator<abstract_tuple> const_iterator; typedef tuple_iterator<abstract_tuple> const_iterator;
inline const_iterator begin() const { return {this}; } inline const_iterator begin() const { return {this}; }
inline const_iterator cbegin() const { return {this}; } inline const_iterator cbegin() const { return {this}; }
inline const_iterator end() const { return {this, size()}; } inline const_iterator end() const { return {this, size()}; }
inline const_iterator cend() const { return {this, size()}; } inline const_iterator cend() const { return {this, size()}; }
}; };
......
...@@ -39,6 +39,9 @@ namespace cppa { namespace detail { ...@@ -39,6 +39,9 @@ namespace cppa { namespace detail {
std::string to_uniform_name(const std::string& demangled_name); std::string to_uniform_name(const std::string& demangled_name);
std::string to_uniform_name(const std::type_info& tinfo); std::string to_uniform_name(const std::type_info& tinfo);
template<class T>
inline std::string to_uniform_name() { return to_uniform_name(typeid(T)); }
} } // namespace cppa::detail } } // namespace cppa::detail
#endif // CPPA_TO_UNIFORM_NAME_HPP #endif // CPPA_TO_UNIFORM_NAME_HPP
...@@ -84,8 +84,6 @@ class uniform_type_info_map { ...@@ -84,8 +84,6 @@ class uniform_type_info_map {
// maps sizeof(-integer_type-) to { signed-names-set, unsigned-names-set } // maps sizeof(-integer_type-) to { signed-names-set, unsigned-names-set }
int_map m_ints; int_map m_ints;
}; };
} } // namespace cppa::detail } } // namespace cppa::detail
......
...@@ -32,28 +32,23 @@ ...@@ -32,28 +32,23 @@
#include "cppa/detail/empty_tuple.hpp" #include "cppa/detail/empty_tuple.hpp"
#include "cppa/detail/singleton_manager.hpp" #include "cppa/detail/singleton_manager.hpp"
namespace { namespace cppa {
inline cppa::detail::empty_tuple* s_empty_tuple() { namespace {
return cppa::detail::singleton_manager::get_empty_tuple(); inline detail::empty_tuple* s_empty_tuple() {
return detail::singleton_manager::get_empty_tuple();
} }
} // namespace <anonymous> } // namespace <anonymous>
namespace cppa { any_tuple::any_tuple() : m_vals(s_empty_tuple()) { }
any_tuple::any_tuple() : m_vals(s_empty_tuple()) { any_tuple::any_tuple(detail::abstract_tuple* ptr) : m_vals(ptr) { }
}
any_tuple::any_tuple(detail::abstract_tuple* ptr) : m_vals(ptr) {
}
any_tuple::any_tuple(any_tuple&& other) : m_vals(s_empty_tuple()) { any_tuple::any_tuple(any_tuple&& other) : m_vals(s_empty_tuple()) {
m_vals.swap(other.m_vals); m_vals.swap(other.m_vals);
} }
any_tuple::any_tuple(const cow_ptr<detail::abstract_tuple>& vals) : m_vals(vals) { any_tuple::any_tuple(const value_ptr& vals) : m_vals(vals) { }
}
any_tuple& any_tuple::operator=(any_tuple&& other) { any_tuple& any_tuple::operator=(any_tuple&& other) {
m_vals.swap(other.m_vals); m_vals.swap(other.m_vals);
......
...@@ -38,14 +38,14 @@ ...@@ -38,14 +38,14 @@
#include "cppa/local_actor.hpp" #include "cppa/local_actor.hpp"
#include "cppa/thread_mapped_actor.hpp" #include "cppa/thread_mapped_actor.hpp"
namespace cppa {
namespace { namespace {
boost::thread_specific_ptr<cppa::local_actor> t_this_actor(&cppa::self_type::cleanup_fun); boost::thread_specific_ptr<local_actor> t_this_actor(&self_type::cleanup_fun);
} // namespace <anonymous> } // namespace <anonymous>
namespace cppa {
void self_type::cleanup_fun(cppa::local_actor* what) { void self_type::cleanup_fun(cppa::local_actor* what) {
if (what) { if (what) {
auto ptr = dynamic_cast<thread_mapped_actor*>(what); auto ptr = dynamic_cast<thread_mapped_actor*>(what);
......
...@@ -63,19 +63,6 @@ void shared_spinlock::lock() { ...@@ -63,19 +63,6 @@ void shared_spinlock::lock() {
void shared_spinlock::lock_upgrade() { void shared_spinlock::lock_upgrade() {
unlock_shared(); unlock_shared();
lock(); lock();
/*
long v = m_flag.load();
for (;;) {
if (v != 1) {
//std::this_thread::yield();
v = m_flag.load();
}
else if (m_flag.compare_exchange_weak(v, min_long)) {
return;
}
// else: next iteration
}
*/
} }
void shared_spinlock::unlock() { void shared_spinlock::unlock() {
......
...@@ -136,7 +136,8 @@ class string_serializer : public serializer { ...@@ -136,7 +136,8 @@ class string_serializer : public serializer {
throw std::runtime_error("expected uint64 value after @atom"); throw std::runtime_error("expected uint64 value after @atom");
} }
// write atoms as strings instead of integer values // write atoms as strings instead of integer values
auto av = static_cast<atom_value>(get<std::uint64_t>(value)); (pt_writer(out))(to_string(av)); auto av = static_cast<atom_value>(get<std::uint64_t>(value));
(pt_writer(out))(to_string(av));
} }
else { else {
value.apply(pt_writer(out)); value.apply(pt_writer(out));
...@@ -202,13 +203,17 @@ class string_deserializer : public deserializer { ...@@ -202,13 +203,17 @@ class string_deserializer : public deserializer {
inline std::string::iterator next_delimiter() { inline std::string::iterator next_delimiter() {
return std::find_if(m_pos, m_str.end(), [] (char c) -> bool { return std::find_if(m_pos, m_str.end(), [] (char c) -> bool {
switch (c) { switch (c) {
case '(': case '(':
case ')': case ')':
case '{': case '{':
case '}': case '}':
case ' ': case ' ':
case ',': return true; case ',': {
default : return false; return true;
}
default: {
return false;
}
} }
}); });
} }
...@@ -284,8 +289,7 @@ class string_deserializer : public deserializer { ...@@ -284,8 +289,7 @@ class string_deserializer : public deserializer {
size_t begin_sequence() { size_t begin_sequence() {
integrity_check(); integrity_check();
consume('{'); consume('{');
auto list_end = std::find(m_pos, m_str.end(), '}'); return std::count(m_pos, std::find(m_pos, m_str.end(), '}'), ',') + 1;
return std::count(m_pos, list_end, ',') + 1;
} }
void end_sequence() { void end_sequence() {
......
This diff is collapsed.
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