Commit 85f7e0ff authored by Dominik Charousset's avatar Dominik Charousset

moved `memory_cached_mixin` to namespace cppa

the mixin is visible in the inheritance diagram for actors, hence it
belongs to namespace cppa rather than cppa::detail
parent 8c32441b
......@@ -289,3 +289,4 @@ unit_testing/test__tuple.cpp
unit_testing/test__type_list.cpp
unit_testing/test__uniform_type.cpp
unit_testing/test__yield_interface.cpp
cppa/memory_cached_mixin.hpp
......@@ -81,45 +81,6 @@ class memory_cache {
};
class memory;
memory_cache* get_cache_map_entry(const std::type_info* tinf);
template<typename T>
class basic_memory_cache;
template<typename Base>
class memory_cached_mixin : public Base {
friend class memory;
template<typename T>
friend class basic_memory_cache;
protected:
template<typename... Args>
memory_cached_mixin(Args&&... args)
: Base(std::forward<Args>(args)...), outer_memory(nullptr) { }
virtual void request_deletion() {
memory_cache* mc = get_cache_map_entry(&typeid(*this));
if (!mc) {
auto om = outer_memory;
if (om) {
om->destroy();
om->deallocate();
}
else delete this;
}
else mc->release_instance(mc->downcast(this));
}
private:
instance_wrapper* outer_memory;
};
template<typename T>
class basic_memory_cache : public memory_cache {
......@@ -219,6 +180,8 @@ class memory {
return result;
}
static memory_cache* get_cache_map_entry(const std::type_info* tinf);
private:
static void add_cache_map_entry(const std::type_info* tinf, memory_cache* instance);
......
......@@ -37,7 +37,7 @@
#include "cppa/any_tuple.hpp"
#include "cppa/message_id.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/detail/memory.hpp"
#include "cppa/memory_cached_mixin.hpp"
// needs access to constructor + destructor to initialize m_dummy_node
namespace cppa { class local_actor; }
......
......@@ -42,8 +42,8 @@
#include "cppa/exit_reason.hpp"
#include "cppa/response_handle.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/memory_cached_mixin.hpp"
#include "cppa/detail/memory.hpp"
#include "cppa/detail/recursive_queue_node.hpp"
namespace cppa {
......@@ -110,7 +110,7 @@ class message_future;
/**
* @brief Base class for local running Actors.
*/
class local_actor : public detail::memory_cached_mixin<actor> {
class local_actor : public memory_cached_mixin<actor> {
typedef actor super;
......
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* 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 3 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 MEMORY_CACHED_MIXIN_HPP
#define MEMORY_CACHED_MIXIN_HPP
#include "cppa/detail/memory.hpp"
namespace cppa {
/**
* @brief This mixin adds all member functions and member variables needed
* by the memory management subsystem.
*/
template<typename Base>
class memory_cached_mixin : public Base {
friend class detail::memory;
template<typename T>
friend class detail::basic_memory_cache;
protected:
template<typename... Args>
memory_cached_mixin(Args&&... args)
: Base(std::forward<Args>(args)...), outer_memory(nullptr) { }
virtual void request_deletion() {
auto mc = detail::memory::get_cache_map_entry(&typeid(*this));
if (!mc) {
auto om = outer_memory;
if (om) {
om->destroy();
om->deallocate();
}
else delete this;
}
else mc->release_instance(mc->downcast(this));
}
private:
detail::instance_wrapper* outer_memory;
};
} // namespace cppa
#endif // MEMORY_CACHED_MIXIN_HPP
......@@ -32,6 +32,7 @@
#define DEFAULT_ACTOR_PROXY_HPP
#include "cppa/actor_proxy.hpp"
#include "cppa/memory_cached_mixin.hpp"
#include "cppa/network/default_protocol.hpp"
......@@ -48,7 +49,7 @@ class basic_memory_cache;
namespace cppa { namespace network {
class sync_request_info : public detail::memory_cached_mixin<memory_managed> {
class sync_request_info : public memory_cached_mixin<memory_managed> {
friend class detail::memory;
......
......@@ -70,7 +70,7 @@ cache_map& get_cache_map() {
return *cache;
}
memory_cache* get_cache_map_entry(const type_info* tinf) {
memory_cache* memory::get_cache_map_entry(const type_info* tinf) {
auto& cache = get_cache_map();
auto i = cache.find(tinf);
if (i != cache.end()) return i->second.get();
......
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