Commit 1620b8ab authored by neverlord's avatar neverlord

local group tests

parent 7893d7a1
......@@ -38,7 +38,8 @@ inline void receive(invoke_rules& rules)
inline void receive(invoke_rules&& rules)
{
this_actor()->receive(rules);
invoke_rules tmp(std::move(rules));
this_actor()->receive(tmp);
}
inline const message& last_dequeued()
......
......@@ -10,7 +10,8 @@
namespace cppa {
template<typename T>
class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>
class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>,
detail::comparable<intrusive_ptr<T>>
{
T* m_ptr;
......@@ -105,35 +106,24 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>, T*>
return get() == ptr;
}
template<typename Y>
inline bool equal_to(const Y* ptr) const
{
return get() == ptr;
}
inline bool operator==(const intrusive_ptr& other) const
{
return equal_to(other.get());
}
template<typename Y>
inline bool operator==(const intrusive_ptr<Y>& other) const
inline bool equal_to(const intrusive_ptr& other) const
{
return equal_to(other.get());
return get() == other.get();
}
inline bool operator!=(const intrusive_ptr& other) const
{
return !(*this == other);
}
};
template<typename Y>
inline bool operator!=(const intrusive_ptr<Y>& other) const
{
return !(*this == other);
}
template<typename X, typename Y>
bool operator==(const intrusive_ptr<X>& lhs, const intrusive_ptr<Y>& rhs)
{
return lhs.get() == rhs.get();
}
};
template<typename X, typename Y>
bool operator!=(const intrusive_ptr<X>& lhs, const intrusive_ptr<Y>& rhs)
{
return lhs.get() != rhs.get();
}
} // namespace cppa
......
......@@ -20,6 +20,11 @@ struct invoke_rules
invoke_rules() { }
invoke_rules(invoke_rules&& other) : m_list(std::move(other.m_list))
{
other.m_list.clear();
}
invoke_rules(intrusive_ptr<detail::invokable>&& arg)
{
if (arg) m_list.push_back(arg);
......
......@@ -80,6 +80,19 @@ get_view(const Tuple<TupleTypes...>& t)
throw std::runtime_error("matcher did not return a valid mapping");
}
template<typename... MatchRules>
typename tuple_view_type_from_type_list<typename util::filter_type_list<any_type, util::type_list<MatchRules...>>::type>::type
get_view(const untyped_tuple& t)
{
std::vector<std::size_t> mappings;
if (match<MatchRules...>(t, mappings))
{
return { t.vals(), std::move(mappings) };
}
// todo: throw nicer exception
throw std::runtime_error("doesn't match");
}
} // namespace cppa
#endif // MATCH_HPP
......@@ -26,10 +26,6 @@ class message
: sender(s), receiver(r), data(ut)
{
}
content(const actor& s, const message_receiver& r, untyped_tuple&& ut)
: sender(s), receiver(r), data(ut)
{
}
};
private:
......
......@@ -5,13 +5,15 @@
#include <typeinfo>
#include "cppa/object.hpp"
#include "cppa/detail/comparable.hpp"
namespace cppa {
/**
* @brief Uniform type information.
*/
struct utype
struct utype : detail::comparable<utype>,
detail::comparable<utype, std::type_info>
{
/**
......@@ -30,6 +32,16 @@ struct utype
*/
virtual const std::type_info& native() const = 0;
inline bool equal_to(const std::type_info& what) const
{
return native() == what;
}
inline bool equal_to(const utype& what) const
{
return native() == what.native();
}
};
} // namespace cppa
......
CXX = /opt/local/bin/g++-mp-4.5
#CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -g -O0 -I/opt/local/include/
CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/ -fPIC
LIBS = -L/opt/local/lib -lboost_thread-mt
include Makefile.rules
INCLUDES = -I./
#CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/ -fPIC
HEADERS = cppa/actor.hpp \
cppa/any_type.hpp \
cppa/config.hpp \
......
......@@ -51,8 +51,8 @@ struct actor_impl : cppa::detail::actor_private
virtual void receive(cppa::invoke_rules& rules)
{
cppa::util::singly_linked_list<actor_message> buffer;
actor_message* amsg = mailbox.pop();
cppa::util::singly_linked_list<actor_message> buffer;
cppa::intrusive_ptr<cppa::detail::intermediate> imd;
while (!(imd = rules.get_intermediate(amsg->msg.data())))
{
......@@ -60,9 +60,9 @@ struct actor_impl : cppa::detail::actor_private
amsg = mailbox.pop();
}
m_last_dequeued = amsg->msg;
delete amsg;
if (!buffer.empty()) mailbox.prepend(std::move(buffer));
imd->invoke();
mailbox.prepend(std::move(buffer));
delete amsg;
}
virtual void send(cppa::detail::channel* whom,
......
CXX = /opt/local/bin/g++-mp-4.5
include ../Makefile.rules
#CXX = /opt/local/bin/g++-mp-4.5
#CXX = /opt/local/bin/g++-mp-4.6
#CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -g -O0 -I/opt/local/include/
CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/
LIBS = -L/opt/local/lib -lboost_thread-mt -L../ -lcppa
#CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/
#LIBS = -L/opt/local/lib -lboost_thread-mt -L../ -lcppa
INCLUDES = -I./ -I../
EXECUTABLE = ../test
......@@ -28,7 +30,7 @@ OBJECTS = $(SOURCES:.cpp=.o)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
$(EXECUTABLE) : $(OBJECTS) $(HEADERS)
$(CXX) $(LIBS) -L./ -lcppa $(OBJECTS) -o $(EXECUTABLE)
$(CXX) $(LIBS) -L../ -lcppa $(OBJECTS) -o $(EXECUTABLE)
all : $(EXECUTABLE)
......
......@@ -133,6 +133,32 @@ struct
}
local;
struct storage
{
std::map<std::string, intrusive_ptr<object>> m_map;
public:
template<typename T>
T& get(const std::string& key)
{
const utype& uti = uniform_type_info<T>();
auto i = m_map.find(key);
if (i == m_map.end())
{
i = m_map.insert(std::make_pair(key, uti.create())).first;
}
else if (uti != i->second->type())
{
// todo: throw nicer exception
throw std::runtime_error("invalid type");
}
return *reinterpret_cast<T*>(i->second->mutable_value());
}
};
void foo_actor()
{
auto x = (local/"foobar")->subscribe(this_actor());
......@@ -149,6 +175,19 @@ std::size_t test__local_group()
CPPA_TEST(test__local_group);
/*
storage st;
st.get<int>("foobaz") = 42;
CPPA_CHECK_EQUAL(st.get<int>("foobaz"), 42);
st.get<std::string>("_s") = "Hello World!";
CPPA_CHECK_EQUAL(st.get<std::string>("_s"), "Hello World!");
*/
auto g = local/"foobar";
for (int i = 0; i < 5; ++i)
......@@ -158,17 +197,20 @@ std::size_t test__local_group()
for (int i = 0; i < 5; ++i)
{
receive(on<float>() >> [&]() { });
receive(on<float>() >> []() { });
}
g->send(1);
int result = 0;
auto rule = on<int>() >> [&result](int x) {
result += x;
};
for (int i = 0; i < 5; ++i)
{
receive(on<int>() >> [&](int x) {
result += x;
});
receive(rule);
}
CPPA_CHECK_EQUAL(result, 5);
......
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