Commit 466b6322 authored by neverlord's avatar neverlord

restructuring

parent 4aaf8427
.DS_Store .DS_Store
*.o *.o
*.dylib
test test
all: all:
make -f libcppa.Makefile make -f libcppa.Makefile
make -f test.Makefile make -C unit_testing
clean: clean:
make -f libcppa.Makefile clean make -f libcppa.Makefile clean
make -f test.Makefile clean make -C unit_testing clean
...@@ -60,15 +60,15 @@ ...@@ -60,15 +60,15 @@
<valuemap type="QVariantMap"> <valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">all</value> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">all</value>
<valuelist key="abstractProcess.Environment" type="QVariantList"> <valuelist key="abstractProcess.Environment" type="QVariantList">
<value type="QString">Apple_PubSub_Socket_Render=/tmp/launch-omyHKo/Render</value> <value type="QString">Apple_PubSub_Socket_Render=/tmp/launch-Ii2KqP/Render</value>
<value type="QString">COMMAND_MODE=unix2003</value> <value type="QString">COMMAND_MODE=unix2003</value>
<value type="QString">DISPLAY=/tmp/launch-fg6icm/org.x:0</value> <value type="QString">DISPLAY=/tmp/launch-6FAyZP/org.x:0</value>
<value type="QString">HOME=/Users/neverlord</value> <value type="QString">HOME=/Users/neverlord</value>
<value type="QString">LOGNAME=neverlord</value> <value type="QString">LOGNAME=neverlord</value>
<value type="QString">PATH=/usr/bin:/bin:/usr/sbin:/sbin</value> <value type="QString">PATH=/usr/bin:/bin:/usr/sbin:/sbin</value>
<value type="QString">SHELL=/bin/bash</value> <value type="QString">SHELL=/bin/bash</value>
<value type="QString">SSH_AUTH_SOCK=/tmp/launch-3s45KF/Listeners</value> <value type="QString">SSH_AUTH_SOCK=/tmp/launch-vifjfO/Listeners</value>
<value type="QString">TMPDIR=/var/folders/SE/SEReyCW0H-yDPCnNCe8mN++++TI/-Tmp-/</value> <value type="QString">TMPDIR=/var/folders/1p/1p6iuPgbH7GoDkrjrT20tU+++TI/-Tmp-/</value>
<value type="QString">USER=neverlord</value> <value type="QString">USER=neverlord</value>
<value type="QString">__CF_USER_TEXT_ENCODING=0x1F5:0:3</value> <value type="QString">__CF_USER_TEXT_ENCODING=0x1F5:0:3</value>
</valuelist> </valuelist>
......
cppa/ref_counted.hpp cppa/ref_counted.hpp
cppa/tuple.hpp cppa/tuple.hpp
src/main.cpp unit_testing/main.cpp
src/ref_counted.cpp src/ref_counted.cpp
cppa/util/void_type.hpp cppa/util/void_type.hpp
cppa/util/type_list.hpp cppa/util/type_list.hpp
...@@ -10,12 +10,12 @@ cppa/util.hpp ...@@ -10,12 +10,12 @@ cppa/util.hpp
cppa/util/is_one_of.hpp cppa/util/is_one_of.hpp
cppa/util/conjunction.hpp cppa/util/conjunction.hpp
cppa/util/disjunction.hpp cppa/util/disjunction.hpp
cppa/test.hpp unit_testing/test.hpp
src/test__a_matches_b.cpp unit_testing/test__a_matches_b.cpp
cppa/uniform_type_info.hpp cppa/uniform_type_info.hpp
src/uniform_type_info.cpp src/uniform_type_info.cpp
cppa/config.hpp cppa/config.hpp
src/test__tuple.cpp unit_testing/test__tuple.cpp
cppa/detail/abstract_tuple.hpp cppa/detail/abstract_tuple.hpp
cppa/tuple_view.hpp cppa/tuple_view.hpp
cppa/untyped_tuple.hpp cppa/untyped_tuple.hpp
...@@ -31,17 +31,17 @@ cppa/util/detach.hpp ...@@ -31,17 +31,17 @@ cppa/util/detach.hpp
cppa/detail/ref_counted_impl.hpp cppa/detail/ref_counted_impl.hpp
cppa/intrusive_ptr.hpp cppa/intrusive_ptr.hpp
cppa/detail/scheduler.hpp cppa/detail/scheduler.hpp
src/test__spawn.cpp unit_testing/test__spawn.cpp
src/mock_scheduler.cpp src/mock_scheduler.cpp
cppa/actor.hpp cppa/actor.hpp
cppa/message.hpp cppa/message.hpp
src/test__intrusive_ptr.cpp unit_testing/test__intrusive_ptr.cpp
cppa/util/concat_type_lists.hpp cppa/util/concat_type_lists.hpp
cppa/util/filter_type_list.hpp cppa/util/filter_type_list.hpp
cppa/util/is_comparable.hpp cppa/util/is_comparable.hpp
cppa/util/callable_trait.hpp cppa/util/callable_trait.hpp
cppa/util/reverse_type_list.hpp cppa/util/reverse_type_list.hpp
src/test__type_list.cpp unit_testing/test__type_list.cpp
cppa/util/remove_const_reference.hpp cppa/util/remove_const_reference.hpp
cppa/util/type_list_apply.hpp cppa/util/type_list_apply.hpp
cppa/util/eval_type_lists.hpp cppa/util/eval_type_lists.hpp
...@@ -56,7 +56,7 @@ cppa/invoke_rules.hpp ...@@ -56,7 +56,7 @@ cppa/invoke_rules.hpp
cppa/util/type_list_pop_back.hpp cppa/util/type_list_pop_back.hpp
cppa/invoke.hpp cppa/invoke.hpp
cppa/on.hpp cppa/on.hpp
src/test__serialization.cpp unit_testing/test__serialization.cpp
cppa/serializer.hpp cppa/serializer.hpp
cppa/deserializer.hpp cppa/deserializer.hpp
cppa/util/is_serializable.hpp cppa/util/is_serializable.hpp
...@@ -76,8 +76,8 @@ cppa/util/sink.hpp ...@@ -76,8 +76,8 @@ cppa/util/sink.hpp
src/untyped_tuple.cpp src/untyped_tuple.cpp
cppa/util/abstract_type_list.hpp cppa/util/abstract_type_list.hpp
cppa/detail/serialize_tuple.hpp cppa/detail/serialize_tuple.hpp
src/test__atom.cpp unit_testing/test__atom.cpp
src/test__queue_performance.cpp unit_testing/test__queue_performance.cpp
cppa/detail/actor_public.hpp cppa/detail/actor_public.hpp
cppa/detail/comparable.hpp cppa/detail/comparable.hpp
cppa/util/single_reader_queue.hpp cppa/util/single_reader_queue.hpp
...@@ -85,3 +85,6 @@ cppa/util/singly_linked_list.hpp ...@@ -85,3 +85,6 @@ cppa/util/singly_linked_list.hpp
cppa/detail/spawn_impl.hpp cppa/detail/spawn_impl.hpp
cppa/detail/actor_private.hpp cppa/detail/actor_private.hpp
cppa/reply.hpp cppa/reply.hpp
unit_testing/test__local_group.cpp
unit_testing/hash_of.cpp
cppa/spawn.hpp
/Users/neverlord/libcppa /Users/neverlord/libcppa
/opt/local/include/gcc45/c++ /opt/local/include/gcc45/c++
/Users/neverlord/libcppa/unit_testing
...@@ -47,6 +47,12 @@ class actor ...@@ -47,6 +47,12 @@ class actor
this_actor()->send(m_ptr.get(), args); this_actor()->send(m_ptr.get(), args);
} }
inline bool operator==(const actor& other) const
{
return m_ptr == other.m_ptr;
}
private: private:
ptr_type m_ptr; ptr_type m_ptr;
......
...@@ -2,22 +2,24 @@ CXX = /opt/local/bin/g++-mp-4.5 ...@@ -2,22 +2,24 @@ CXX = /opt/local/bin/g++-mp-4.5
#CXX = /opt/local/bin/g++-mp-4.6 #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 -g -O0 -I/opt/local/include/
CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/ CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/
LIBS = -L/opt/local/lib -lboost_thread-mt LIBS = -L/opt/local/lib -lboost_thread-mt -L../ -lcppa
INCLUDES = -I./ INCLUDES = -I./ -I../
EXECUTABLE = test EXECUTABLE = ../test
HEADERS = cppa/test.hpp HEADERS = test.hpp
SOURCES = src/main.cpp \ SOURCES = hash_of.cpp \
src/test__a_matches_b.cpp \ main.cpp \
src/test__atom.cpp \ test__a_matches_b.cpp \
src/test__intrusive_ptr.cpp \ test__atom.cpp \
src/test__queue_performance.cpp \ test__intrusive_ptr.cpp \
src/test__serialization.cpp \ test__local_group.cpp \
src/test__spawn.cpp \ test__queue_performance.cpp \
src/test__tuple.cpp \ test__serialization.cpp \
src/test__type_list.cpp test__spawn.cpp \
test__tuple.cpp \
test__type_list.cpp
OBJECTS = $(SOURCES:.cpp=.o) OBJECTS = $(SOURCES:.cpp=.o)
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#include <typeinfo> #include <typeinfo>
#include <iostream> #include <iostream>
#include "cppa/test.hpp" #include "test.hpp"
#include "cppa/tuple.hpp" #include "cppa/tuple.hpp"
#include "cppa/config.hpp" #include "cppa/config.hpp"
#include "cppa/uniform_type_info.hpp" #include "cppa/uniform_type_info.hpp"
...@@ -59,6 +60,7 @@ int main(int argc, char** c_argv) ...@@ -59,6 +60,7 @@ int main(int argc, char** c_argv)
RUN_TEST(test__type_list); RUN_TEST(test__type_list);
RUN_TEST(test__serialization); RUN_TEST(test__serialization);
RUN_TEST(test__atom); RUN_TEST(test__atom);
RUN_TEST(test__local_group);
cout << endl cout << endl
<< "error(s) in all tests: " << errors << "error(s) in all tests: " << errors
<< endl; << endl;
......
...@@ -34,6 +34,10 @@ if ((lhs_loc) != (rhs_loc)) \ ...@@ -34,6 +34,10 @@ if ((lhs_loc) != (rhs_loc)) \
++error_count; \ ++error_count; \
} ((void) 0) } ((void) 0)
unsigned int hash_of(const char* what, int what_length);
unsigned int hash_of(const std::string& what);
std::size_t test__type_list(); std::size_t test__type_list();
std::size_t test__a_matches_b(); std::size_t test__a_matches_b();
std::size_t test__atom(); std::size_t test__atom();
...@@ -41,6 +45,7 @@ std::size_t test__tuple(); ...@@ -41,6 +45,7 @@ std::size_t test__tuple();
std::size_t test__spawn(); std::size_t test__spawn();
std::size_t test__intrusive_ptr(); std::size_t test__intrusive_ptr();
std::size_t test__serialization(); std::size_t test__serialization();
std::size_t test__local_group();
void test__queue_performance(); void test__queue_performance();
......
#include <string> #include <string>
#include <typeinfo> #include <typeinfo>
#include "cppa/test.hpp" #include "test.hpp"
#include "cppa/util.hpp" #include "cppa/util.hpp"
using namespace cppa; using namespace cppa;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <typeinfo> #include <typeinfo>
#include <iostream> #include <iostream>
#include "cppa/test.hpp" #include "test.hpp"
#include "cppa/util.hpp" #include "cppa/util.hpp"
using std::cout; using std::cout;
...@@ -11,70 +11,6 @@ using std::endl; ...@@ -11,70 +11,6 @@ using std::endl;
using namespace cppa; using namespace cppa;
using namespace cppa::util; using namespace cppa::util;
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed )
{
static_assert(sizeof(int) == 4,
"MurmurHash2 requires sizeof(int) == 4");
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
const unsigned int m = 0x5bd1e995;
const int r = 24;
// Initialize the hash to a 'random' value
unsigned int h = seed ^ len;
// Mix 4 bytes at a time into the hash
const unsigned char * data = (const unsigned char *)key;
while(len >= 4)
{
unsigned int k = *(unsigned int *)data;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
len -= 4;
}
// Handle the last few bytes of the input array
switch(len)
{
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
h *= m;
};
// Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h;
}
unsigned int hash_of(const char* what, int what_length)
{
return MurmurHash2(what, what_length, 0x15091984);
}
unsigned int hash_of(const std::string& what)
{
return MurmurHash2(what.c_str(), what.size(), 0x15091984);
}
template<char... Str> template<char... Str>
struct _tostring; struct _tostring;
......
#include <list> #include <list>
#include <cstddef> #include <cstddef>
#include "cppa/test.hpp" #include "test.hpp"
#include "cppa/intrusive_ptr.hpp" #include "cppa/intrusive_ptr.hpp"
#include "cppa/detail/ref_counted_impl.hpp" #include "cppa/detail/ref_counted_impl.hpp"
......
#include "test.hpp"
#include "cppa/on.hpp"
#include "cppa/spawn.hpp"
#include "cppa/reply.hpp"
#include "cppa/actor.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/intrusive_ptr.hpp"
#include <map>
#include <list>
#include <iostream>
#include <algorithm>
#include <boost/thread/mutex.hpp>
using std::cout;
using std::endl;
using namespace cppa;
class group : public ref_counted
{
boost::mutex m_mtx;
std::list<actor> m_subscribers;
public:
struct subscription
{
actor m_self;
intrusive_ptr<group> m_group;
subscription(const actor& s, const intrusive_ptr<group>& g)
: m_self(s), m_group(g)
{
}
~subscription()
{
m_group->unsubscribe(m_self);
}
};
subscription subscribe(const actor& who)
{
boost::mutex::scoped_lock guard(m_mtx);
m_subscribers.push_back(who);
return { who, this };
}
void unsubscribe(const actor& who)
{
boost::mutex::scoped_lock guard(m_mtx);
auto i = std::find(m_subscribers.begin(), m_subscribers.end(), who);
if (i != m_subscribers.end())
{
m_subscribers.erase(i);
}
}
template<typename... Args>
void send(const Args&... args)
{
boost::mutex::scoped_lock guard(m_mtx);
for (auto i = m_subscribers.begin(); i != m_subscribers.end(); ++i)
{
i->send(args...);
}
}
};
namespace {
class group_bucket
{
boost::mutex m_mtx;
std::map<std::string, intrusive_ptr<group>> m_groups;
public:
intrusive_ptr<group> get(const std::string& group_name)
{
boost::mutex::scoped_lock guard(m_mtx);
intrusive_ptr<group>& result = m_groups[group_name];
if (!result)
{
result.reset(new group);
}
return result;
}
};
template<std::size_t NumBuckets>
class group_table
{
group_bucket m_buckets[NumBuckets];
group_bucket& bucket(const std::string& group_name)
{
unsigned int gn_hash = hash_of(group_name);
return m_buckets[gn_hash % NumBuckets];
}
public:
intrusive_ptr<group> operator[](const std::string& group_name)
{
return bucket(group_name).get(group_name);
}
};
group_table<100> m_groups;
} // namespace <anonymous>
struct
{
intrusive_ptr<group> operator/(const std::string& group_name)
{
return m_groups[group_name];
}
}
local;
void foo_actor()
{
auto x = (local/"foobar")->subscribe(this_actor());
receive(on<int, int, int>() >> []() {
reply(23.f);
});
receive(on<int>() >> [](int i) {
reply(i);
});
}
std::size_t test__local_group()
{
CPPA_TEST(test__local_group);
auto g = local/"foobar";
for (int i = 0; i < 5; ++i)
{
spawn(foo_actor).send(1, 2, 3);
}
for (int i = 0; i < 5; ++i)
{
receive(on<float>() >> [&]() { });
}
g->send(1);
int result = 0;
for (int i = 0; i < 5; ++i)
{
receive(on<int>() >> [&](int x) {
result += x;
});
}
CPPA_CHECK_EQUAL(result, 5);
return CPPA_TEST_RESULT;
}
#include <list> #include <list>
#include <atomic> #include <atomic>
#include <iostream> #include <iostream>
#include "cppa/test.hpp" #include "test.hpp"
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include <iostream> #include <iostream>
#include <type_traits> #include <type_traits>
#include "cppa/test.hpp" #include "test.hpp"
#include "cppa/util.hpp" #include "cppa/util.hpp"
#include "cppa/match.hpp" #include "cppa/match.hpp"
#include "cppa/tuple.hpp" #include "cppa/tuple.hpp"
......
#include <iostream> #include <iostream>
#include <functional> #include <functional>
#include "test.hpp"
#include "cppa/on.hpp" #include "cppa/on.hpp"
#include "cppa/test.hpp"
#include "cppa/actor.hpp" #include "cppa/actor.hpp"
#include "cppa/spawn.hpp"
#include "cppa/detail/scheduler.hpp" #include "cppa/detail/scheduler.hpp"
using std::cout; using std::cout;
...@@ -11,25 +13,6 @@ using std::endl; ...@@ -11,25 +13,6 @@ using std::endl;
using namespace cppa; using namespace cppa;
template<typename F>
actor spawn(F act_fun)
{
struct bhv : cppa::detail::behavior
{
std::function<void ()> m_act;
bhv(const F& invokable) : m_act(invokable) { }
virtual void act()
{
m_act();
}
virtual void on_exit()
{
}
};
return cppa::detail::spawn_impl(new bhv(act_fun));
// return actor();
}
void pong() void pong()
{ {
receive(on<int>() >> [](int value) { receive(on<int>() >> [](int value) {
......
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
#include <typeinfo> #include <typeinfo>
#include <functional> #include <functional>
#include "test.hpp"
#include "cppa/on.hpp" #include "cppa/on.hpp"
#include "cppa/util.hpp" #include "cppa/util.hpp"
#include "cppa/test.hpp"
#include "cppa/tuple.hpp" #include "cppa/tuple.hpp"
#include "cppa/match.hpp" #include "cppa/match.hpp"
#include "cppa/invoke.hpp" #include "cppa/invoke.hpp"
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
#include <typeinfo> #include <typeinfo>
#include <type_traits> #include <type_traits>
#include "test.hpp"
#include "cppa/util.hpp" #include "cppa/util.hpp"
#include "cppa/test.hpp"
#include "cppa/uniform_type_info.hpp" #include "cppa/uniform_type_info.hpp"
using std::cout; using std::cout;
......
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