MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2008 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library 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 GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 (2008) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file CLArgFlag.hpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #ifndef MSQ_CLARG_FLAG_HPP 00033 #define MSQ_CLARG_FLAG_HPP 00034 00035 #include "Mesquite.hpp" 00036 #include "CLArgs.hpp" 00037 #include <string> 00038 #include <vector> 00039 #include <iosfwd> 00040 00041 class CLArgFlag 00042 { 00043 private: 00044 char mFlag; 00045 std::string mDesc; 00046 00047 protected: 00048 CLArgFlag( char pflag, const char* pdesc ) : mFlag( pflag ), mDesc( pdesc ) {} 00049 00050 public: 00051 virtual ~CLArgFlag(); 00052 00053 char flag() const 00054 { 00055 return mFlag; 00056 } 00057 const char* desc() const 00058 { 00059 return mDesc.c_str(); 00060 } 00061 virtual const CLArgs::ArgIBase* callback() const = 0; 00062 00063 virtual bool is_toggle() const; 00064 virtual bool parse( const char* string_value ) const = 0; 00065 00066 /** Get brief format of option */ 00067 virtual std::string brief() const = 0; 00068 /** Get UNIX man-page formated synposis of flag */ 00069 virtual std::string manstr() const = 0; 00070 00071 virtual bool add_set( int size, const char* const* names ); 00072 00073 std::string make_man_string( int count, const char* names[] ) const; 00074 std::string make_man_string( const char* arg_name ) const 00075 { 00076 return make_man_string( 1, &arg_name ); 00077 } 00078 std::string make_man_string() const 00079 { 00080 return make_man_string( 0, 0 ); 00081 } 00082 std::string make_literal_man_string( int count, const char* literal_args[] ) const; 00083 std::string make_literal_man_string( const char* literal_args ) const 00084 { 00085 return make_literal_man_string( 1, &literal_args ); 00086 } 00087 }; 00088 00089 class CLArgToggle : public CLArgFlag 00090 { 00091 private: 00092 bool mValue; //!< value to pass to callback when flag is encountered 00093 CLArgs::ToggleArgI* mCallback; 00094 CLArgToggle* mOpposite; 00095 00096 public: 00097 CLArgToggle( char pflag, const char* pdesc, bool value, CLArgs::ToggleArgI* pcallback ) 00098 : CLArgFlag( pflag, pdesc ), mValue( value ), mCallback( pcallback ), mOpposite( 0 ) 00099 { 00100 } 00101 CLArgToggle( char pflag, const char* pdesc, CLArgToggle* opposite ) 00102 : CLArgFlag( pflag, pdesc ), mValue( !opposite->mValue ), mCallback( opposite->mCallback ), 00103 mOpposite( opposite ) 00104 { 00105 mOpposite->mOpposite = this; 00106 } 00107 00108 virtual const CLArgs::ArgIBase* callback() const 00109 { 00110 return mCallback; 00111 } 00112 00113 virtual bool is_toggle() const 00114 { 00115 return true; 00116 } 00117 virtual bool parse( const char* option ) const; 00118 00119 virtual std::string brief() const; 00120 virtual std::string manstr() const; 00121 }; 00122 00123 class CLArgString : public CLArgFlag 00124 { 00125 private: 00126 std::string mName; 00127 CLArgs::StringArgI* mCallback; 00128 00129 public: 00130 CLArgString( char fl, const char* name, const char* pdesc, CLArgs::StringArgI* pcallback ) 00131 : CLArgFlag( fl, pdesc ), mName( name ), mCallback( pcallback ) 00132 { 00133 } 00134 00135 virtual const CLArgs::ArgIBase* callback() const 00136 { 00137 return mCallback; 00138 } 00139 00140 virtual bool parse( const char* option ) const; 00141 00142 virtual std::string brief() const; 00143 virtual std::string manstr() const; 00144 }; 00145 00146 class CLArgLong : public CLArgFlag 00147 { 00148 private: 00149 CLArgs::LongArgI* mCallback; 00150 std::string mName; 00151 00152 public: 00153 CLArgLong( char fl, const char* name, const char* pdesc, CLArgs::LongArgI* pcallback ) 00154 : CLArgFlag( fl, pdesc ), mCallback( pcallback ), mName( name ) 00155 { 00156 } 00157 00158 virtual const CLArgs::ArgIBase* callback() const 00159 { 00160 return mCallback; 00161 } 00162 00163 virtual bool parse( const char* option ) const; 00164 00165 virtual std::string brief() const; 00166 virtual std::string manstr() const; 00167 }; 00168 00169 class CLArgInt : public CLArgFlag 00170 { 00171 private: 00172 CLArgs::IntArgI* mCallback; 00173 std::string mName; 00174 00175 public: 00176 CLArgInt( char fl, const char* name, const char* pdesc, CLArgs::IntArgI* pcallback ) 00177 : CLArgFlag( fl, pdesc ), mCallback( pcallback ), mName( name ) 00178 { 00179 } 00180 00181 virtual const CLArgs::ArgIBase* callback() const 00182 { 00183 return mCallback; 00184 } 00185 00186 virtual bool parse( const char* option ) const; 00187 00188 virtual std::string brief() const; 00189 virtual std::string manstr() const; 00190 }; 00191 00192 class CLArgDouble : public CLArgFlag 00193 { 00194 private: 00195 CLArgs::DoubleArgI* mCallback; 00196 std::string mName; 00197 00198 public: 00199 CLArgDouble( char fl, const char* name, const char* pdesc, CLArgs::DoubleArgI* pcallback ) 00200 : CLArgFlag( fl, pdesc ), mCallback( pcallback ), mName( name ) 00201 { 00202 } 00203 00204 virtual const CLArgs::ArgIBase* callback() const 00205 { 00206 return mCallback; 00207 } 00208 00209 virtual bool parse( const char* option ) const; 00210 00211 virtual std::string brief() const; 00212 virtual std::string manstr() const; 00213 }; 00214 00215 class CLArgIDList : public CLArgFlag 00216 { 00217 public: 00218 CLArgs::IntListArgI* mCallback; 00219 00220 public: 00221 CLArgIDList( char fl, const char* pdesc, CLArgs::IntListArgI* pcallback ) 00222 : CLArgFlag( fl, pdesc ), mCallback( pcallback ) 00223 { 00224 } 00225 00226 virtual const CLArgs::ArgIBase* callback() const 00227 { 00228 return mCallback; 00229 } 00230 00231 virtual bool parse( const char* str ) const; 00232 00233 virtual std::string brief() const; 00234 virtual std::string manstr() const; 00235 }; 00236 00237 class CLArgListData 00238 { 00239 std::vector< std::vector< std::string > > mSets; 00240 00241 public: 00242 bool add_set( int size, const char* const* names ); 00243 bool acceptable_length( unsigned len ) const; 00244 bool accept_any_length() const 00245 { 00246 return mSets.empty(); 00247 } 00248 00249 std::string set_string( int set ) const; 00250 std::string brief() const; 00251 std::string manstr( char type_char, const CLArgFlag& f ) const; 00252 }; 00253 00254 class CLArgIntList : public CLArgFlag 00255 { 00256 private: 00257 CLArgListData listData; 00258 CLArgs::IntListArgI* mCallback; 00259 00260 public: 00261 CLArgIntList( char fl, const char* pdesc, CLArgs::IntListArgI* pcallback ) 00262 : CLArgFlag( fl, pdesc ), mCallback( pcallback ) 00263 { 00264 } 00265 00266 virtual const CLArgs::ArgIBase* callback() const 00267 { 00268 return mCallback; 00269 } 00270 00271 virtual bool parse( const char* option ) const; 00272 00273 virtual std::string brief() const; 00274 virtual std::string manstr() const; 00275 virtual bool add_set( int size, const char* const* names ) 00276 { 00277 return listData.add_set( size, names ); 00278 } 00279 }; 00280 00281 class CLArgDoubleList : public CLArgFlag 00282 { 00283 private: 00284 CLArgListData listData; 00285 std::string mName; 00286 CLArgs::DoubleListArgI* mCallback; 00287 00288 public: 00289 CLArgDoubleList( char fl, const char* pdesc, CLArgs::DoubleListArgI* pcallback ) 00290 : CLArgFlag( fl, pdesc ), mCallback( pcallback ) 00291 { 00292 } 00293 00294 virtual const CLArgs::ArgIBase* callback() const 00295 { 00296 return mCallback; 00297 } 00298 00299 virtual bool parse( const char* option ) const; 00300 00301 virtual std::string brief() const; 00302 virtual std::string manstr() const; 00303 virtual bool add_set( int size, const char* const* names ) 00304 { 00305 return listData.add_set( size, names ); 00306 } 00307 }; 00308 00309 #endif