Commit 9cab0eca authored by Davis King's avatar Davis King

Updated the examples to use dlib::sa rather than string_cast.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403878
parent 528005a1
...@@ -661,7 +661,7 @@ on_sel_node_evidence_modified ( ...@@ -661,7 +661,7 @@ on_sel_node_evidence_modified (
{ {
// get the numerical value of the new evidence value. Here we are taking // get the numerical value of the new evidence value. Here we are taking
// the string from the text field and casting it to an unsigned long. // the string from the text field and casting it to an unsigned long.
value = string_cast<unsigned long>(trim(sel_node_evidence.text())); value = sa = trim(sel_node_evidence.text());
} }
catch (string_cast_error&) catch (string_cast_error&)
{ {
...@@ -704,7 +704,7 @@ on_sel_node_num_values_modified ( ...@@ -704,7 +704,7 @@ on_sel_node_num_values_modified (
try try
{ {
// get the number of values out of the text field. // get the number of values out of the text field.
num_values = string_cast<unsigned long>(trim(sel_node_num_values.text())); num_values = sa = trim(sel_node_num_values.text());
} }
catch (string_cast_error&) catch (string_cast_error&)
{ {
...@@ -756,7 +756,7 @@ on_cpt_grid_modified(unsigned long row, unsigned long col) ...@@ -756,7 +756,7 @@ on_cpt_grid_modified(unsigned long row, unsigned long col)
try try
{ {
// get the new value out of the table // get the new value out of the table
prob = string_cast<double>(cpt_grid.text(row,col)); prob = sa = cpt_grid.text(row,col);
} }
catch (string_cast_error&) catch (string_cast_error&)
{ {
......
...@@ -84,7 +84,7 @@ int main(int argc, char** argv) ...@@ -84,7 +84,7 @@ int main(int argc, char** argv)
parser.check_incompatible_options("c", "d"); parser.check_incompatible_options("c", "d");
// Here I'm checking that the argument to the l option is an integer in the range 1 to 3. // Here I'm checking that the argument to the l option is an integer in the range 1 to 3.
// That is, it should be convertible to an int by dlib::string_cast<int>() and be either // That is, it should be convertible to an int by dlib::string_assign and be either
// 1, 2, or 3. Note that if you wanted to allow floating point values in the range 1 to // 1, 2, or 3. Note that if you wanted to allow floating point values in the range 1 to
// 3 then you could give a range 1.0 to 3.0 or explicitly supply a type of float or double // 3 then you could give a range 1.0 to 3.0 or explicitly supply a type of float or double
// to the template argument of the check_option_arg_range() function. // to the template argument of the check_option_arg_range() function.
...@@ -119,8 +119,10 @@ int main(int argc, char** argv) ...@@ -119,8 +119,10 @@ int main(int argc, char** argv)
// Figure out what the compression level should be. The default is 2. // Figure out what the compression level should be. The default is 2.
int compression_level = 2; int compression_level = 2;
// If the user supplied the -l option then use whatever value they gave for the level. // 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")) if (parser.option("l"))
compression_level = string_cast<int>(parser.option("l").argument()); compression_level = sa = parser.option("l").argument();
......
...@@ -99,11 +99,13 @@ int main() ...@@ -99,11 +99,13 @@ 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_cast function to easily convert fields // 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 // into non-string types. For example, the config file has an integer id
// field that could be converted into an int like so: // field that could be converted into an int like so:
int id = string_cast<int>(cr.block("user2")["id"]); int id1 = sa = cr.block("user1")["id"];
cout << "user2's id is " << id << endl; int id2 = sa = cr.block("user2")["id"];
cout << "user1's id is " << id1 << endl;
cout << "user2's id is " << id2 << 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