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() {
});
QString line = input()->text();
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) {
group gptr;
try { gptr = group::get(mod, g); }
......@@ -74,7 +76,7 @@ void ChatWidget::sendChatMessage() {
"/join <module> <group id>\n"
"/setName <new name>\n");
}
);
});
return;
}
if (m_name.empty()) {
......
......@@ -124,7 +124,9 @@ void client_repl(const string& host, uint16_t port) {
anon_send_exit(client, exit_reason::user_shutdown);
return;
} 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) {
try {
auto lport = std::stoul(sport);
......@@ -144,7 +146,7 @@ void client_repl(const string& host, uint16_t port) {
others() >> [] {
cout << "*** usage: connect <host> <port>" << endl;
}
);
});
} else {
auto toint = [](const string& str) -> optional<int> {
try { return {std::stoi(str)}; }
......
......@@ -18,6 +18,8 @@
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/string_algorithms.hpp"
using namespace std;
using namespace caf;
......@@ -127,35 +129,39 @@ int main(int argc, char** argv) {
return none;
};
};
istream_iterator<line> lines(cin);
istream_iterator<line> eof;
match_each (lines, eof, split_line) (
on("/join", arg_match) >> [&](const string& mod, const string& id) {
try {
group grp = (mod == "remote") ? io::remote_group(id)
: group::get(mod, id);
anon_send(client_actor, join_atom::value, grp);
}
catch (exception& e) {
cerr << "*** exception: " << to_verbose_string(e) << endl;
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) {
try {
group grp = (mod == "remote") ? io::remote_group(id)
: group::get(mod, id);
anon_send(client_actor, join_atom::value, grp);
}
catch (exception& e) {
cerr << "*** exception: " << to_verbose_string(e) << endl;
}
},
on("/quit") >> [&] {
// close STDIN; causes this match loop to quit
cin.setstate(ios_base::eofbit);
},
on(starts_with("/"), any_vals) >> [&] {
cout << "*** available commands:\n"
" /join <module> <group> join a new chat channel\n"
" /quit quit the program\n"
" /help print this text\n" << flush;
},
others() >> [&] {
if (!s_last_line.empty()) {
anon_send(client_actor, broadcast_atom::value, s_last_line);
}
}
},
on("/quit") >> [&] {
// close STDIN; causes this match loop to quit
cin.setstate(ios_base::eofbit);
},
on(starts_with("/"), any_vals) >> [&] {
cout << "*** available commands:\n"
" /join <module> <group> join a new chat channel\n"
" /quit quit the program\n"
" /help print this text\n" << flush;
},
others() >> [&] {
if (!s_last_line.empty()) {
anon_send(client_actor, broadcast_atom::value, s_last_line);
}
}
);
});
}
// force actor to quit
anon_send_exit(client_actor, exit_reason::user_shutdown);
await_all_actors_done();
......
......@@ -52,7 +52,6 @@ set (LIBCAF_CORE_SRCS
src/local_actor.cpp
src/logging.cpp
src/mailbox_element.cpp
src/match.cpp
src/memory.cpp
src/memory_managed.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