Commit e7261af0 authored by Davis King's avatar Davis King

updated examples to use get_option()

parent a23adf88
...@@ -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();
......
...@@ -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 could be converted into an int like so: // field that can 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)
......
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