arguments

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
arguments [05.01.2006 13:42 (vor 19 Jahren)] cwachaarguments [16.11.2016 23:18 (vor 8 Jahren)] (aktuell) – Externe Bearbeitung 127.0.0.1
Zeile 24: Zeile 24:
  
 === Download === === Download ===
 +  * {{projects:arguments-1.2.zip}}
   * {{projects:arguments-1.1.zip}}   * {{projects:arguments-1.1.zip}}
   * {{projects:arguments-1.0.tar.gz}}   * {{projects:arguments-1.0.tar.gz}}
Zeile 49: Zeile 50:
  // !! argument list !!  // !! argument list !!
   
- // Format: getXXX(option to search, default value, long option to search); + // Format: get(option to search, default value, long option to search); 
- //  the latter two are optional + //  long_option is optional 
- int my_int = a.getInt("-a"); + int my_int = a.get("-a", 0); 
- int my_int2 = a.getInt("-a", "340", "--with-long-option");+ double my_int2 = a.get<double>("-a", 340, "--with-long-option"); 
 + string test = a.get<string>("-test", "not here");
  bool show_help = a.getFlag("-h", "--help");  bool show_help = a.getFlag("-h", "--help");
   
- // if you are interested in a supplied filename you can use front()+ // if you are interested a supplied filename you can use front()
  //  or back() to pop the first or last element  //  or back() to pop the first or last element
  string filename = a.back();  string filename = a.back();
Zeile 71: Zeile 73:
  //now do your stuff  //now do your stuff
   
- cout << "a=" << my_int << " other a=" << my_int2 << endl; + cout << "a=" << my_int << " other a=" << my_int2 << " test=" << test << endl; 
- +
  return 0;  return 0;
 } }
 +
 </code> </code>
  
Zeile 92: Zeile 95:
  // returns true if flag is found, false else  // returns true if flag is found, false else
  bool getFlag(const std::string& option, const std::string& long_option = "");  bool getFlag(const std::string& option, const std::string& long_option = "");
- // returns integer if found, supplied default_value else + // returns type T if found or default_value (converted to type T) else 
- int getInt(const std::string& option, const std::string& default_value = "", const std::string& long_option = "")+ // Remarkdoes NOT work with char*. Use string instead and c_str() to get a char* 
- // returns double if found, supplied default_value else + template<typename T> T get(const std::string& option, const T& default_value, const std::string& long_option = ""); 
- double getDouble(const std::string& option, const std::string& default_value = "", const std::string& long_option = ""); +
- // returns string if found, supplied default_value else +
- std::string getString(const std::string& option, const std::string& default_value = "", const std::string& long_option = "")+
- // returns char* to a C string if found, char* to a copy of default_value if not found. +
- // Remark that you will have to free() the returned string once you don't need it anymore! +
- char* getCString(const std::string& option, const std::string& default_value = "", const std::string& long_option = ""); +
- +
  // return first element  // return first element
  std::string front();  std::string front();
Zeile 113: Zeile 110:
 </code> </code>
  
 +
 +=== License ===
 +
 +<html>
 +
 +<!-- Creative Commons License -->
 +<a href="http://creativecommons.org/licenses/GPL/2.0/">
 +<img alt="CC-GNU GPL" border="0" src="http://creativecommons.org/images
 +/public/cc-GPL-a.png" /></a><br />
 +This software is licensed under the <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL</a>.
 +<!-- /Creative Commons License -->
 +
 +<!--
 +
 +<rdf:RDF xmlns="http://web.resource.org/cc/"
 +    xmlns:dc="http://purl.org/dc/elements/1.1/"
 +    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 +<Work rdf:about="">
 +   <license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
 +   <dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" />
 +</Work>
 +
 +<License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
 +<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
 +   <permits rdf:resource="http://web.resource.org/cc/Distribution" />
 +   <requires rdf:resource="http://web.resource.org/cc/Notice" />
 +   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
 +   <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
 +   <requires rdf:resource="http://web.resource.org/cc/SourceCode" />
 +</License>
 +
 +</rdf:RDF>
 +
 +-->
 +
 +</html>
  
  • arguments.1136464947.txt.gz
  • Zuletzt geändert: 16.11.2016 23:16 (vor 8 Jahren)
  • (Externe Bearbeitung)