diff options
| author | Gary Scavone <gary@music.mcgill.ca> | 2013-10-09 23:49:32 +0200 |
|---|---|---|
| committer | Stephen Sinclair <sinclair@music.mcgill.ca> | 2013-10-10 01:15:42 +0200 |
| commit | fdc3f15bec57b30fae67f65270392ba7a86680b8 (patch) | |
| tree | c40a558b21ec18df4a4fd2613ead8f54dd3c4156 /tests/Windows/rtaudiotest/StdOpt.cpp | |
| parent | 2b55be781872498a3b4c6cde60be4c2f69ec7eb4 (diff) | |
Version 3.0.2
Diffstat (limited to 'tests/Windows/rtaudiotest/StdOpt.cpp')
| -rw-r--r-- | tests/Windows/rtaudiotest/StdOpt.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
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<std::string> 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<std::string>& 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);
+}
|
