Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
e7261af0
Commit
e7261af0
authored
Feb 03, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated examples to use get_option()
parent
a23adf88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
compress_stream_ex.cpp
examples/compress_stream_ex.cpp
+3
-7
config_reader_ex.cpp
examples/config_reader_ex.cpp
+10
-6
No files found.
examples/compress_stream_ex.cpp
View file @
e7261af0
...
...
@@ -116,13 +116,9 @@ int main(int argc, char** argv)
const
clp
::
option_type
&
option_in
=
parser
.
option
(
"in"
);
const
clp
::
option_type
&
option_out
=
parser
.
option
(
"out"
);
// Figure out what the compression level should be. The default is 2.
int
compression_level
=
2
;
// If the user supplied the -l option then use whatever value they gave for the level.
// Note that we use the string_assign object, sa, to convert the string returned
// by argument() to an int.
if
(
parser
.
option
(
"l"
))
compression_level
=
sa
=
parser
.
option
(
"l"
).
argument
();
// Figure out what the compression level should be. If the user didn't supply
// this command line option then a value of 2 will be used.
int
compression_level
=
get_option
(
parser
,
"l"
,
2
);
...
...
examples/config_reader_ex.cpp
View file @
e7261af0
...
...
@@ -10,7 +10,6 @@
#include "dlib/config_reader.h"
#include "dlib/string.h"
#include <iostream>
#include <fstream>
#include <vector>
...
...
@@ -96,13 +95,18 @@ int main()
cout
<<
cr
.
block
(
"user1"
).
block
(
"details"
)[
"editor"
]
<<
endl
;
// Note that you can use
the string_assign object, sa, to easily convert fields
//
into
non-string types. For example, the config file has an integer id
// field that c
ould
be converted into an int like so:
int
id1
=
sa
=
cr
.
block
(
"user1"
)[
"id"
];
int
id2
=
sa
=
cr
.
block
(
"user2"
)[
"id"
];
// Note that you can use
get_option() to easily convert fields into
// non-string types. For example, the config file has an integer id
// field that c
an
be converted into an int like so:
int
id1
=
get_option
(
cr
,
"user1.id"
,
0
);
int
id2
=
get_option
(
cr
,
"user2.id"
,
0
);
cout
<<
"user1's id is "
<<
id1
<<
endl
;
cout
<<
"user2's id is "
<<
id2
<<
endl
;
// The third argument to get_option() is the default value returned if
// the config reader doesn't contain a corresponding entry. So for
// example, the following prints 321 since there is no user3.
int
id3
=
get_option
(
cr
,
"user3.id"
,
321
);
cout
<<
"user3's id is "
<<
id3
<<
endl
;
}
catch
(
exception
&
e
)
...
...
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