Commit f20f86a2 authored by Dominik Charousset's avatar Dominik Charousset

Use message builder API instead of removed API

parent b90ccd38
...@@ -55,7 +55,9 @@ void ChatWidget::sendChatMessage() { ...@@ -55,7 +55,9 @@ void ChatWidget::sendChatMessage() {
}); });
QString line = input()->text(); QString line = input()->text();
if (line.startsWith('/')) { if (line.startsWith('/')) {
match_split(line.midRef(1).toUtf8().constData(), ' ') ( vector<string> words;
split(words, line.midRef(1).toUtf8().constData(), is_any_of(" "));
message_builder(words.begin(), words.end()).apply({
on("join", arg_match) >> [=](const string& mod, const string& g) { on("join", arg_match) >> [=](const string& mod, const string& g) {
group gptr; group gptr;
try { gptr = group::get(mod, g); } try { gptr = group::get(mod, g); }
...@@ -74,7 +76,7 @@ void ChatWidget::sendChatMessage() { ...@@ -74,7 +76,7 @@ void ChatWidget::sendChatMessage() {
"/join <module> <group id>\n" "/join <module> <group id>\n"
"/setName <new name>\n"); "/setName <new name>\n");
} }
); });
return; return;
} }
if (m_name.empty()) { if (m_name.empty()) {
......
...@@ -124,7 +124,9 @@ void client_repl(const string& host, uint16_t port) { ...@@ -124,7 +124,9 @@ void client_repl(const string& host, uint16_t port) {
anon_send_exit(client, exit_reason::user_shutdown); anon_send_exit(client, exit_reason::user_shutdown);
return; return;
} else if (equal(begin(connect), end(connect) - 1, begin(line))) { } else if (equal(begin(connect), end(connect) - 1, begin(line))) {
match_split(line, ' ') ( vector<string> words;
split(words, line, is_any_of(" "));
message_builder(words.begin(), words.end()).apply({
on("connect", arg_match) >> [&](string& nhost, string& sport) { on("connect", arg_match) >> [&](string& nhost, string& sport) {
try { try {
auto lport = std::stoul(sport); auto lport = std::stoul(sport);
...@@ -144,7 +146,7 @@ void client_repl(const string& host, uint16_t port) { ...@@ -144,7 +146,7 @@ void client_repl(const string& host, uint16_t port) {
others() >> [] { others() >> [] {
cout << "*** usage: connect <host> <port>" << endl; cout << "*** usage: connect <host> <port>" << endl;
} }
); });
} else { } else {
auto toint = [](const string& str) -> optional<int> { auto toint = [](const string& str) -> optional<int> {
try { return {std::stoi(str)}; } try { return {std::stoi(str)}; }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "caf/all.hpp" #include "caf/all.hpp"
#include "caf/io/all.hpp" #include "caf/io/all.hpp"
#include "caf/string_algorithms.hpp"
using namespace std; using namespace std;
using namespace caf; using namespace caf;
...@@ -127,9 +129,12 @@ int main(int argc, char** argv) { ...@@ -127,9 +129,12 @@ int main(int argc, char** argv) {
return none; return none;
}; };
}; };
istream_iterator<line> lines(cin);
istream_iterator<line> eof; istream_iterator<line> eof;
match_each (lines, eof, split_line) ( vector<string> words;
for (istream_iterator<line> i(cin); i != eof; ++i) {
words.clear();
split(words, i->str, is_any_of(" "));
message_builder(words.begin(), words.end()).apply({
on("/join", arg_match) >> [&](const string& mod, const string& id) { on("/join", arg_match) >> [&](const string& mod, const string& id) {
try { try {
group grp = (mod == "remote") ? io::remote_group(id) group grp = (mod == "remote") ? io::remote_group(id)
...@@ -155,7 +160,8 @@ int main(int argc, char** argv) { ...@@ -155,7 +160,8 @@ int main(int argc, char** argv) {
anon_send(client_actor, broadcast_atom::value, s_last_line); anon_send(client_actor, broadcast_atom::value, s_last_line);
} }
} }
); });
}
// force actor to quit // force actor to quit
anon_send_exit(client_actor, exit_reason::user_shutdown); anon_send_exit(client_actor, exit_reason::user_shutdown);
await_all_actors_done(); await_all_actors_done();
......
...@@ -52,7 +52,6 @@ set (LIBCAF_CORE_SRCS ...@@ -52,7 +52,6 @@ set (LIBCAF_CORE_SRCS
src/local_actor.cpp src/local_actor.cpp
src/logging.cpp src/logging.cpp
src/mailbox_element.cpp src/mailbox_element.cpp
src/match.cpp
src/memory.cpp src/memory.cpp
src/memory_managed.cpp src/memory_managed.cpp
src/message.cpp src/message.cpp
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include <vector>
#include <string>
#include <sstream>
#include "caf/match.hpp"
using namespace std;
namespace caf {
detail::match_helper match_split(const std::string& str, char delim,
bool keep_empties) {
message_builder result;
stringstream strs(str);
string tmp;
while (getline(strs, tmp, delim)) {
if (!tmp.empty() && !keep_empties) {
result.append(std::move(tmp));
}
}
return result.to_message();
}
} // namespace caf
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