00001 /** 00002 * @file basis/CmdLine.h 00003 * @brief Manages command line definition and parsing of arguments. 00004 * 00005 * Copyright (c) 2011 University of Pennsylvania. All rights reserved.<br /> 00006 * See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file. 00007 * 00008 * Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00009 * 00010 * @ingroup CxxCmdLine 00011 */ 00012 00013 #pragma once 00014 #ifndef _SBIA_BASIS_CMDLINE_H 00015 #define _SBIA_BASIS_CMDLINE_H 00016 00017 00018 #include <sbia/tclap/CmdLine.h> // TCLAP implementation 00019 #include <sbia/basis/CmdArgs.h> // commonly used arguments 00020 00021 00022 namespace sbia 00023 { 00024 00025 namespace basis 00026 { 00027 00028 00029 /** 00030 * @brief Manages command line definition and parsing of arguments. 00031 * 00032 * See @ref CxxCmdLineParsing for an example use of this class. 00033 * 00034 * Copyright (c) 2011 University of Pennsylvania. All rights reserved.<br /> 00035 * See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file. 00036 * 00037 * @ingroup CxxCmdLine 00038 */ 00039 class CmdLine : public TCLAP::CmdLine 00040 { 00041 // ----------------------------------------------------------------------- 00042 // construction / destruction 00043 public: 00044 00045 /** 00046 * @brief Constructor. 00047 * 00048 * @param [in] name Program name. Should be a constant string which 00049 * helps to identify the program, not the name of 00050 * the executable as determined at runtime. 00051 * @param [in] project Name of project this program belongs to. 00052 * @param [in] description Program description. 00053 * @param [in] example Usage example. 00054 * @param [in] version Program version. 00055 * @param [in] copyright Copyright notice. 00056 * @param [in] license License information. 00057 * @param [in] contact Contact information. 00058 * @param [in] stdargs Enable/disable handling of standard arguments. 00059 */ 00060 CmdLine(const std::string& name, 00061 const std::string& project, 00062 const std::string& description, 00063 const std::string& example, 00064 const std::string& version, 00065 const std::string& copyright = 00066 "Copyright (c) University of Pennsylvania." 00067 " All rights reserved.", 00068 const std::string& license = 00069 "See https://www.cbica.upenn.edu/sbia/software/license.html" 00070 " or COPYING file.", 00071 const std::string& contact = 00072 "SBIA Group <sbia-software at uphs.upenn.edu>", 00073 bool stdargs = true); 00074 00075 /** 00076 * @brief Constructor. 00077 * 00078 * @param [in] name Program name. Should be a constant string which 00079 * helps to identify the program, not the name of 00080 * the executable as determined at runtime. 00081 * @param [in] project Name of project this program belongs to. 00082 * @param [in] description Program description. 00083 * @param [in] examples Usage examples. 00084 * @param [in] version Program version. 00085 * @param [in] copyright Copyright notice. 00086 * @param [in] license License information. 00087 * @param [in] contact Contact information. 00088 * @param [in] stdargs Enable/disable handling of standard arguments. 00089 */ 00090 CmdLine(const std::string& name, 00091 const std::string& project, 00092 const std::string& description, 00093 const std::vector<std::string>& examples, 00094 const std::string& version, 00095 const std::string& copyright = 00096 "Copyright (c) University of Pennsylvania." 00097 " All rights reserved.", 00098 const std::string& license = 00099 "See https://www.cbica.upenn.edu/sbia/software/license.html" 00100 " or COPYING file.", 00101 const std::string& contact = 00102 "SBIA Group <sbia-software at uphs.upenn.edu>", 00103 bool stdargs = true); 00104 00105 /** 00106 * @brief Destructor. 00107 */ 00108 virtual ~CmdLine() { } 00109 00110 // ----------------------------------------------------------------------- 00111 // command arguments 00112 public: 00113 00114 /** 00115 * @brief Adds an argument to the list of arguments to be parsed. 00116 * 00117 * @param [in] a Argument to be added. 00118 */ 00119 void add(Arg& a); 00120 00121 /** 00122 * @brief An alternative add. Functionally identical. 00123 * 00124 * @param [in] a Argument to be added. 00125 */ 00126 void add(Arg* a); 00127 00128 /** 00129 * @brief Add two Args that will be xor'd. 00130 * 00131 * If this method is used, add does not need to be called. 00132 * 00133 * @param [in] a Argument to be added and xor'd. 00134 * @param [in] b Argument to be added and xor'd. 00135 */ 00136 void xorAdd(Arg& a, Arg& b); 00137 00138 /** 00139 * @brief Add a list of arguments that will be xor'd. 00140 * 00141 * If this method is used, add does not need to be called. 00142 * 00143 * @param [in] xors List of Args to be added and xor'd. 00144 */ 00145 void xorAdd(std::vector<Arg*>& xors); 00146 00147 // ----------------------------------------------------------------------- 00148 // parse command-line arguments 00149 public: 00150 00151 /** 00152 * @brief Parses the command line. 00153 * 00154 * @param [in] argc Number of arguments. 00155 * @param [in] argv Array of arguments. 00156 */ 00157 void parse(int argc, const char* const* argv); 00158 00159 /** 00160 * @brief Parses the command line. 00161 * 00162 * @param [in] args A vector of strings representing the args. 00163 * args[0] is still the program name. 00164 */ 00165 void parse(std::vector<std::string>& args); 00166 00167 // ----------------------------------------------------------------------- 00168 // accessors 00169 public: 00170 00171 /** 00172 * @brief Get name of program. 00173 * 00174 * @returns Name of program this command-line object belongs to. 00175 */ 00176 std::string& getProgramName() { return _name; } 00177 00178 /** 00179 * @brief Get name of project the program belongs to. 00180 * 00181 * @returns Name of project this program belongs to. 00182 */ 00183 std::string& getProjectName() { return _project; } 00184 00185 /** 00186 * @brief Get program description. 00187 * 00188 * @returns Description of program this command-line object belongs to. 00189 */ 00190 std::string& getDescription() { return _message; } 00191 00192 /** 00193 * @brief Get usage example. 00194 * 00195 * @returns Example command-line usage. 00196 */ 00197 std::vector<std::string>& getExamples() { return _examples; } 00198 00199 /** 00200 * @brief Get copyright notice. 00201 * 00202 * @return Copyright information of program. 00203 */ 00204 std::string& getCopyright() { return _copyright; } 00205 00206 /** 00207 * @brief Get license information. 00208 * 00209 * @returns License information of program. 00210 */ 00211 std::string& getLicense() { return _license; } 00212 00213 /** 00214 * @brief Get contact information. 00215 * 00216 * @returns Contact information. 00217 */ 00218 std::string& getContact() { return _contact; } 00219 00220 // ----------------------------------------------------------------------- 00221 // helpers 00222 protected: 00223 00224 /** 00225 * @brief Set up command-line object. 00226 */ 00227 void setup(bool stdargs); 00228 00229 // ----------------------------------------------------------------------- 00230 // unsupported 00231 private: 00232 00233 CmdLine(const CmdLine&); ///< Intentionally not implemented. 00234 CmdLine& operator=(const CmdLine&); ///< Intentionally not implemented. 00235 00236 // ----------------------------------------------------------------------- 00237 // member variables 00238 protected: 00239 00240 std::string _name; ///< Program name. 00241 std::string _project; ///< Name of project. 00242 std::vector<std::string> _examples; ///< Program usage example. 00243 std::string _copyright; ///< Program copyright. 00244 std::string _license; ///< Program license. 00245 std::string _contact; ///< Contact information. 00246 00247 }; // class CmdLine 00248 00249 00250 } // namespace basis 00251 00252 } // namespace sbia 00253 00254 00255 #endif // _SBIA_BASIS_CMDLINE_H