libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


command_line.h

00001 //---------------------------------------------------------------------
00002 //  Algorithmic Conjurings @ http://www.coyotegulch.com
00003 //
00004 //  command_line.h (libcoyotl)
00005 //---------------------------------------------------------------------
00006 //
00007 //  Copyright 1990-2005 Scott Robert Ladd
00008 //
00009 //  This program is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //  
00014 //  This program is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //  GNU General Public License for more details.
00018 //  
00019 //  You should have received a copy of the GNU General Public License
00020 //  along with this program; if not, write to the
00021 //      Free Software Foundation, Inc.
00022 //      59 Temple Place - Suite 330
00023 //      Boston, MA 02111-1307, USA.
00024 //
00025 //-----------------------------------------------------------------------
00026 //
00027 //  For more information on this software package, please visit
00028 //  Scott's web site, Coyote Gulch Productions, at:
00029 //
00030 //      http://www.coyotegulch.com
00031 //  
00032 //-----------------------------------------------------------------------
00033 
00034 #if !defined(LIBCOYOTL_COMMAND_LINE_H)
00035 #define LIBCOYOTL_COMMAND_LINE_H
00036 
00037 // Standard C++
00038 #include <string>
00039 #include <vector>
00040 #include <set>
00041 
00042 namespace libcoyotl
00043 {
00044     using std::string;
00045     using std::vector;
00046     using std::set;
00047 
00048     // a very simple command-line parser
00049     class command_line
00050     {
00051     public:
00052         struct option
00053         {
00054             string m_name;
00055             string m_value;
00056             
00057             option(const string & a_name)
00058               : m_name(a_name), m_value("")
00059             {
00060                 // nada
00061             }
00062         };
00063         
00064         // create a command line parser
00065         command_line(int argc, char * argv[], const set<string> & bool_opts);
00066         
00067         // retrieve a list of options
00068         const vector<option> & get_options() const
00069         {
00070             return m_options;
00071         }
00072         
00073         // retrieve a list of input values
00074         const vector<string> & get_inputs() const
00075         {
00076             return m_inputs;
00077         }
00078         
00079     private:
00080         // the set of option names, with associated values
00081         vector<option> m_options;
00082         
00083         // the set of inputs -- command line arguments not associated with an option
00084         vector<string> m_inputs;
00085         
00086         // a list of boolean options, which have no values
00087         const std::set<std::string> & m_bool_opts;
00088     };
00089 
00090 }
00091 
00092 #endif

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.