[pktools] 04/375: support Optionpk without default value

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:53:52 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 70f56cf5d9be154d0c283ab4857f56e770ec7e6e
Author: Pieter Kempeneers <kempenep at gmail.com>
Date:   Tue Aug 28 15:26:07 2012 +0200

    support Optionpk without default value
---
 src/apps/pkfilter.cc |  4 ++--
 src/base/Optionpk.h  | 30 +++++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/apps/pkfilter.cc b/src/apps/pkfilter.cc
index c4c2122..b78ac57 100644
--- a/src/apps/pkfilter.cc
+++ b/src/apps/pkfilter.cc
@@ -58,9 +58,9 @@ int main(int argc,char **argv) {
   Optionpk<int> dimX_opt("dx", "dx", "filter kernel size in x, must be odd (example: 3).", 0);
   Optionpk<int> dimY_opt("dy", "dy", "filter kernel size in y, must be odd (example: 3).. Set dy=0 if 1-D filter must be used in band domain", 0);
   Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
-  Optionpk<short> class_opt("class", "class", "class value(s) to use for density, erosion, dilation, openening and closing, thresholding", 1);
+  Optionpk<short> class_opt("class", "class", "class value(s) to use for density, erosion, dilation, openening and closing, thresholding");
   Optionpk<double> threshold_opt("t", "threshold", "threshold value(s) to use for threshold filter (one for each class)", 0);
-  Optionpk<short> mask_opt("\0", "mask", "mask value(s) ", -1);
+  Optionpk<short> mask_opt("\0", "mask", "mask value(s) ");
   Optionpk<std::string> tap_opt("tap", "tap", "text file conttaining taps used for filtering (from ul to lr). Use dimX and dimY to specify tap dimensions in x and y. Leave empty for not using taps", "");
   Optionpk<std::string> colorTable_opt("\0", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
   Optionpk<short> down_opt("d", "down", "down sampling factor. Use value 1 for no downsampling)", 1);
diff --git a/src/base/Optionpk.h b/src/base/Optionpk.h
index 48922f9..6547f99 100644
--- a/src/base/Optionpk.h
+++ b/src/base/Optionpk.h
@@ -117,8 +117,10 @@ 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();
+  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 setHelp(const string& helpInfo){m_help=helpInfo;};
   string usage() const;
@@ -155,6 +157,7 @@ private:
   string m_help;
   bool m_hasArgument;
   T m_defaultValue;
+  bool m_hasDefault;
 };
 
 template<class T1> ostream& operator<<(ostream& os, const Optionpk<T1>& theOption)
@@ -167,10 +170,17 @@ template<class T1> ostream& operator<<(ostream& os, const Optionpk<T1>& theOptio
 }
 
 template<class T> Optionpk<T>::Optionpk() 
+  : m_hasDefault(false)
 {
 }
 
-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)
+  : 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)
 {
   setAll(shortName,longName,helpInfo,defaultValue);
 }
@@ -192,7 +202,8 @@ template<class T> string Optionpk<T>::usage() const
     helpss << "   " << setiosflags(ios::left) << setw(20) << " ";
   helpss << "   " << m_help;
   // helpss << std::resetiosflags << " (default: " << type2string<T>(m_defaultValue) << ")";
-  helpss << " (default: " << type2string<T>(m_defaultValue) << ")";
+  if(m_hasDefault)
+    helpss << " (default: " << type2string<T>(m_defaultValue) << ")";
   return helpss.str();
 }
 
@@ -203,9 +214,21 @@ template<class T> void Optionpk<T>::setAll(const string& shortName, const string
   m_hasArgument=true;
   m_help=helpInfo;
   m_defaultValue=defaultValue;
+  m_hasDefault=true;
+}
+
+template<class T> void Optionpk<T>::setAll(const string& shortName, const string& longName, const string& helpInfo)
+{
+  m_shortName=shortName;
+  m_longName=longName;
+  m_hasArgument=true;
+  m_help=helpInfo;
 }
+
 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);
+
 template<> Optionpk<bool>::Optionpk(const string& shortName, const string& longName, const string& helpInfo,const bool& defaultValue)
 {
   setAll(shortName,longName,helpInfo,defaultValue);
@@ -218,6 +241,7 @@ template<> void Optionpk<bool>::setAll(const string& shortName, const string& lo
   m_hasArgument=false;
   m_help=helpInfo;
   m_defaultValue=defaultValue;
+  m_hasDefault=true;
 }
 
 template<class T> Optionpk<T>::~Optionpk() 
@@ -259,7 +283,7 @@ template<class T> int Optionpk<T>::retrieveOption(int argc, char **argv){
         this->push_back(string2type<T>("1"));
     }
   }
-  if(!(this->size()))//only set default value if no options were given
+  if(!(this->size())&&m_hasDefault)//only set default value if no options were given
     this->push_back(m_defaultValue);
   return(this->size());
 }

-- 
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