[pktools] 41/375: doxygen help format in Optionpk.h, example for pkinfo.cc, other apps to be done
Bas Couwenberg
sebastic at xs4all.nl
Wed Dec 3 21:53:56 UTC 2014
This is an automated email from the git hooks/post-receive script.
sebastic-guest pushed a commit to branch upstream-master
in repository pktools.
commit e287c40d8cffd359bbd395ba95d32b4d52c37579
Author: user <user at osgeolive.(none)>
Date: Sat Jan 26 22:08:42 2013 +0100
doxygen help format in Optionpk.h, example for pkinfo.cc, other apps to be done
---
src/apps/pkinfo.cc | 132 +++++++++++++++++++++++++++-------------------------
src/base/Optionpk.h | 113 ++++++++++++++++++++++++++------------------
2 files changed, 136 insertions(+), 109 deletions(-)
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index ad86a50..64062dc 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -33,49 +33,51 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
- boolean (bool) options do not expect a value (e.g., `pkinfo --version`)
- multiple inputs require duplicate options (e.g., `pkinfo -i input1.tif -i input2.tif -f`)
- |short|long|type|description|default|
- |-----|----|----|-----------|------|
- | |version|bool|Shows version of pktools|false |
- | lic | license | b | Shows license information | false|
- | h | help | b | Shows this help info | false|
- | | todo | b | | false|
- | i | input | Ss | Input image file | <empty string>|
- | bb | bbox | b | Shows bounding box | false|
- | te | te | b | Shows bounding box in GDAL format: xmin ymin xmax ymax | false|
- | c | centre | b | Image centre in projected X,Y coordinates | false|
- | ct | colourtable | b | Shows colour table | false|
- | s | samples | b | Number of samples in image | false|
- | l | lines | b | Number of lines in image | false|
- | nb | nband | b | Show number of bands in image | false|
- | b | band | s | Band specific information | 0|
- | dx | dx | b | Gets resolution in x (in m) | false|
- | dy | dy | b | Gets resolution in y (in m) | false|
- | mm | minmax | b | Shows min and max value of the image | false|
- | stat | stat | b | Shows statistics (min,max, mean and stdDev of the image) | false|
- | min | min | d | Sets minimum for histogram | |
- | max | max | d | Sets maximum for histogram | |
- | rel | rel | b | Calculates relative histogram in percentage | false|
- | p | projection | b | Shows projection of the image | false|
- | geo | geo | b | Gets geotransform | false|
- | il | interleave | b | Shows interleave | false|
- | f | filename | b | Shows image filename | false|
- | cov | cover | b | Image covers bounding box (or x and y pos) if printed to std out | false|
- | x | xpos | d | x pos | |
- | y | ypos | d | y pos | |
- | r | read | b | Reads row y (in projected coordinates if geo option is set, otherwise in image coordinates, 0 based) | false|
- | ref | ref | b | Gets reference pixel (lower left corner of centre of gravity pixel) | false|
- | of | oformat | b | Gets driver description | false|
- | e | extent | Ss | Gets boundary from extent from polygons in vector file | <empty string>|
- | ulx | ulx | d | Upper left x value bounding box | |
- | uly | uly | d | Upper left y value bounding box | |
- | lrx | lrx | d | Lower right x value bounding box | |
- | lry | lry | d | Lower right y value bounding box | |
- | hist | hist | b | Calculates histogram. Use --rel for a relative histogram output. | false|
- | nbin | nbin | s | Number of bins used in histogram. Use 0 for all input values as integers | 0|
- | ot | otype | b | Returns data type | false|
- | d | description | b | Returns image description | false|
- | meta | meta | b | Shows meta data | false|
- | nodata | nodata | d | Sets no data value(s) for calculations (flags in input image) | |
+ |short|long|type|default|description|
+ |-----|----|----|-------|-----------|
+ | lic | license | b | false |Shows license information |
+ | h | help | b | false |Shows this help info |
+ | i | input | Ss | <empty string> |Input image file |
+ | bb | bbox | b | false |Shows bounding box |
+ | te | te | b | false |Shows bounding box in GDAL format: xmin ymin xmax ymax |
+ | c | centre | b | false |Image centre in projected X,Y coordinates |
+ | ct | colourtable | b | false |Shows colour table |
+ | s | samples | b | false |Number of samples in image |
+ | l | lines | b | false |Number of lines in image |
+ | nb | nband | b | false |Show number of bands in image |
+ | b | band | s | 0 |Band specific information |
+ | dx | dx | b | false |Gets resolution in x (in m) |
+ | dy | dy | b | false |Gets resolution in y (in m) |
+ | mm | minmax | b | false |Shows min and max value of the image |
+ | stat | stat | b | false |Shows statistics (min,max, mean and stdDev of the image) |
+ | min | min | d | |Sets minimum for histogram |
+ | max | max | d | |Sets maximum for histogram |
+ | rel | rel | b | false |Calculates relative histogram in percentage |
+ | p | projection | b | false |Shows projection of the image |
+ | geo | geo | b | false |Gets geotransform |
+ | il | interleave | b | false |Shows interleave |
+ | f | filename | b | false |Shows image filename |
+ | cov | cover | b | false |Image covers bounding box (or x and y pos) if printed to std out |
+ | x | xpos | d | |x pos |
+ | y | ypos | d | |y pos |
+ | r | read | b | false |Reads row y (in projected coordinates if geo option is set, otherwise in image coordinates, 0 based) |
+ | ref | ref | b | false |Gets reference pixel (lower left corner of centre of gravity pixel) |
+ | of | oformat | b | false |Gets driver description |
+ | e | extent | Ss | <empty string> |Gets boundary from extent from polygons in vector file |
+ | ulx | ulx | d | |Upper left x value bounding box |
+ | uly | uly | d | |Upper left y value bounding box |
+ | lrx | lrx | d | |Lower right x value bounding box |
+ | lry | lry | d | |Lower right y value bounding box |
+ | hist | hist | b | false |Calculates histogram. Use --rel for a relative histogram output. |
+ | nbin | nbin | s | 0 |Number of bins used in histogram. Use 0 for all input values as integers |
+ | ot | otype | b | false |Returns data type |
+ | d | description | b | false |Returns image description |
+ | meta | meta | b | false |Shows meta data |
+ | nodata | nodata | d | |Sets no data value(s) for calculations (flags in input image) |
+ | | version | b | false |version 2.4, Copyright (C) 2008-2012 Pieter Kempeneers.
+ This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; use option --license for details. |
*/
#include <sstream>
#include <list>
@@ -90,16 +92,10 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
int main(int argc, char *argv[])
{
- std::string versionString="version ";
- versionString+=VERSION;
- versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
- This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
- This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.";
- Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","Shows license information",false);
Optionpk<bool> help_opt("h","help","Shows this help info",false);
- Optionpk<bool> todo_opt("\0","todo","",false);
+ Optionpk<bool> doxygen_opt("\0","doxygen","Shows this help info",false,2);
+ Optionpk<bool> todo_opt("todo","todo","Nothing planned",false,2);
Optionpk<std::string> input_opt("i","input","Input image file","");
Optionpk<bool> bbox_opt("bb", "bbox", "Shows bounding box ", false);
Optionpk<bool> bbox_te_opt("te", "te", "Shows bounding box in GDAL format: xmin ymin xmax ymax ", false);
@@ -137,21 +133,19 @@ int main(int argc, char *argv[])
Optionpk<bool> description_opt("d", "description", "Returns image description", false);
Optionpk<bool> metadata_opt("meta", "meta", "Shows meta data ", false);
Optionpk<double> nodata_opt("nodata", "nodata", "Sets no data value(s) for calculations (flags in input image)");
-
- version_opt.retrieveOption(argc,argv);
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
+ This is free software, and you are welcome to redistribute it\n\
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
+
license_opt.retrieveOption(argc,argv);
help_opt.retrieveOption(argc,argv);
+ doxygen_opt.retrieveOption(argc,argv);
todo_opt.retrieveOption(argc,argv);
- if(version_opt[0]){
- std::cout << version_opt.getHelp() << std::endl;
- exit(0);
- }
- if(license_opt[0]){
- cout << Optionpk<bool>::getGPLv3License() << endl;
- exit(0);
- }
-
input_opt.retrieveOption(argc,argv);
bbox_opt.retrieveOption(argc,argv);
bbox_te_opt.retrieveOption(argc,argv);
@@ -189,9 +183,21 @@ int main(int argc, char *argv[])
description_opt.retrieveOption(argc,argv);
metadata_opt.retrieveOption(argc,argv);
nodata_opt.retrieveOption(argc,argv);
+ version_opt.retrieveOption(argc,argv);
+ if(version_opt[0]){
+ std::cout << version_opt.getHelp() << std::endl;
+ exit(0);
+ }
+ if(license_opt[0]){
+ cout << Optionpk<bool>::getGPLv3License() << endl;
+ exit(0);
+ }
if(help_opt[0]){
- std::cout << "usage: pkinfo -i imagefile [OPTIONS]" << std::endl;
+ cout << "usage: pkcrop -i inputimage -o outputimage [OPTIONS]" << endl;
+ exit(0);
+ }
+ if(doxygen_opt[0]){
exit(0);
}
diff --git a/src/base/Optionpk.h b/src/base/Optionpk.h
index 11378b6..c9271c9 100644
--- a/src/base/Optionpk.h
+++ b/src/base/Optionpk.h
@@ -119,10 +119,11 @@ template<class T> class Optionpk : public vector <T>
public:
Optionpk();
Optionpk(const string& shortName, const string& longName, const string& helpInfo);
- Optionpk(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue);
+ Optionpk(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue, short hide=0);
~Optionpk();
void setHelp(const string& helpInfo){m_help=helpInfo;};
string usage() const;
+ string usageDoxygen() const;
static string getGPLv3License(){
return static_cast<string>("\n\
This program is free software: you can redistribute it and/or modify\n\
@@ -138,12 +139,12 @@ public:
You should have received a copy of the GNU General Public License\n\
along with this program. If not, see <http://www.gnu.org/licenses/>.\n");};
string getHelp() const {return m_help;};
- int retrieveOption(int argc, char ** argv);
+ bool retrieveOption(int argc, char ** argv);///make sure to call this function first before using the option
std::vector<string>::const_iterator findSubstring(string argument) const;
template<class T1> friend ostream& operator<<(ostream & os, const Optionpk<T1>& theOption);
private:
void setAll(const string& shortName, const string& longName, const string& helpInfo);
- void setAll(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue);
+ void setAll(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue, short hide);
void setDefault(const T& defaultValue);
string getDefaultValue() const {return m_defaultValue;};
void setShortName(const string& shortName);
@@ -154,12 +155,13 @@ private:
bool hasShortOption() const {return m_shortName.compare("\0");};
bool hasLongOption() const {return m_longName.compare("\0");};
- string m_shortName;
- string m_longName;
- string m_help;
- bool m_hasArgument;
- T m_defaultValue;
- bool m_hasDefault;
+ /*! short option invoked with `-` */string m_shortName;
+ /*! long option invoked with `--` */ string m_longName;
+ /*! the help message that is shown when option -h or --help is invoked */ string m_help;
+ /*! false for options of type bool */ bool m_hasArgument;
+ /*! the default value of the option */ T m_defaultValue;
+ /*! option has a default value */ bool m_hasDefault;
+ /*! 0: always show, 1: only show with long help (--help), 2: never show (hide)*/ short m_hide;
};
template<class T1> ostream& operator<<(ostream& os, const Optionpk<T1>& theOption)
@@ -172,19 +174,19 @@ template<class T1> ostream& operator<<(ostream& os, const Optionpk<T1>& theOptio
}
template<class T> Optionpk<T>::Optionpk()
- : m_hasDefault(false)
+: m_hasDefault(false)
{
}
template<class T> Optionpk<T>::Optionpk(const string& shortName, const string& longName, const string& helpInfo)
- : m_hasDefault(false)
+: m_hasDefault(false)
{
setAll(shortName,longName,helpInfo);
}
- template<class T> Optionpk<T>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue)
+template<class T> Optionpk<T>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue, short hide)
{
- setAll(shortName,longName,helpInfo,defaultValue);
+ setAll(shortName,longName,helpInfo,defaultValue, hide);
}
template<class T> string Optionpk<T>::usage() const
@@ -192,41 +194,47 @@ template<class T> string Optionpk<T>::usage() const
ostringstream helpss;
string shortOption=m_shortName;
string longOption=m_longName;
+ shortOption.insert(0,"-");
+ longOption.insert(0,"--");
+ if(hasShortOption())
+ helpss << " " << setiosflags(ios::left) << setw(4) << shortOption;
+ else
+ helpss << " " << setiosflags(ios::left) << setw(4) << " ";
+ if(hasLongOption())
+ helpss << " " << setiosflags(ios::left) << setw(20) << longOption;
+ else
+ helpss << " " << setiosflags(ios::left) << setw(20) << " ";
+ helpss << " " << m_help;
+ if(m_hasDefault)
+ helpss << " (default: " << type2string<T>(m_defaultValue) << ")";
+ return helpss.str();
+}
+
+template<class T> string Optionpk<T>::usageDoxygen() const
+{
+ ostringstream helpss;
+ string shortOption=m_shortName;
+ string longOption=m_longName;
+
if(hasShortOption())
helpss << " | " << setiosflags(ios::left) << setw(6) << shortOption << " | ";
- else
- helpss << " | " << setiosflags(ios::left) << setw(6) << " | ";
+ else
+ helpss << " | " << setiosflags(ios::left) << " | ";
if(hasLongOption())
helpss << setiosflags(ios::left) << setw(20) << longOption << " | ";
else
- helpss << setiosflags(ios::left) << setw(20) << " | ";
+ helpss << setiosflags(ios::left) << " | ";
helpss << setiosflags(ios::left) << setw(4) << typeid(T).name() << " | ";
- helpss << m_help << " | ";
if(m_hasDefault)
- helpss << type2string<T>(m_defaultValue) << "|";
+ helpss <<setiosflags(ios::left) << setw(5) << type2string<T>(m_defaultValue) << " |";
else
- helpss << "|";
+ helpss << " |";
+ helpss << m_help << " | ";
+
return helpss.str();
- /* ostringstream helpss; */
- /* string shortOption=m_shortName; */
- /* string longOption=m_longName; */
- /* shortOption.insert(0,"-"); */
- /* longOption.insert(0,"--"); */
- /* if(hasShortOption()) */
- /* helpss << " " << setiosflags(ios::left) << setw(4) << shortOption; */
- /* else */
- /* helpss << " " << setiosflags(ios::left) << setw(4) << " "; */
- /* if(hasLongOption()) */
- /* helpss << " " << setiosflags(ios::left) << setw(20) << longOption; */
- /* else */
- /* helpss << " " << setiosflags(ios::left) << setw(20) << " "; */
- /* helpss << " " << m_help; */
- /* if(m_hasDefault) */
- /* helpss << " (default: " << type2string<T>(m_defaultValue) << ")"; */
- /* return helpss.str(); */
}
-template<class T> void Optionpk<T>::setAll(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue)
+template<class T> void Optionpk<T>::setAll(const string& shortName, const string& longName, const string& helpInfo,const T& defaultValue, short hide)
{
m_shortName=shortName;
m_longName=longName;
@@ -234,6 +242,7 @@ template<class T> void Optionpk<T>::setAll(const string& shortName, const string
m_help=helpInfo;
m_defaultValue=defaultValue;
m_hasDefault=true;
+ m_hide=hide;
}
template<class T> void Optionpk<T>::setAll(const string& shortName, const string& longName, const string& helpInfo)
@@ -242,18 +251,19 @@ template<class T> void Optionpk<T>::setAll(const string& shortName, const string
m_longName=longName;
m_hasArgument=true;
m_help=helpInfo;
+ m_hide=0;
}
-template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue);
+template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue, short hide);
template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo);
-template<> Optionpk<bool>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue)
+template<> Optionpk<bool>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue, short hide)
{
- setAll(shortName,longName,helpInfo,defaultValue);
+ setAll(shortName,longName,helpInfo,defaultValue, hide);
}
-template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue)
+template<> void Optionpk<bool>::setAll(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue, short hide)
{
m_shortName=shortName;
m_longName=longName;
@@ -261,30 +271,41 @@ template<> void Optionpk<bool>::setAll(const string& shortName, const string& lo
m_help=helpInfo;
m_defaultValue=defaultValue;
m_hasDefault=true;
+ m_hide=hide;
}
template<class T> Optionpk<T>::~Optionpk()
{
}
-template<class T> int Optionpk<T>::retrieveOption(int argc, char **argv){
+template<class T> bool Optionpk<T>::retrieveOption(int argc, char **argv){
for(int i = 1; i < argc; ++i ){
string helpStringShort="-h";
string helpStringLong="--help";
+ string helpStringDoxygen="--doxygen";
string currentArgument;
string currentOption=argv[i];
string shortOption=m_shortName;
string longOption=m_longName;
shortOption.insert(0,"-");
longOption.insert(0,"--");
- // size_t foundEqual=currentOption.rfind("=");
size_t foundEqual=currentOption.rfind("=");
if(foundEqual!=string::npos){
currentArgument=currentOption.substr(foundEqual+1);
currentOption=currentOption.substr(0,foundEqual);
}
- if(!(helpStringShort.compare(currentOption))||!(helpStringLong.compare(currentOption)))
- cout << usage() << endl;
+ if(!helpStringShort.compare(currentOption)){
+ if(m_hide<1)
+ std::cout << usage() << std::endl;
+ }
+ else if(!helpStringLong.compare(currentOption)){
+ if(m_hide<2)
+ std::cout << usage() << std::endl;
+ }
+ else if(!helpStringDoxygen.compare(currentOption)){
+ if(m_hide<2)
+ std::cout << usageDoxygen() << std::endl;
+ }
if(hasShortOption()&&!(shortOption.compare(currentOption))){//for -option
if(foundEqual!=string::npos)
this->push_back(string2type<T>(currentArgument));
@@ -304,7 +325,7 @@ template<class T> int Optionpk<T>::retrieveOption(int argc, char **argv){
}
if(!(this->size())&&m_hasDefault)//only set default value if no options were given
this->push_back(m_defaultValue);
- return(this->size());
+ return(true);
}
template<class T> std::vector<string>::const_iterator Optionpk<T>::findSubstring(string argument) const{
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git
More information about the Pkg-grass-devel
mailing list