00001 /* 00002 Copyright 2008 Larry Gritz and the other authors and contributors. 00003 All Rights Reserved. 00004 Based on BSD-licensed software Copyright 2004 NVIDIA Corp. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are 00008 met: 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 * Redistributions in binary form must reproduce the above copyright 00012 notice, this list of conditions and the following disclaimer in the 00013 documentation and/or other materials provided with the distribution. 00014 * Neither the name of the software's owners nor the names of its 00015 contributors may be used to endorse or promote products derived from 00016 this software without specific prior written permission. 00017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00018 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00019 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00020 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00021 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00022 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00024 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00025 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 00029 (This is the Modified BSD License) 00030 */ 00031 00032 00035 00036 00037 #ifndef OPENIMAGEIO_ARGPARSE_H 00038 #define OPENIMAGEIO_ARGPARSE_H 00039 00040 #include <vector> 00041 00042 #include "export.h" 00043 00044 #ifndef OPENIMAGEIO_PRINTF_ARGS /* See comments in strutil.h */ 00045 # ifndef __GNUC__ 00046 # define __attribute__(x) 00047 # endif 00048 # define OPENIMAGEIO_PRINTF_ARGS(fmtarg_pos, vararg_pos) \ 00049 __attribute__ ((format (printf, fmtarg_pos, vararg_pos) )) 00050 #endif 00051 00052 #ifdef OPENIMAGEIO_NAMESPACE 00053 namespace OPENIMAGEIO_NAMESPACE { 00054 #endif 00055 00056 // namespace I have no idea... { 00057 00058 00059 class ArgOption; // Forward declaration 00060 00061 00062 00129 00130 00131 class DLLPUBLIC ArgParse { 00132 public: 00133 ArgParse (int argc=0, const char **argv=NULL); 00134 ~ArgParse (); 00135 00143 int options (const char *intro, ...); 00144 00147 int parse (int argc, const char **argv); 00148 00152 std::string geterror () const { 00153 std::string e = errmessage; 00154 errmessage.clear (); 00155 return e; 00156 } 00159 std::string error_message () const { return geterror (); } 00160 00164 void usage () const; 00165 00168 std::string command_line () const; 00169 00170 private: 00171 int argc; // a copy of the command line argc 00172 const char **argv; // a copy of the command line argv 00173 mutable std::string errmessage; // error message 00174 ArgOption *global; // option for extra cmd line arguments 00175 std::string intro; 00176 std::vector<ArgOption *> option; 00177 00178 ArgOption *find_option(const char *name); 00179 void error (const char *format, ...) OPENIMAGEIO_PRINTF_ARGS(2,3); 00180 int found (const char *option); // number of times option was parsed 00181 }; 00182 00183 00184 00185 // }; // namespace ??? 00186 00187 #ifdef OPENIMAGEIO_NAMESPACE 00188 }; // end namespace OPENIMAGEIO_NAMESPACE 00189 using namespace OPENIMAGEIO_NAMESPACE; 00190 #endif 00191 00192 #endif // OPENIMAGEIO_ARGPARSE_H