Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
2e1201df
Commit
2e1201df
authored
Jan 06, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make c_args_remainder const
parent
d7653648
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
38 deletions
+39
-38
examples/qtsupport/qt_group_chat.cpp
examples/qtsupport/qt_group_chat.cpp
+10
-14
libcaf_core/caf/actor_system_config.hpp
libcaf_core/caf/actor_system_config.hpp
+4
-2
libcaf_core/src/actor_system_config.cpp
libcaf_core/src/actor_system_config.cpp
+25
-22
No files found.
examples/qtsupport/qt_group_chat.cpp
View file @
2e1201df
...
...
@@ -9,26 +9,25 @@
* - qt_group_chat -g remote:chatroom@localhost:4242 -n bob *
\******************************************************************************/
#include <set>
#include <map>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <time.h>
#include <
cstdlib
>
#include <
vector
>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
CAF_PUSH_WARNINGS
#include <QMainWindow>
#include <QApplication>
#include "ui_chatwindow.h" // auto generated from chatwindow.ui
#include <QApplication>
#include <QMainWindow>
CAF_POP_WARNINGS
#include "chatwidget.hpp"
using
namespace
std
;
using
namespace
caf
;
class
config
:
public
actor_system_config
{
...
...
@@ -43,7 +42,7 @@ public:
int
caf_main
(
actor_system
&
sys
,
const
config
&
cfg
)
{
std
::
string
name
;
if
(
auto
config_name
=
get_if
<
std
::
string
>
(
&
cfg
,
"name"
))
name
=
*
config_name
;
name
=
std
::
move
(
*
config_name
)
;
while
(
name
.
empty
())
{
std
::
cout
<<
"please enter your name: "
<<
std
::
flush
;
if
(
!
std
::
getline
(
std
::
cin
,
name
))
{
...
...
@@ -62,8 +61,7 @@ int caf_main(actor_system& sys, const config& cfg) {
<<
std
::
endl
;
}
}
auto
[
argc
,
argv
]
=
const_cast
<
config
&>
(
cfg
).
c_args_remainder
();
auto
[
argc
,
argv
]
=
cfg
.
c_args_remainder
();
QApplication
app
{
argc
,
argv
};
app
.
setQuitOnLastWindowClosed
(
true
);
QMainWindow
mw
;
...
...
@@ -71,10 +69,8 @@ int caf_main(actor_system& sys, const config& cfg) {
helper
.
setupUi
(
&
mw
);
helper
.
chatwidget
->
init
(
sys
);
auto
client
=
helper
.
chatwidget
->
as_actor
();
if
(
!
name
.
empty
())
send_as
(
client
,
client
,
set_name_atom_v
,
move
(
name
));
if
(
grp
)
send_as
(
client
,
client
,
join_atom_v
,
std
::
move
(
grp
));
anon_send
(
client
,
set_name_atom_v
,
move
(
name
));
anon_send
(
client
,
join_atom_v
,
std
::
move
(
grp
));
mw
.
show
();
return
app
.
exec
();
}
...
...
libcaf_core/caf/actor_system_config.hpp
View file @
2e1201df
...
...
@@ -197,7 +197,7 @@ public:
/// necessary buffers lazily on first call.
/// @note The returned pointer remains valid only as long as the
/// `actor_system_config` object exists.
std
::
pair
<
int
,
char
**>
c_args_remainder
();
std
::
pair
<
int
,
char
**>
c_args_remainder
()
const
noexcept
;
// -- caf-run parameters -----------------------------------------------------
...
...
@@ -328,7 +328,9 @@ protected:
config_option_set
custom_options_
;
private:
std
::
vector
<
char
*>
c_args_remainder_
;
void
set_remainder
(
string_list
args
);
mutable
std
::
vector
<
char
*>
c_args_remainder_
;
std
::
vector
<
char
>
c_args_remainder_buf_
;
actor_system_config
&
set_impl
(
string_view
name
,
config_value
value
);
...
...
libcaf_core/src/actor_system_config.cpp
View file @
2e1201df
...
...
@@ -206,25 +206,27 @@ error actor_system_config::parse(int argc, char** argv, std::istream& conf) {
return
parse
(
std
::
move
(
args
),
conf
);
}
std
::
pair
<
int
,
char
**>
actor_system_config
::
c_args_remainder
()
{
if
(
c_args_remainder_
.
empty
())
{
c_args_remainder_buf_
.
assign
(
program_name
.
begin
(),
program_name
.
end
());
std
::
pair
<
int
,
char
**>
actor_system_config
::
c_args_remainder
()
const
noexcept
{
return
{
static_cast
<
int
>
(
c_args_remainder_
.
size
()),
c_args_remainder_
.
data
()};
}
void
actor_system_config
::
set_remainder
(
string_list
args
)
{
remainder
.
swap
(
args
);
c_args_remainder_buf_
.
assign
(
program_name
.
begin
(),
program_name
.
end
());
c_args_remainder_buf_
.
emplace_back
(
'\0'
);
for
(
const
auto
&
arg
:
remainder
)
{
c_args_remainder_buf_
.
insert
(
c_args_remainder_buf_
.
end
(),
//
arg
.
begin
(),
arg
.
end
());
c_args_remainder_buf_
.
emplace_back
(
'\0'
);
for
(
const
auto
&
arg
:
remainder
)
{
c_args_remainder_buf_
.
insert
(
c_args_remainder_buf_
.
end
(),
//
arg
.
begin
(),
arg
.
end
());
c_args_remainder_buf_
.
emplace_back
(
'\0'
);
}
auto
ptr
=
c_args_remainder_buf_
.
data
();
auto
end
=
ptr
+
c_args_remainder_buf_
.
size
();
auto
advance_ptr
=
[
&
ptr
]
{
while
(
*
ptr
++
!=
'\0'
)
;
// nop
};
for
(;
ptr
!=
end
;
advance_ptr
())
c_args_remainder_
.
emplace_back
(
ptr
);
}
return
{
static_cast
<
int
>
(
c_args_remainder_
.
size
()),
c_args_remainder_
.
data
()};
auto
ptr
=
c_args_remainder_buf_
.
data
();
auto
end
=
ptr
+
c_args_remainder_buf_
.
size
();
auto
advance_ptr
=
[
&
ptr
]
{
while
(
*
ptr
++
!=
'\0'
)
;
// nop
};
for
(;
ptr
!=
end
;
advance_ptr
())
c_args_remainder_
.
emplace_back
(
ptr
);
}
namespace
{
...
...
@@ -316,15 +318,16 @@ error actor_system_config::parse(string_list args, std::istream& config) {
using
std
::
make_move_iterator
;
auto
res
=
custom_options_
.
parse
(
content
,
args
);
if
(
res
.
second
!=
args
.
end
())
{
if
(
res
.
first
!=
pec
::
success
&&
starts_with
(
*
res
.
second
,
"-"
))
if
(
res
.
first
!=
pec
::
success
&&
starts_with
(
*
res
.
second
,
"-"
))
{
return
make_error
(
res
.
first
,
*
res
.
second
);
auto
first
=
args
.
begin
();
first
+=
std
::
distance
(
args
.
c
begin
(),
res
.
second
);
remainder
.
insert
(
remainder
.
end
(),
make_move_iterator
(
first
),
make_move_iterator
(
args
.
end
()));
}
else
{
args
.
erase
(
args
.
begin
(),
res
.
second
);
set_remainder
(
std
::
move
(
args
));
}
}
else
{
cli_helptext_printed
=
get_or
(
content
,
"help"
,
false
)
||
get_or
(
content
,
"long-help"
,
false
);
set_remainder
(
string_list
{});
}
// Generate help text if needed.
if
(
cli_helptext_printed
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment