From 80362da641a9d84bfd2ec5586a117e036846bcae Mon Sep 17 00:00:00 2001 From: Zdenek Nemec Date: Wed, 26 Jun 2013 11:02:14 +0200 Subject: [PATCH 1/8] fix parse_check() argv's constantness --- cmdline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdline.h b/cmdline.h index de9eaf7..2e14968 100644 --- a/cmdline.h +++ b/cmdline.h @@ -536,7 +536,7 @@ class parser{ check(args.size(), parse(args)); } - void parse_check(int argc, char *argv[]){ + void parse_check(int argc, const char *argv[]){ if (!options.count("help")) add("help", '?', "print this message"); check(argc, parse(argc, argv)); From 3d6b55e2964719288c1135b2e00b79f4e47f8a07 Mon Sep 17 00:00:00 2001 From: Zdenek Nemec Date: Wed, 26 Jun 2013 11:03:25 +0200 Subject: [PATCH 2/8] add explicit cast from size_type to int --- cmdline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdline.h b/cmdline.h index 2e14968..7e73f38 100644 --- a/cmdline.h +++ b/cmdline.h @@ -533,7 +533,7 @@ class parser{ void parse_check(const std::vector &args){ if (!options.count("help")) add("help", '?', "print this message"); - check(args.size(), parse(args)); + check(static_cast(args.size()), parse(args)); } void parse_check(int argc, const char *argv[]){ From 5600583b5e1d5c6e93fc3964dd4a097565f68403 Mon Sep 17 00:00:00 2001 From: Z Date: Thu, 4 Jul 2013 11:07:19 +0200 Subject: [PATCH 3/8] Do not use demangle on Windows, fix unused variable --- cmdline.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmdline.h b/cmdline.h index 7e73f38..a84dd36 100644 --- a/cmdline.h +++ b/cmdline.h @@ -36,7 +36,11 @@ #include #include #include + +#if defined(__clang__) || defined(__GNUC__) #include +#endif + #include namespace cmdline{ @@ -104,11 +108,15 @@ Target lexical_cast(const Source &arg) static inline std::string demangle(const std::string &name) { +#if defined(__clang__) || defined(__GNUC__) int status=0; char *p=abi::__cxa_demangle(name.c_str(), 0, 0, &status); std::string ret(p); free(p); return ret; +#else + return name; +#endif } template @@ -721,7 +729,7 @@ class parser{ actual=read(value); has=true; } - catch(const std::exception &e){ + catch(const std::exception &){ return false; } return true; From 44dca6325c3111b38e9d9416f6663062ca95e0dd Mon Sep 17 00:00:00 2001 From: y-sasaki-nuem Date: Sat, 31 Jan 2015 21:57:21 +0900 Subject: [PATCH 4/8] Fixed README.rst && Added support of Visual Studio * Add syntax highlighting * Fixed to use boost::units::detail::demangle() when the compiler is VC --- README.rst | 8 ++++---- cmdline.h | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 319c9cc..aee0842 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ Normal usage This is an example of simple usage. -:: +.. sourcecode:: cpp // include cmdline.h #include "cmdline.h" @@ -143,16 +143,16 @@ Rest of arguments are referenced by rest() method. It returns vector of string. Usualy, they are used to specify filenames, and so on. -:: +.. sourcecode:: cpp for (int i = 0; i < a.rest().size(); i++) - cout << a.rest()[i] << endl\; + cout << a.rest()[i] << endl; - footer footer() method is add a footer text of usage. -:: +.. sourcecode:: cpp ... a.footer("filename ..."); diff --git a/cmdline.h b/cmdline.h index de9eaf7..ed1da66 100644 --- a/cmdline.h +++ b/cmdline.h @@ -36,8 +36,17 @@ #include #include #include -#include #include +#if defined(_MSC_VER) +#include +#else +#include +#endif + +#if defined(_MSC_VER) +#undef max +#undef min +#endif namespace cmdline{ @@ -102,6 +111,9 @@ Target lexical_cast(const Source &arg) return lexical_cast_t::value>::cast(arg); } +#if defined(_MSC_VER) +using boost::units::detail::demangle; +#else static inline std::string demangle(const std::string &name) { int status=0; @@ -110,6 +122,7 @@ static inline std::string demangle(const std::string &name) free(p); return ret; } +#endif template std::string readable_typename() From 3fa83039a135b902f7b56017e77132e50cb1fb5c Mon Sep 17 00:00:00 2001 From: y-sasaki-nuem Date: Sat, 31 Jan 2015 22:12:15 +0900 Subject: [PATCH 5/8] Remove redundant descriptions && fix #9 --- README.rst | 2 +- cmdline.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index aee0842..562f7e5 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,7 @@ This is an example of simple usage. // 1st argument is long name // 2nd argument is short name (no short name if '\0' specified) // 3rd argument is description - // 4th argument is mandatory (optional. default is false) + // 4th argument is mandatory (optional. default is true) // 5th argument is default value (optional. it used when mandatory is false) a.add("host", 'h', "host name", true, ""); diff --git a/cmdline.h b/cmdline.h index ed1da66..7bf9dad 100644 --- a/cmdline.h +++ b/cmdline.h @@ -36,16 +36,15 @@ #include #include #include -#include #if defined(_MSC_VER) #include #else #include #endif +#include #if defined(_MSC_VER) #undef max -#undef min #endif namespace cmdline{ From e5b7fc1b83a05c07cf678ee48176f1e450cee6da Mon Sep 17 00:00:00 2001 From: y-sasaki-nuem Date: Sat, 31 Jan 2015 22:37:05 +0900 Subject: [PATCH 6/8] Remove the dependency of boost In boost/units/detail/utility.hpp, demangle() returns the argument directly. Therefore, boost::units::detail::demangle() in my previous code was unnecessary --- cmdline.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmdline.h b/cmdline.h index 7bf9dad..2f3e0fb 100644 --- a/cmdline.h +++ b/cmdline.h @@ -36,9 +36,7 @@ #include #include #include -#if defined(_MSC_VER) -#include -#else +#if !defined(_MSC_VER) #include #endif #include @@ -111,7 +109,7 @@ Target lexical_cast(const Source &arg) } #if defined(_MSC_VER) -using boost::units::detail::demangle; +static inline std::string demangle(const std::string &name) { return name; } #else static inline std::string demangle(const std::string &name) { From 39e2c25635ede4a94d6713ecdd3b1e6292da1c3a Mon Sep 17 00:00:00 2001 From: y-sasaki-nuem Date: Sat, 31 Jan 2015 22:46:24 +0900 Subject: [PATCH 7/8] remove undefinition of `max` --- cmdline.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmdline.h b/cmdline.h index 2f3e0fb..879241b 100644 --- a/cmdline.h +++ b/cmdline.h @@ -41,10 +41,6 @@ #endif #include -#if defined(_MSC_VER) -#undef max -#endif - namespace cmdline{ namespace detail{ From 7319bd54a6c530e49e157002b23a1ce6ac820a8e Mon Sep 17 00:00:00 2001 From: Yusuke Sasaki Date: Thu, 1 Oct 2015 22:54:16 +0900 Subject: [PATCH 8/8] Use UnDecorateSymbolName() on MSVC --- cmdline.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmdline.h b/cmdline.h index 879241b..76c15b7 100644 --- a/cmdline.h +++ b/cmdline.h @@ -36,7 +36,12 @@ #include #include #include -#if !defined(_MSC_VER) +#if defined(_MSC_VER) +#include +#include +#undef max +#pragma comment(lib, "dbghelp.lib") +#else #include #endif #include @@ -104,18 +109,21 @@ Target lexical_cast(const Source &arg) return lexical_cast_t::value>::cast(arg); } -#if defined(_MSC_VER) -static inline std::string demangle(const std::string &name) { return name; } -#else static inline std::string demangle(const std::string &name) { +#if defined(_MSC_VER) + TCHAR ret[256]; + std::memset(ret, 0, 256); + ::UnDecorateSymbolName(name.c_str(), ret, 256, 0); + return ret; +#else int status=0; char *p=abi::__cxa_demangle(name.c_str(), 0, 0, &status); std::string ret(p); free(p); return ret; -} #endif +} template std::string readable_typename()