From fdc3f15bec57b30fae67f65270392ba7a86680b8 Mon Sep 17 00:00:00 2001 From: Gary Scavone Date: Wed, 9 Oct 2013 23:49:32 +0200 Subject: Version 3.0.2 --- tests/Windows/rtaudiotest/StdOpt.cpp | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/Windows/rtaudiotest/StdOpt.cpp (limited to 'tests/Windows/rtaudiotest/StdOpt.cpp') diff --git a/tests/Windows/rtaudiotest/StdOpt.cpp b/tests/Windows/rtaudiotest/StdOpt.cpp new file mode 100644 index 0000000..02c8eea --- /dev/null +++ b/tests/Windows/rtaudiotest/StdOpt.cpp @@ -0,0 +1,91 @@ +/************************************************************************/ +/*! \class CommandLine + \brief Command-line option parser. + + Copyright (c) 2005 Robin Davies. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +/************************************************************************/ + +#include ".\stdopt.h" + +using namespace stdopt; + +CommandLine::CommandLine() +{ +} + +void CommandLine::ProcessCommandLine(int argc, char**argv) +{ + std::vector cmdline; + for (int i = 0; i < argc; ++i) { + cmdline.push_back(argv[i]); + } + ProcessCommandLine(cmdline); +} + +const CommandLine::COptionHandlerBase*CommandLine::GetOptionHandler(const std::string &name) const +{ + // Return excact matches only. + for (size_t i = 0; i < optionHandlers.size(); ++i) + { + if (optionHandlers[i]->getName() == name) { + return (optionHandlers[i]); + } + } + return NULL; +} + +void CommandLine::ProcessCommandLine(const std::vector& cmdline) +{ + for (size_t i = 1; i < cmdline.size(); ++i) + { + if (cmdline[i].length() != 0 && cmdline[i][0] == L'/' || (cmdline[i][0] == '-')) { + std::string arg = cmdline[i].substr(1); + const COptionHandlerBase *pHandler = GetOptionHandler(arg); + if (pHandler == NULL) { + throw CommandLineException(std::string("Unknown option: ") + arg); + } + if (pHandler->HasArgument()) + { + std::string strArg; + if (i+1 < cmdline.size()) { + ++i; + strArg = cmdline[i]; + } + pHandler->Process(strArg.c_str()); + } else { + pHandler->Process(NULL); + } + } else { + args.push_back(cmdline[i]); + } + } +} + +CommandLine::~CommandLine(void) +{ + for (size_t i = 0; i < optionHandlers.size(); ++i) + { + delete optionHandlers[i]; + } + optionHandlers.resize(0); +} -- cgit v1.2.3