cmd_line.cpp

00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: cmd_line.cpp,v 1.2 2005/01/30 05:11:40 gabest Exp $ $Name:  $
00004 *
00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006 *
00007 * The contents of this file are subject to the Mozilla Public License
00008 * Version 1.1 (the "License"); you may not use this file except in compliance
00009 * with the License. You may obtain a copy of the License at
00010 * http://www.mozilla.org/MPL/
00011 *
00012 * Software distributed under the License is distributed on an "AS IS" basis,
00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
00014 * the specific language governing rights and limitations under the License.
00015 *
00016 * The Original Code is BBC Research and Development code.
00017 *
00018 * The Initial Developer of the Original Code is the British Broadcasting
00019 * Corporation.
00020 * Portions created by the Initial Developer are Copyright (C) 2004.
00021 * All Rights Reserved.
00022 *
00023 * Contributor(s): Scott R Ladd (Original Author), Thomas Davies
00024 *
00025 * Alternatively, the contents of this file may be used under the terms of
00026 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00027 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00028 * the GPL or the LGPL are applicable instead of those above. If you wish to
00029 * allow use of your version of this file only under the terms of the either
00030 * the GPL or LGPL and not to allow others to use your version of this file
00031 * under the MPL, indicate your decision by deleting the provisions above
00032 * and replace them with the notice and other provisions required by the GPL
00033 * or LGPL. If you do not delete the provisions above, a recipient may use
00034 * your version of this file under the terms of any one of the MPL, the GPL
00035 * or the LGPL.
00036 * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "cmd_line.h"
00039 using namespace dirac;
00040 
00041 using namespace std;
00042 
00043 CommandLine::CommandLine(int argc, char * argv[], const set<string> & bool_opts)
00044   : m_options(),
00045     m_inputs(),
00046     m_bool_opts(bool_opts)
00047 {
00048     bool option_active = false;
00049     vector<option>::iterator active_option;
00050 
00051     for (int i = 1; i < argc; ++i)
00052     {
00053         // is it an option?
00054         if ((strlen(argv[i]) > 1) && (argv[i][0] == '-'))
00055         {
00056             // store new key
00057             string opt_key = string(&argv[i][1]);
00058             m_options.push_back(option(opt_key));
00059             
00060             // active option is now last in list
00061             active_option = m_options.end();
00062             --active_option;
00063             
00064             // check option list to see if we're looking for an argument
00065             option_active = (m_bool_opts.find(opt_key) == m_bool_opts.end());
00066         }
00067         else
00068         {
00069             if (option_active)
00070                 active_option->m_value = string(argv[i]);
00071             else
00072                 m_inputs.push_back(string(argv[i]));
00073 
00074             option_active = false;
00075         }
00076     }
00077 }

Generated on Tue Dec 13 14:47:12 2005 for guliverkli by  doxygen 1.4.5