diff --git a/README.rst b/README.rst index 319c9cc..562f7e5 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" @@ -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, ""); @@ -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..a26cbf5 100644 --- a/cmdline.h +++ b/cmdline.h @@ -36,8 +36,16 @@ #include #include #include -#include #include +#if defined(_MSC_VER) +#define CMDLINE_DEMANGLE_WINDOWS +#include +#include +#undef max +#pragma comment(lib, "dbghelp.lib") +#elif defined(__clang__) || defined(__GNUC__) +#include +#endif namespace cmdline{ @@ -51,7 +59,7 @@ class lexical_cast_t{ std::stringstream ss; if (!(ss<>ret && ss.eof())) throw std::bad_cast(); - + return ret; } }; @@ -61,7 +69,7 @@ class lexical_cast_t{ public: static Target cast(const Source &arg){ return arg; - } + } }; template @@ -104,11 +112,18 @@ Target lexical_cast(const Source &arg) static inline std::string demangle(const std::string &name) { +#if defined(CMDLINE_DEMANGLE_WINDOWS) + 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 @@ -533,10 +548,10 @@ 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, char *argv[]){ + void parse_check(int argc, const char *argv[]){ if (!options.count("help")) add("help", '?', "print this message"); check(argc, parse(argc, argv)); @@ -560,7 +575,7 @@ class parser{ if (ordered[i]->must()) oss<short_description()<<" "; } - + oss<<"[options] ... "<