Permalink
Browse files

refactored type name mapping

type names are now mapped using a static lookup table; all built-in types
information instances are now members of uniform_type_info_map to get rid
of as much heap allocations as possible
  • Loading branch information...
1 parent 31699f7 commit 488ca9719074b8c7e9ce67d0f1b9f6d5d3c1d31c @Neverlord Neverlord committed May 5, 2013
View
@@ -102,7 +102,6 @@ set(LIBCPPA_SRC
src/context_switching_actor.cpp
src/continuable_reader.cpp
src/continuable_writer.cpp
- src/decorated_names_map.cpp
src/default_actor_addressing.cpp
src/default_actor_proxy.cpp
src/default_peer.cpp
@@ -154,6 +153,7 @@ set(LIBCPPA_SRC
src/to_uniform_name.cpp
src/unicast_network.cpp
src/uniform_type_info.cpp
+ src/uniform_type_info_map.cpp
src/weak_ptr_anchor.cpp
src/yield_interface.cpp)
View
@@ -25,7 +25,6 @@ cppa/detail/behavior_impl.hpp
cppa/detail/behavior_stack.hpp
cppa/detail/boxed.hpp
cppa/detail/container_tuple_view.hpp
-cppa/detail/decorated_names_map.hpp
cppa/detail/decorated_tuple.hpp
cppa/detail/default_uniform_type_info_impl.hpp
cppa/detail/demangle.hpp
@@ -122,6 +121,7 @@ cppa/option.hpp
cppa/partial_function.hpp
cppa/primitive_type.hpp
cppa/primitive_variant.hpp
+cppa/prioritizing.hpp
cppa/process_information.hpp
cppa/qtsupport/actor_widget_mixin.hpp
cppa/receive.hpp
@@ -131,6 +131,7 @@ cppa/sb_actor.hpp
cppa/scheduled_actor.hpp
cppa/scheduler.hpp
cppa/self.hpp
+cppa/send.hpp
cppa/serializer.hpp
cppa/singletons.hpp
cppa/spawn_options.hpp
@@ -227,7 +228,6 @@ src/channel.cpp
src/context_switching_actor.cpp
src/continuable_reader.cpp
src/continuable_writer.cpp
-src/decorated_names_map.cpp
src/default_actor_addressing.cpp
src/default_actor_proxy.cpp
src/default_peer.cpp
@@ -283,6 +283,7 @@ src/thread_pool_scheduler.cpp
src/to_uniform_name.cpp
src/unicast_network.cpp
src/uniform_type_info.cpp
+src/uniform_type_info_map.cpp
src/weak_ptr_anchor.cpp
src/yield_interface.cpp
unit_testing/ping_pong.cpp
@@ -306,5 +307,3 @@ unit_testing/test_sync_send.cpp
unit_testing/test_tuple.cpp
unit_testing/test_uniform_type.cpp
unit_testing/test_yield_interface.cpp
-cppa/prioritizing.hpp
-cppa/send.hpp
@@ -1,61 +0,0 @@
-/******************************************************************************\
- * ___ __ *
- * /\_ \ __/\ \ *
- * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
- * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
- * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
- * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
- * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
- * \ \_\ \ \_\ *
- * \/_/ \/_/ *
- * *
- * Copyright (C) 2011-2013 *
- * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
- * *
- * This file is part of libcppa. *
- * libcppa is free software: you can redistribute it and/or modify it under *
- * the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation; either version 2.1 of the License, *
- * or (at your option) any later version. *
- * *
- * libcppa is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- * See the GNU Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
-\******************************************************************************/
-
-
-#ifndef CPPA_DECORATED_NAMES_MAP_HPP
-#define CPPA_DECORATED_NAMES_MAP_HPP
-
-#include <map>
-#include <string>
-
-#include "cppa/detail/singleton_mixin.hpp"
-
-namespace cppa { namespace detail {
-
-class decorated_names_map : public singleton_mixin<decorated_names_map> {
-
- friend class singleton_mixin<decorated_names_map>;
-
- public:
-
- // returns either a decorated version of @p demangled_name or
- // @p demangled_name itself
- const std::string& decorate(const std::string& demangled_name) const;
-
- private:
-
- decorated_names_map();
-
- std::map<std::string, std::string> m_map;
-
-};
-
-} } // namespace cppa::detail
-
-#endif // DECORATED_NAMES_MAP_HPP
@@ -50,7 +50,6 @@ class empty_tuple;
class group_manager;
class abstract_tuple;
class actor_registry;
-class decorated_names_map;
class uniform_type_info_map;
class singleton_manager {
@@ -79,8 +78,6 @@ class singleton_manager {
static empty_tuple* get_empty_tuple();
- static decorated_names_map* get_decorated_names_map();
-
static opencl::command_dispatcher* get_command_dispatcher();
private:
@@ -32,57 +32,93 @@
#define CPPA_UNIFORM_TYPE_INFO_MAP_HPP
#include <set>
+#include <map>
#include <string>
-#include <utility> // std::pair
+#include <utility>
+#include <type_traits>
+
+#include "cppa/cppa_fwd.hpp"
+
+#include "cppa/util/duration.hpp"
+#include "cppa/util/type_list.hpp"
#include "cppa/detail/singleton_mixin.hpp"
-#include "cppa/detail/default_uniform_type_info_impl.hpp"
namespace cppa { class uniform_type_info; }
namespace cppa { namespace detail {
+using mapped_type_list = util::type_list<
+ bool,
+ any_tuple,
+ atom_value,
+ actor_ptr,
+ channel_ptr,
+ group_ptr,
+ process_information_ptr,
+ message_header,
+ std::nullptr_t,
+ util::duration,
+ util::void_type,
+ double,
+ float,
+ long double,
+ std::string,
+ std::u16string,
+ std::u32string,
+ std::map<std::string,std::string>
+>;
+
+using zipped_type_list = util::tl_zip_with_index<mapped_type_list>::type;
+
+// lookup table for built-in types
+extern const char* mapped_type_names[][2];
+
+template<typename T>
+constexpr const char* mapped_name() {
+ return mapped_type_names[util::tl_index_of<zipped_type_list,T>::value][1];
+}
+
+const char* mapped_name_by_decorated_name(const char* decorated_type_name);
+
+// lookup table for integer types
+extern const char* mapped_int_names[][2];
+
+template<typename T>
+constexpr const char* mapped_int_name() {
+ return mapped_int_names[sizeof(T)][std::is_signed<T>::value ? 1 : 0];
+}
+
class uniform_type_info_map_helper;
// note: this class is implemented in uniform_type_info.cpp
-class uniform_type_info_map : public singleton_mixin<uniform_type_info_map> {
+class uniform_type_info_map {
friend class uniform_type_info_map_helper;
friend class singleton_mixin<uniform_type_info_map>;
public:
- typedef std::set<std::string> set_type;
- typedef std::map<std::string, uniform_type_info*> uti_map_type;
- typedef std::map<int, std::pair<set_type, set_type> > int_map_type;
+ typedef const uniform_type_info* pointer;
- inline const int_map_type& int_names() const {
- return m_ints;
- }
+ virtual ~uniform_type_info_map();
- const uniform_type_info* by_raw_name(const std::string& name) const;
+ virtual pointer by_uniform_name(const std::string& name) const = 0;
- const uniform_type_info* by_uniform_name(const std::string& name) const;
+ virtual pointer by_rtti(const std::type_info& ti) const = 0;
- std::vector<const uniform_type_info*> get_all() const;
+ virtual std::vector<pointer> get_all() const = 0;
// NOT thread safe!
- bool insert(const std::set<std::string>& raw_names, uniform_type_info* uti);
-
- private:
-
- // maps raw typeid names to uniform type informations
- uti_map_type m_by_rname;
+ virtual bool insert(uniform_type_info* uti) = 0;
- // maps uniform names to uniform type informations
- uti_map_type m_by_uname;
+ static uniform_type_info_map* create_singleton();
- // maps sizeof(-integer_type-) to { signed-names-set, unsigned-names-set }
- int_map_type m_ints;
+ inline void dispose() { delete this; }
- uniform_type_info_map();
+ inline void destroy() { delete this; }
- ~uniform_type_info_map();
+ virtual void initialize() = 0;
};
View
@@ -67,10 +67,6 @@ inline detail::empty_tuple* get_empty_tuple() {
return detail::singleton_manager::get_empty_tuple();
}
-inline detail::decorated_names_map* get_decorated_names_map() {
- return detail::singleton_manager::get_decorated_names_map();
-}
-
} // namespace cppa
#endif // CPPA_SINGLETONS_HPP
View
@@ -187,12 +187,6 @@ class uniform_type_info {
static std::vector<const uniform_type_info*> instances();
/**
- * @brief Get the internal @p libcppa name for this type.
- * @returns A string describing the @p libcppa internal type name.
- */
- inline const std::string& name() const { return m_name; }
-
- /**
* @brief Creates an object of this type.
*/
object create() const;
@@ -203,6 +197,12 @@ class uniform_type_info {
object deserialize(deserializer* source) const;
/**
+ * @brief Get the internal @p libcppa name for this type.
+ * @returns A string describing the @p libcppa internal type name.
+ */
+ virtual const char* name() const = 0;
+
+ /**
* @brief Determines if this uniform_type_info describes the same
* type than @p tinfo.
* @returns @p true if @p tinfo describes the same type as @p this.
@@ -234,23 +234,9 @@ class uniform_type_info {
*/
virtual void deserialize(void* instance, deserializer* source) const = 0;
- /**
- * @brief Checks wheter <tt>src->seek_object()</tt>
- * returns @p tname and throws an exception if not.
- * @throws std::logic_error
- */
- static void assert_type_name(deserializer* src, const std::string& tname);
-
protected:
- /**
- * @brief Checks wheter <tt>src->seek_object()</tt>
- * returns {@link name()} and throws an exception if not.
- * @throws std::logic_error
- */
- void assert_type_name(deserializer* src) const;
-
- uniform_type_info(const std::string& uniform_name);
+ uniform_type_info() = default;
/**
* @brief Casts @p instance to the native type and deletes it.
@@ -270,10 +256,6 @@ class uniform_type_info {
*/
virtual void* new_instance(const void* instance = nullptr) const = 0;
- private:
-
- std::string m_name;
-
};
/**
Oops, something went wrong.

0 comments on commit 488ca97

Please sign in to comment.