cmdline.h

Go to the documentation of this file.
00001 /*
00002  * cmdline.h
00003  *
00004  * Copyright 2004  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Abstractions for dealing with the command line
00032  */
00033 
00034 #ifndef WAVEPACKET_CMDLINE_H__
00035 #define WAVEPACKET_CMDLINE_H__
00036 
00037 // includes --------------------------------------------------------------------
00038 #include "common/common.h"
00039 
00040 #include "threadsafe/smart_ptr.h"
00041 
00042 
00043 /// \ingroup general
00044 /*@{*/
00045 
00046 ////////////////////////////////////////////////////////////////////////////////
00047 ///
00048 /// \defgroup cmdline Command Line API
00049 ///
00050 /// This is an older class, and it should probably be deprecated in favor of
00051 /// better command-line parsing objects out there.  But for whatever reason
00052 /// I've been using this one for most projects.
00053 ///
00054 ////////////////////////////////////////////////////////////////////////////////
00055 /*@{*/
00056 
00057 
00058 ////////////////////////////////////////////////////////////////////////////////
00059 ///
00060 /// Command Line object
00061 ///
00062 /// Create one of these from the command line strings, and then query it about
00063 /// options you care about.
00064 ///
00065 /// Example:
00066 /// \code
00067 ///     int main(int argc, char * argv[]) {
00068 ///             smart_ptr<CommandLine> cmdline = CommandLine::create(argc, argv);
00069 ///             const char * file = getSingleKeyValue(cmdline, "file", false);
00070 ///             if (!file) {
00071 ///                     std::cout << "recommended usage: ";
00072 ///                     std::cout << "my_program --file <path>";
00073 ///             }
00074 ///             return 0;
00075 ///     }
00076 /// \endcode
00077 ///
00078 ////////////////////////////////////////////////////////////////////////////////
00079 class CommandLine {
00080 public:
00081         // virtual destructor --------------------------------------------------
00082         virtual ~CommandLine(void) throw();
00083 
00084         // CommandLine class interface methods ---------------------------------
00085         virtual void getKeys(OUT VecString& keys) throw() = 0;
00086         virtual bool getValues(IN const char * key,
00087                                 OUT VecString& values) throw() = 0;
00088 
00089         // static class methods (factories) ------------------------------------
00090         static smart_ptr<CommandLine> create(IN int argc,
00091                                 IN const char * argv[]) throw();
00092 };
00093 
00094 
00095 const char * getSingleKeyValue(IN CommandLine * cmd, IN const char * key,
00096                         bool is_required,
00097                         const char * description = NULL) throw();
00098 
00099 
00100 /*@}*/  // end of documentation block
00101 
00102 #endif  // WAVEPACKET_CMDLINE_H__
00103