Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
e7261af0
"llama/git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "548a9f56a6315316481a9a901f77922cb77e0f68"
Commit
e7261af0
authored
Feb 03, 2012
by
Davis King
Browse files
updated examples to use get_option()
parent
a23adf88
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
examples/compress_stream_ex.cpp
examples/compress_stream_ex.cpp
+3
-7
examples/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)
...
@@ -116,13 +116,9 @@ int main(int argc, char** argv)
const
clp
::
option_type
&
option_in
=
parser
.
option
(
"in"
);
const
clp
::
option_type
&
option_in
=
parser
.
option
(
"in"
);
const
clp
::
option_type
&
option_out
=
parser
.
option
(
"out"
);
const
clp
::
option_type
&
option_out
=
parser
.
option
(
"out"
);
// Figure out what the compression level should be. The default is 2.
// Figure out what the compression level should be. If the user didn't supply
int
compression_level
=
2
;
// this command line option then a value of 2 will be used.
// If the user supplied the -l option then use whatever value they gave for the level.
int
compression_level
=
get_option
(
parser
,
"l"
,
2
);
// 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
();
...
...
examples/config_reader_ex.cpp
View file @
e7261af0
...
@@ -10,7 +10,6 @@
...
@@ -10,7 +10,6 @@
#include "dlib/config_reader.h"
#include "dlib/config_reader.h"
#include "dlib/string.h"
#include <iostream>
#include <iostream>
#include <fstream>
#include <fstream>
#include <vector>
#include <vector>
...
@@ -96,13 +95,18 @@ int main()
...
@@ -96,13 +95,18 @@ int main()
cout
<<
cr
.
block
(
"user1"
).
block
(
"details"
)[
"editor"
]
<<
endl
;
cout
<<
cr
.
block
(
"user1"
).
block
(
"details"
)[
"editor"
]
<<
endl
;
// Note that you can use
the string_assign object, sa,
to easily convert fields
// Note that you can use
get_option()
to easily convert fields
into
//
into
non-string types. For example, the config file has an integer id
// non-string types. For example, the config file has an integer id
// field that c
ould
be converted into an int like so:
// field that c
an
be converted into an int like so:
int
id1
=
sa
=
cr
.
block
(
"user1"
)[
"id"
];
int
id1
=
get_option
(
cr
,
"user1.id"
,
0
);
int
id2
=
sa
=
cr
.
block
(
"user2"
)[
"id"
];
int
id2
=
get_option
(
cr
,
"user2.id"
,
0
);
cout
<<
"user1's id is "
<<
id1
<<
endl
;
cout
<<
"user1's id is "
<<
id1
<<
endl
;
cout
<<
"user2's id is "
<<
id2
<<
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
)
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