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
c8b9165f
Commit
c8b9165f
authored
Jun 17, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use load_file instead of reading file manually
parent
23cb4188
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
examples/config/read-json.cpp
examples/config/read-json.cpp
+7
-12
No files found.
examples/config/read-json.cpp
View file @
c8b9165f
...
@@ -48,22 +48,17 @@ int caf_main(caf::actor_system& sys) {
...
@@ -48,22 +48,17 @@ int caf_main(caf::actor_system& sys) {
// Get file path from config (positional argument).
// Get file path from config (positional argument).
auto
&
cfg
=
sys
.
config
();
auto
&
cfg
=
sys
.
config
();
if
(
cfg
.
remainder
.
size
()
!=
1
)
{
if
(
cfg
.
remainder
.
size
()
!=
1
)
{
std
::
cerr
<<
"*** expected one positional argument: path to a JSON file
\n
"
;
std
::
cerr
<<
"*** expected one positional argument: path to a JSON file
\n
"
<<
"
\n\n
Note: expected a JSON list of user objects. For example:
\n
"
<<
example_input
<<
'\n'
;
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
auto
&
file_path
=
cfg
.
remainder
[
0
];
auto
&
file_path
=
cfg
.
remainder
[
0
];
// Read file into a string.
// Read JSON-formatted file.
std
::
ifstream
input
{
file_path
};
if
(
!
input
)
{
std
::
cerr
<<
"*** unable to open input file '"
<<
file_path
<<
"'
\n
"
;
return
EXIT_FAILURE
;
}
std
::
string
json
{
std
::
istreambuf_iterator
<
char
>
{
input
},
std
::
istreambuf_iterator
<
char
>
{}};
// Parse the JSON-formatted text.
caf
::
json_reader
reader
;
caf
::
json_reader
reader
;
if
(
!
reader
.
load
(
json
))
{
if
(
!
reader
.
load
_file
(
file_path
))
{
std
::
cerr
<<
"*** failed to parse JSON
input
: "
std
::
cerr
<<
"*** failed to parse JSON
file
: "
<<
to_string
(
reader
.
get_error
())
<<
'\n'
;
<<
to_string
(
reader
.
get_error
())
<<
'\n'
;
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
...
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