From 203a9acdbc7ea130aabb05e98d35b0033fa552d1 Mon Sep 17 00:00:00 2001 From: pxli168 Date: Tue, 31 Dec 2013 12:53:31 +0800 Subject: [PATCH 1/3] Add support to bool type Add the bool support to the get function --- modules/core/src/command_line_parser.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 7a0284f75a..8b7fcad6b3 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -41,6 +41,8 @@ static String get_type_name(int type) { if( type == Param::INT ) return "int"; + if( type == Param::BOOLEAN ) + return "bool"; if( type == Param::UNSIGNED_INT ) return "unsigned"; if( type == Param::UINT64 ) @@ -59,6 +61,13 @@ static void from_str(const String& str, int type, void* dst) std::stringstream ss(str.c_str()); if( type == Param::INT ) ss >> *(int*)dst; + else if( type == Param::BOOLEAN ) + { + std::string temp; + ss >> temp; + if( !temp.compare("true") ) *(bool*)dst = true; + else *(bool*)dst = false; + } else if( type == Param::UNSIGNED_INT ) ss >> *(unsigned*)dst; else if( type == Param::UINT64 ) From 70d462b3526027ec1f27dbb054bf6c3d8336a923 Mon Sep 17 00:00:00 2001 From: pxli168 Date: Mon, 17 Feb 2014 10:21:18 +0800 Subject: [PATCH 2/3] Simplify the code Simplify the code as @SpecLad suggested. --- modules/core/src/command_line_parser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 8b7fcad6b3..0fa3304889 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -65,8 +65,7 @@ static void from_str(const String& str, int type, void* dst) { std::string temp; ss >> temp; - if( !temp.compare("true") ) *(bool*)dst = true; - else *(bool*)dst = false; + *(bool*) = temp == "true"; } else if( type == Param::UNSIGNED_INT ) ss >> *(unsigned*)dst; From 44ecb727c559c3545203919292901405197fe0b4 Mon Sep 17 00:00:00 2001 From: pxli168 Date: Tue, 18 Feb 2014 10:13:30 +0800 Subject: [PATCH 3/3] Change again. Opps. --- modules/core/src/command_line_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 0fa3304889..2818e75ac8 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -65,7 +65,7 @@ static void from_str(const String& str, int type, void* dst) { std::string temp; ss >> temp; - *(bool*) = temp == "true"; + *(bool*) dst = temp == "true"; } else if( type == Param::UNSIGNED_INT ) ss >> *(unsigned*)dst;