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 b84ea717af1f5b78b47d14403b512fc515772fd6
Author: Pieter Kempeneers <kempe...@gmail.com>
Date:   Wed Jan 30 15:46:20 2013 +0100

    error in pkclassify_svm when aggregation_opt is 0
---
 Doxyfile                   |   2 +-
 src/apps/pkclassify_svm.cc | 141 ++++++++++++++++++++++++++-------------------
 src/apps/pkinfo.cc         |  13 ++---
 src/base/Makefile.am       |  11 ++++
 src/base/Makefile.in       |  52 ++++++++++++-----
 src/base/Optionpk.h        |  74 ++++++++++++++++++++++--
 6 files changed, 205 insertions(+), 88 deletions(-)

diff --git a/Doxyfile b/Doxyfile
index 24934c5..0d95bdc 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -266,7 +266,7 @@ AUTOLINK_SUPPORT       = YES
 # func(std::string) {}). This also makes the inheritance and collaboration
 # diagrams that involve STL classes more complete and accurate.
 
-BUILTIN_STL_SUPPORT    = NO
+BUILTIN_STL_SUPPORT    = YES
 
 # If you use Microsoft's C++/CLI language, you should set this option to YES to
 # enable parsing support.
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index db3b615..96445d1 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -31,26 +31,26 @@ along with pktools.  If not, see 
<http://www.gnu.org/licenses/>.
 
 #define Malloc(type,n) (type *)malloc((n)*sizeof(type))
 
-void reclass(const vector<double>& result, const vector<int>& vreclass, const 
vector<double>& priors, unsigned short aggregation, vector<float>& 
theResultReclass);
+void reclass(const vector<double>& result, const vector<short>& vreclass, 
const vector<double>& priors, unsigned short aggregation, vector<float>& 
theResultReclass);
 
-void reclass(const vector<double>& result, const vector<int>& vreclass, const 
vector<double>& priors, unsigned short aggregation, vector<float>& 
theResultReclass){
-  unsigned int nclass=result.size();
+void reclass(const vector<double>& result, const vector<short>& vreclass, 
const vector<double>& priors, unsigned short aggregation, vector<float>& 
theResultReclass){
+  short nclass=result.size();
   assert(priors.size()==nclass);
   assert(theResultReclass.size()>1);//must have size nreclass!
-  unsigned int nreclass=theResultReclass.size();
+  short nreclass=theResultReclass.size();
   vector<float> pValues(nclass);
   float normReclass=0;
-  for(int iclass=0;iclass<nclass;++iclass){
+  for(short iclass=0;iclass<nclass;++iclass){
     float pv=result[iclass];//todo: check if result from svm is [0,1]
     assert(pv>=0);
     assert(pv<=1);
     pv*=priors[iclass];
     pValues[iclass]=pv;
   }
-  for(int iclass=0;iclass<nreclass;++iclass){
+  for(short iclass=0;iclass<nreclass;++iclass){
     theResultReclass[iclass]=0;
     float maxPaggreg=0;
-    for(int ic=0;ic<nclass;++ic){
+    for(short ic=0;ic<nclass;++ic){
       if(vreclass[ic]==iclass){
        switch(aggregation){
        default:
@@ -69,7 +69,7 @@ void reclass(const vector<double>& result, const vector<int>& 
vreclass, const ve
     }
     normReclass+=theResultReclass[iclass];
   }
-  for(int iclass=0;iclass<nreclass;++iclass){
+  for(short iclass=0;iclass<nreclass;++iclass){
     float prv=theResultReclass[iclass];
     prv/=normReclass;
     theResultReclass[iclass]=prv;
@@ -79,8 +79,8 @@ void reclass(const vector<double>& result, const vector<int>& 
vreclass, const ve
 int main(int argc, char *argv[])
 {
   // map<short,int> reclassMap;
-  vector<int> vreclass;          //vreclass: map nclass->nreclass
-  vector<int> vuniqueclass;
+  vector<short> vreclass;        //vreclass: map nclass->nreclass
+  vector<short> vuniqueclass;
   vector<double> priors;
   vector<double> priorsReclass;
   
@@ -196,18 +196,18 @@ int main(int argc, char *argv[])
     std::cout << "number of bootstrap aggregations: " << nbag << std::endl;
   
   unsigned int totalSamples=0;
-  int nreclass=0;
-  vector<int> vcode;//unique class codes in recode string
+  short nreclass=0;
+  vector<short> vcode;//unique reclass codes (e.g., -rc 1 -rc 1 -rc 2 -rc 2 -> 
vcode[0]=1,vcode[1]=2)
   vector<struct svm_model*> svm(nbag);
   vector<struct svm_parameter> param(nbag);
 
-  unsigned int nclass=0;
+  short nclass=0;
   int nband=0;
   int startBand=2;//first two bands represent X and Y pos
 
   if(reclass_opt.size()){
     vreclass.resize(reclass_opt.size());
-    for(int iclass=0;iclass<reclass_opt.size();++iclass){
+    for(short iclass=0;iclass<reclass_opt.size();++iclass){
       // reclassMap[iclass]=reclass_opt[iclass];
       vreclass[iclass]=reclass_opt[iclass];
     }
@@ -215,12 +215,12 @@ int main(int argc, char *argv[])
   if(priors_opt.size()>1){//priors from argument list
     priors.resize(priors_opt.size());
     double normPrior=0;
-    for(int iclass=0;iclass<priors_opt.size();++iclass){
+    for(short iclass=0;iclass<priors_opt.size();++iclass){
       priors[iclass]=priors_opt[iclass];
       normPrior+=priors[iclass];
     }
     //normalize
-    for(int iclass=0;iclass<priors_opt.size();++iclass)
+    for(short iclass=0;iclass<priors_opt.size();++iclass)
       priors[iclass]/=normPrior;
   }
 
@@ -337,7 +337,7 @@ int main(int argc, char *argv[])
         if(random)
           srand(time(NULL));
         totalSamples=0;
-        for(int iclass=0;iclass<nclass;++iclass){
+        for(short iclass=0;iclass<nclass;++iclass){
           if(trainingPixels[iclass].size()>balance_opt[0]){
             while(trainingPixels[iclass].size()>balance_opt[0]){
               int index=rand()%trainingPixels[iclass].size();
@@ -373,7 +373,7 @@ int main(int argc, char *argv[])
         if(scale[ibag][iband]<=0){
           float theMin=trainingPixels[0][0][iband+startBand];
           float theMax=trainingPixels[0][0][iband+startBand];
-          for(int iclass=0;iclass<nclass;++iclass){
+          for(short iclass=0;iclass<nclass;++iclass){
             for(int isample=0;isample<trainingPixels[iclass].size();++isample){
               if(theMin>trainingPixels[iclass][isample][iband+startBand])
                 theMin=trainingPixels[iclass][isample][iband+startBand];
@@ -405,37 +405,37 @@ int main(int argc, char *argv[])
       vcode.clear();
       if(verbose_opt[0]>=1){
         std::cout << "before recoding: " << std::endl;
-        for(int iclass = 0; iclass < vreclass.size(); iclass++)
+        for(short iclass = 0; iclass < vreclass.size(); iclass++)
           std::cout << " " << vreclass[iclass];
         std::cout << std::endl; 
       }
-      vector<int> vord=vreclass;//ordered vector, starting from 0 to nreclass
-      int iclass=0;
-      map<short,int> mreclass;
-      for(int ic=0;ic<vreclass.size();++ic){
+      vector<short> vord=vreclass;//ordered vector, starting from 0 to nreclass
+      short iclass=0;
+      map<short,short> mreclass;
+      for(short ic=0;ic<vreclass.size();++ic){
         if(mreclass.find(vreclass[ic])==mreclass.end())
           mreclass[vreclass[ic]]=iclass++;
       }
-      for(int ic=0;ic<vreclass.size();++ic)
+      for(short ic=0;ic<vreclass.size();++ic)
         vord[ic]=mreclass[vreclass[ic]];
       //construct uniqe class codes
       while(!vreclass.empty()){
         vcode.push_back(*(vreclass.begin()));
         //delete all these entries from vreclass
-        vector<int>::iterator vit;
+        vector<short>::iterator vit;
         
while((vit=find(vreclass.begin(),vreclass.end(),vcode.back()))!=vreclass.end())
           vreclass.erase(vit);
       }
       if(verbose_opt[0]>=1){
         std::cout << "recode values: " << std::endl;
-        for(int icode=0;icode<vcode.size();++icode)
+        for(short icode=0;icode<vcode.size();++icode)
           std::cout << vcode[icode] << " ";
         std::cout << std::endl;
       }
       vreclass=vord;
       if(verbose_opt[0]>=1){
         std::cout << "after recoding: " << std::endl;
-        for(int iclass = 0; iclass < vord.size(); iclass++)
+        for(short iclass = 0; iclass < vord.size(); iclass++)
           std::cout << " " << vord[iclass];
         std::cout << std::endl; 
       }
@@ -447,7 +447,7 @@ int main(int argc, char *argv[])
       nreclass=vuniqueclass.size();
       if(verbose_opt[0]>=1){
         std::cout << "unique classes: " << std::endl;
-        for(int iclass = 0; iclass < vuniqueclass.size(); iclass++)
+        for(short iclass = 0; iclass < vuniqueclass.size(); iclass++)
           std::cout << " " << vuniqueclass[iclass];
         std::cout << std::endl; 
         std::cout << "number of reclasses: " << nreclass << std::endl;
@@ -455,15 +455,15 @@ int main(int argc, char *argv[])
     
       if(priors_opt.size()==1){//default: equal priors for each class
         priors.resize(nclass);
-        for(int iclass=0;iclass<nclass;++iclass)
+        for(short iclass=0;iclass<nclass;++iclass)
           priors[iclass]=1.0/nclass;
       }
       assert(priors_opt.size()==1||priors_opt.size()==nclass);
 
       priorsReclass.resize(nreclass);
-      for(int iclass=0;iclass<nreclass;++iclass){
+      for(short iclass=0;iclass<nreclass;++iclass){
        priorsReclass[iclass]=0;
-       for(int ic=0;ic<nclass;++ic){
+       for(short ic=0;ic<nclass;++ic){
          if(vreclass[ic]==iclass)
            priorsReclass[iclass]+=priors[ic];
        }
@@ -473,7 +473,7 @@ int main(int argc, char *argv[])
         std::cout << "number of bands: " << nband << std::endl;
         std::cout << "number of classes: " << nclass << std::endl;
         std::cout << "priors:";
-        for(int iclass=0;iclass<nclass;++iclass)
+        for(short iclass=0;iclass<nclass;++iclass)
           std::cout << " " << priors[iclass];
         std::cout << std::endl;
       }
@@ -481,7 +481,7 @@ int main(int argc, char *argv[])
 
     //Calculate features of trainig set
     vector< Vector2d<float> > trainingFeatures(nclass);
-    for(int iclass=0;iclass<nclass;++iclass){
+    for(short iclass=0;iclass<nclass;++iclass){
       int nctraining=0;
       if(verbose_opt[0]>=1)
         std::cout << "calculating features for class " << iclass << std::endl;
@@ -508,7 +508,7 @@ int main(int argc, char *argv[])
     
     unsigned int nFeatures=trainingFeatures[0][0].size();
     unsigned int ntraining=0;
-    for(int iclass=0;iclass<nclass;++iclass){
+    for(short iclass=0;iclass<nclass;++iclass){
       //vcode has size nreclass???
       // if(verbose_opt[0]>=1)
       //   std::cout << "training sample size for class " << vcode[iclass] << 
": " << trainingFeatures[iclass].size() << std::endl;
@@ -522,7 +522,7 @@ int main(int argc, char *argv[])
     x_space[ibag] = Malloc(struct svm_node,(nFeatures+1)*ntraining);
     unsigned long int spaceIndex=0;
     int lIndex=0;
-    for(int iclass=0;iclass<nclass;++iclass){
+    for(short iclass=0;iclass<nclass;++iclass){
       for(int isample=0;isample<trainingFeatures[iclass].size();++isample){
         prob[ibag].x[lIndex]=&(x_space[ibag][spaceIndex]);
         for(int ifeature=0;ifeature<nFeatures;++ifeature){
@@ -578,7 +578,7 @@ int main(int argc, char *argv[])
       else{
         if(verbose_opt[0]>1)
           std::cout << "classes for confusion matrix: " << std::endl;
-        for(int iclass=0;iclass<nreclass;++iclass){
+        for(short iclass=0;iclass<nreclass;++iclass){
           ostringstream os;
           os << vcode[iclass];
           if(verbose_opt[0]>1)
@@ -605,7 +605,7 @@ int main(int argc, char *argv[])
       double dua=0;
       double dpa=0;
       double doa=0;
-      for(int iclass=0;iclass<cm.nClasses();++iclass){
+      for(short iclass=0;iclass<cm.nClasses();++iclass){
         dua=cm.ua_pct(cm.getClass(iclass),&se95_ua);
         dpa=cm.pa_pct(cm.getClass(iclass),&se95_pa);
         cout << cm.getClass(iclass) << " " << 
cm.nReference(cm.getClass(iclass)) << " " << dua << " (" << se95_ua << ")" << " 
" << dpa << " (" << se95_pa << ")" << endl;
@@ -809,7 +809,7 @@ int main(int argc, char *argv[])
           classOut[icol]=flag_opt[0];
           continue;//next column
         }
-        for(int iclass=0;iclass<nreclass;++iclass)
+        for(short iclass=0;iclass<nreclass;++iclass)
           prOut[iclass][icol]=0;
         //----------------------------------- classification 
-------------------
         for(int ibag=0;ibag<nbag;++ibag){
@@ -835,8 +835,8 @@ int main(int argc, char *argv[])
           float maxP=0;
           if(!aggreg_opt[0]){
             predict_label = svm_predict(svm[ibag],x);
-            for(int iclass=0;iclass<nclass;++iclass){
-              if(iclass==static_cast<int>(predict_label))
+            for(short iclass=0;iclass<nclass;++iclass){
+              if(iclass==static_cast<short>(predict_label))
                 result[iclass]=1;
               else
                 result[iclass]=0;
@@ -849,14 +849,14 @@ int main(int argc, char *argv[])
 
          reclass(result,vreclass,priors,aggreg_opt[0],prValues);
          
-          for(int iclass=0;iclass<nreclass;++iclass)
+          for(short iclass=0;iclass<nreclass;++iclass)
           //calculate posterior prob of bag 
           if(classBag_opt.size()){
             //search for max prob within bag
             maxP=0;
             classBag[ibag][icol]=0;
           }
-          for(int iclass=0;iclass<nreclass;++iclass){
+          for(short iclass=0;iclass<nreclass;++iclass){
             switch(comb_opt[0]){
             default:
             case(0)://sum rule
@@ -884,7 +884,7 @@ int main(int argc, char *argv[])
         //search for max class prob
         float maxBag=0;
         float normBag=0;
-        for(int iclass=0;iclass<nreclass;++iclass){
+        for(short iclass=0;iclass<nreclass;++iclass){
           if(prOut[iclass][icol]>maxBag){
             maxBag=prOut[iclass][icol];
             classOut[icol]=vcode[iclass];
@@ -893,7 +893,7 @@ int main(int argc, char *argv[])
         }
         //normalize prOut and convert to percentage
         if(prob_opt.size()){
-          for(int iclass=0;iclass<nreclass;++iclass){
+          for(short iclass=0;iclass<nreclass;++iclass){
             float prv=prOut[iclass][icol];
             prv/=normBag;
             prv*=100.0;
@@ -906,7 +906,7 @@ int main(int argc, char *argv[])
         for(int ibag=0;ibag<nbag;++ibag)
           classImageBag.writeData(classBag[ibag],GDT_Byte,iline,ibag);
       if(prob_opt.size()){
-        for(int iclass=0;iclass<nreclass;++iclass)
+        for(short iclass=0;iclass<nreclass;++iclass)
           probImage.writeData(prOut[iclass],GDT_Float32,iline,iclass);
       }
       classImageOut.writeData(classOut,GDT_Byte,iline);
@@ -934,7 +934,8 @@ int main(int argc, char *argv[])
       ImgWriterOgr imgWriterOgr(output_opt[ivalidation],imgReaderOgr,false);
       if(verbose_opt[0])
         std::cout << "creating field class" << std::endl;
-      imgWriterOgr.createField("class",OFTInteger);
+      // imgWriterOgr.createField("class",OFTInteger);
+      imgWriterOgr.createField("class",OFTString);
       OGRFeature *poFeature;
       unsigned int ifeature=0;
       unsigned int nFeatures=imgReaderOgr.getFeatureCount();
@@ -959,7 +960,7 @@ int main(int argc, char *argv[])
         OGRFeature::DestroyFeature( poFeature );
         assert(validationPixel.size()==nband);
         vector<float> prOut(nreclass);//posterior prob for each reclass
-        for(int iclass=0;iclass<nreclass;++iclass)
+        for(short iclass=0;iclass<nreclass;++iclass)
           prOut[iclass]=0;
         for(int ibag=0;ibag<nbag;++ibag){
           for(int iband=0;iband<nband;++iband){
@@ -984,8 +985,8 @@ int main(int argc, char *argv[])
           vector<float> prValues(nreclass);
           if(!aggreg_opt[0]){
             predict_label = svm_predict(svm[ibag],x);
-            for(int iclass=0;iclass<nclass;++iclass){
-              if(predict_label==static_cast<int>(predict_label))
+            for(short iclass=0;iclass<nclass;++iclass){
+              if(iclass==static_cast<short>(predict_label))
                 result[iclass]=1;
               else
                 result[iclass]=0;
@@ -995,11 +996,25 @@ int main(int argc, char *argv[])
             assert(svm_check_probability_model(svm[ibag]));
             predict_label = svm_predict_probability(svm[ibag],x,&(result[0]));
           }
-
+          
+          if(verbose_opt[0]>1)
+            std::cout << "predict_label: " << predict_label << std::endl;
+          if(verbose_opt[0]>1){
+            std::cout << "result before reclass: " << std::endl;
+            for(int iclass=0;iclass<result.size();++iclass)
+              std::cout << result[iclass] << " ";
+            std::cout << std::endl;
+          }
          reclass(result,vreclass,priors,aggreg_opt[0],prValues);
+          if(verbose_opt[0]>1){
+            std::cout << "prValues after reclass: " << std::endl;
+            for(int iclass=0;iclass<prValues.size();++iclass)
+              std::cout << prValues[iclass] << " ";
+            std::cout << std::endl;
+          }
 
           //calculate posterior prob of bag 
-          for(int iclass=0;iclass<nreclass;++iclass){
+          for(short iclass=0;iclass<nreclass;++iclass){
             switch(comb_opt[0]){
             default:
             case(0)://sum rule
@@ -1020,21 +1035,27 @@ int main(int argc, char *argv[])
         //search for max class prob
         float maxBag=0;
         float normBag=0;
-        char classOut=0;
-        for(int iclass=0;iclass<nreclass;++iclass){
+        short classOut=0;
+        for(short iclass=0;iclass<nreclass;++iclass){
+          if(verbose_opt[0]>1)
+            std::cout << prOut[iclass] << " ";
           if(prOut[iclass]>maxBag){
             maxBag=prOut[iclass];
             classOut=vcode[iclass];
           }
-          normBag+=prOut[iclass];
+          // normBag+=prOut[iclass];
         }
+        //look for class name
+        //todo: write class name to field "class" in output ogr file
+        if(verbose_opt[0]>1)
+          std::cout << "->" << static_cast<short>(classOut) << std::endl;
         //normalize prOut and convert to percentage
-        for(int iclass=0;iclass<nreclass;++iclass){
-          float prv=prOut[iclass];
-          prv/=normBag;
-          prv*=100.0;
-          prOut[iclass]=static_cast<short>(prv+0.5);
-        }
+        // for(int iclass=0;iclass<nreclass;++iclass){
+        //   float prv=prOut[iclass];
+        //   prv/=normBag;
+        //   prv*=100.0;
+        //   prOut[iclass]=static_cast<short>(prv+0.5);
+        // }
         poDstFeature->SetField("class",classOut);
         poDstFeature->SetFID( poFeature->GetFID() );
         CPLErrorReset();
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index 0219f72..9acaed4 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -80,13 +80,9 @@ along with pktools.  If not, see 
<http://www.gnu.org/licenses/>.
 #include "imageclasses/ImgReaderGdal.h"
 #include "imageclasses/ImgReaderOgr.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 int main(int argc, char *argv[])
 {
-  Optionpk<std::string> input_opt("i","input","Input image file","");
+  Optionpk<std::string> input_opt("i","input","Input image file");
   Optionpk<bool>  bbox_opt("bb", "bbox", "Shows bounding box ", false,1);
   Optionpk<bool>  bbox_te_opt("te", "te", "Shows bounding box in GDAL format: 
xmin ymin xmax ymax ", false,1);
   Optionpk<bool>  centre_opt("c", "centre", "Image centre in projected X,Y 
coordinates ", false,1);
@@ -109,7 +105,7 @@ int main(int argc, char *argv[])
   Optionpk<bool>  cover_opt("cov", "cover", "Image covers bounding box (or x 
and y pos) if printed to std out ", false,1);
   Optionpk<double>  x_opt("x", "xpos", "x pos");
   Optionpk<double>  y_opt("y", "ypos", "y pos");
-  Optionpk<bool>  read_opt("r", "read", "Reads row y (in projected coordinates 
if geo option is set, otherwise in image coordinates, 0 based)", 0,1);
+  Optionpk<bool>  read_opt("r", "read", "Reads row y (in projected coordinates 
if geo option is set, otherwise in image coordinates, 0 based)",false,1);
   Optionpk<bool>  refpixel_opt("ref", "ref", "Gets reference pixel (lower left 
corner of centre of gravity pixel)", false,1);
   Optionpk<bool>  driver_opt("of", "oformat", "Gets driver description ", 
false,1);
   Optionpk<std::string>  extent_opt("e", "extent", "Gets boundary from extent 
from polygons in vector file");
@@ -467,7 +463,8 @@ int main(int argc, char *argv[])
     else
       std::cout << "no intersect" << std::endl;
   }
-  //    std::cout << "bounding box mosaic (ULX ULY LRX LRY): " << minULX << " 
" << maxULY << " " << maxLRX << " " << minLRY << std::endl;
-  if(!read_opt[0]&&!hist_opt[0])
+  if(!input_opt.size())
+    std::cerr << "No input file provided (use option -i). Use pkinfo --help 
for help information" << std::endl;
+  else if(!read_opt[0]&&!hist_opt[0])
     std::cout << std::endl;
 }
diff --git a/src/base/Makefile.am b/src/base/Makefile.am
index 370b15b..3c1a63b 100644
--- a/src/base/Makefile.am
+++ b/src/base/Makefile.am
@@ -1,3 +1,11 @@
+###############################################################################
+# THE PROGRAMS TO BUILD
+###############################################################################
+
+# the program to build (the names of the final binaries)
+#do not want to install pktestoption
+noinst_PROGRAMS = pktestOption  
+
 # additional include pathes necessary to compile the C++ library
 AM_CXXFLAGS = -I$(top_srcdir)/src @AM_CXXFLAGS@
 
@@ -18,6 +26,9 @@ libbase_a_HEADERS = PointData.h
 libbase_a_SOURCES = $(libbase_a_HEADERS) PointData.cc
 ###############################################################################
 
+# list of sources for the binaries
+pktestOption_SOURCES = pktestOption.cc
+
 ###############################################################################
 # HEADERS USED FOR BUILDING BUT NOT TO BE INSTALLED
 ###############################################################################
diff --git a/src/base/Makefile.in b/src/base/Makefile.in
index ab89956..a0ddf10 100644
--- a/src/base/Makefile.in
+++ b/src/base/Makefile.in
@@ -15,6 +15,11 @@
 
 @SET_MAKE@
 
+###############################################################################
+# THE PROGRAMS TO BUILD
+###############################################################################
+
+
 
 VPATH = @srcdir@
 pkgdatadir = $(datadir)/@PACKAGE@
@@ -33,6 +38,7 @@ POST_INSTALL = :
 NORMAL_UNINSTALL = :
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+noinst_PROGRAMS = pktestOption$(EXEEXT)
 subdir = src/base
 DIST_COMMON = $(libbase_a_HEADERS) $(noinst_HEADERS) \
        $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@@ -53,6 +59,10 @@ libbase_a_LIBADD =
 am__objects_1 =
 am_libbase_a_OBJECTS = $(am__objects_1) PointData.$(OBJEXT)
 libbase_a_OBJECTS = $(am_libbase_a_OBJECTS)
+PROGRAMS = $(noinst_PROGRAMS)
+am_pktestOption_OBJECTS = pktestOption.$(OBJEXT)
+pktestOption_OBJECTS = $(am_pktestOption_OBJECTS)
+pktestOption_LDADD = $(LDADD)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
@@ -66,8 +76,8 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-SOURCES = $(libbase_a_SOURCES)
-DIST_SOURCES = $(libbase_a_SOURCES)
+SOURCES = $(libbase_a_SOURCES) $(pktestOption_SOURCES)
+DIST_SOURCES = $(libbase_a_SOURCES) $(pktestOption_SOURCES)
 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 am__vpath_adj = case $$p in \
     $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@@ -224,6 +234,9 @@ libbase_a_HEADERS = PointData.h
 libbase_a_SOURCES = $(libbase_a_HEADERS) PointData.cc
 ###############################################################################
 
+# list of sources for the binaries
+pktestOption_SOURCES = pktestOption.cc
+
 ###############################################################################
 # HEADERS USED FOR BUILDING BUT NOT TO BE INSTALLED
 ###############################################################################
@@ -270,6 +283,12 @@ libbase.a: $(libbase_a_OBJECTS) $(libbase_a_DEPENDENCIES)
        $(libbase_a_AR) libbase.a $(libbase_a_OBJECTS) $(libbase_a_LIBADD)
        $(RANLIB) libbase.a
 
+clean-noinstPROGRAMS:
+       -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
+pktestOption$(EXEEXT): $(pktestOption_OBJECTS) $(pktestOption_DEPENDENCIES) 
+       @rm -f pktestOption$(EXEEXT)
+       $(CXXLINK) $(pktestOption_OBJECTS) $(pktestOption_LDADD) $(LIBS)
+
 mostlyclean-compile:
        -rm -f *.$(OBJEXT)
 
@@ -277,6 +296,7 @@ distclean-compile:
        -rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PointData.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pktestOption.Po@am__quote@
 
 .cc.o:
 @am__fastdepCXX_TRUE@  $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o 
$@ $<
@@ -396,7 +416,7 @@ distdir: $(DISTFILES)
        done
 check-am: all-am
 check: check-am
-all-am: Makefile $(LIBRARIES) $(HEADERS)
+all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(HEADERS)
 installdirs:
        for dir in "$(DESTDIR)$(libbase_adir)"; do \
          test -z "$$dir" || $(MKDIR_P) "$$dir"; \
@@ -428,7 +448,8 @@ maintainer-clean-generic:
        @echo "it deletes files that may require special tools to rebuild."
 clean: clean-am
 
-clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
+clean-am: clean-generic clean-noinstLIBRARIES clean-noinstPROGRAMS \
+       mostlyclean-am
 
 distclean: distclean-am
        -rm -rf ./$(DEPDIR)
@@ -498,17 +519,18 @@ uninstall-am: uninstall-libbase_aHEADERS
 .MAKE: install-am install-strip
 
 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
-       clean-noinstLIBRARIES ctags distclean distclean-compile \
-       distclean-generic distclean-tags distdir dvi dvi-am html \
-       html-am info info-am install install-am install-data \
-       install-data-am install-dvi install-dvi-am install-exec \
-       install-exec-am install-html install-html-am install-info \
-       install-info-am install-libbase_aHEADERS install-man \
-       install-pdf install-pdf-am install-ps install-ps-am \
-       install-strip installcheck installcheck-am installdirs \
-       maintainer-clean maintainer-clean-generic mostlyclean \
-       mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
-       tags uninstall uninstall-am uninstall-libbase_aHEADERS
+       clean-noinstLIBRARIES clean-noinstPROGRAMS ctags distclean \
+       distclean-compile distclean-generic distclean-tags distdir dvi \
+       dvi-am html html-am info info-am install install-am \
+       install-data install-data-am install-dvi install-dvi-am \
+       install-exec install-exec-am install-html install-html-am \
+       install-info install-info-am install-libbase_aHEADERS \
+       install-man install-pdf install-pdf-am install-ps \
+       install-ps-am install-strip installcheck installcheck-am \
+       installdirs maintainer-clean maintainer-clean-generic \
+       mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \
+       ps ps-am tags uninstall uninstall-am \
+       uninstall-libbase_aHEADERS
 
 ###############################################################################
 
diff --git a/src/base/Optionpk.h b/src/base/Optionpk.h
index 11379d9..4b9fbdd 100644
--- a/src/base/Optionpk.h
+++ b/src/base/Optionpk.h
@@ -122,6 +122,73 @@ template<> inline std::string type2string(double const& 
value){
   return oss.str();
 }
 
+/**
+Class to implement command line options. With the constructor you can define 
an option, in both short `-` and long `--` format, of a specific type, help 
information and a default value.\n
+This class inherits from std::vector, so the option variable is a vector, 
supporting multiple inputs for the same option (e.g., --input file1 [--input 
file2 ...].
+Several command line option formats are supported: 
+- `-shortOption value`
+- `-shortOption=value`
+- `--longOption value`
+- `--longOption=value`
+- `-shortOption` (no value for boolean options, which are automatically set by 
invoking the option)
+- `--longOption` (no value for boolean options, which are automatically set by 
invoking the option)
+
+Option names should have regular characters and no white space in them. Some 
names are reserved and can not be used either:
+- short option `h` or long option `help`: shows help info
+- long option `license`: shows license info
+- long option `version`: shows current version of pktools
+- long option `doxygen`: shows help info in table format, ready to be included 
in doxygen
+
+A call to member function \ref retrieveOption reads the command line arguments 
and initializes the object (vector). Make sure to call this member function 
before using the option object in your main program (or a segmentation error 
due to an un-initialized vector will occur).
+
+All calls to retrieveOption should reside in a try{} block. If one of the 
reserved options
+- `license`
+- `version`
+is used, an exception of type std::string is thrown. This can be caught with a 
catch(string predefinedString) right after the try block, where the message can 
be sent to stdout and the program can be ended.
+
+Similarly, if help is invoked with the short option `-h` or long option 
`--help`, the main program is informed by the return value `false` of \ref 
retrieveOption (for any option). Thus, a typical use of \ref Optionpk would 
look like:
+
+~~~
+#include <iostream>
+#include <string>
+#include "base/Optionpk.h"
+
+int main(int argc, char *argv[])
+{
+  Optionpk<std::string> foo_opt("f","foo","command line option **foo** of type 
string can be invoked with either short (f) or long (foo) 
option","defaultString");
+  Optionpk<int> bar_opt("\0","bar","command line option **bar** of type int 
has no short option",false,1);//bar will only be visible in long help (hide=1)
+  Optionpk<bool> easterEgg_opt("egg","egg","this help information is 
useless",false,2);//this option will not be shown in help (hide=2)
+
+  bool doProcess;//stop process when program was invoked with help option (-h 
--help)
+  try{
+    doProcess=foo_opt.retrieveOption(argc,argv);
+    bar_opt.retrieveOption(argc,argv);
+    easterEgg_opt.retrieveOption(argc,argv);
+    }
+  catch(std::string predefinedString){//command line option contained license 
or version
+    std::cout << predefinedString << std::endl;//report the predefined string 
to stdout
+    exit(0);//stop processing
+  }
+  if(!doProcess){//command line option contained help option
+    std::cout << "short option -h shows basic options only, use long option 
--help to show all options" << std::endl;//provide extra details for help to 
the user
+    exit(0);//stop processing
+  }
+  std::cout << "foo: ";
+  for(int ifoo=0;ifoo<foo_opt.size();++ifoo){
+    std::cout << foo_opt[ifoo] << " ";
+  }
+  std::cout << std::endl;
+  std::cout << foo_opt << std::endl;//short cut for code above
+
+  if(bar_opt[0]>0)
+    std::cout << "long option for bar was used with a positive value" << 
std::endl;
+  
+  if(easterEgg_opt[0])
+    std::cout << "How did you find this option -egg or --egg? Not through the 
help info!" << std::endl;
+}
+~~~
+**/
+
 template<class T> class Optionpk : public std::vector <T>
 {
 public:
@@ -198,7 +265,6 @@ constructor without default value\n
 shortName is option invoked with `-`\n
 longName is option invoked with `--`\n
 helpInfo is the help message that is shown when option -h or --help is 
invoked\n
-When the constructor without default value is used, the option is only visible 
in long help (`--help`), i.e., hide=1
 **/
 template<class T> Optionpk<T>::Optionpk(const std::string& shortName, const 
std::string& longName, const std::string& helpInfo)
 : m_hasDefault(false)
@@ -206,7 +272,7 @@ template<class T> Optionpk<T>::Optionpk(const std::string& 
shortName, const std:
   setAll(shortName,longName,helpInfo);
 }
 
-/*!
+/**
 constructor with default value.\n
 shortName is option invoked with `-`\n
 longName is option invoked with `--`\n
@@ -215,7 +281,7 @@ defaultValue is default value of the option (first value of 
vector: option[0])\n
 hide=0 : option is visible for in both short (`-h`) and long (`--help`) help. 
Typical use: mandatory options\n
 hide=1 : option is only visible in long help (`--help`). Typical use: expert 
options\n
 hide=2 : option is hidden for user. Typical use: Easter eggs or options only 
known to author
-*/
+**/
 template<class T> Optionpk<T>::Optionpk(const std::string& shortName, const 
std::string& longName, const std::string& helpInfo,const T& defaultValue, short 
hide)
 {
   setAll(shortName,longName,helpInfo,defaultValue, hide);
@@ -272,7 +338,7 @@ template<class T> void Optionpk<T>::setAll(const 
std::string& shortName, const s
   m_longName=longName;
   m_hasArgument=true;
   m_help=helpInfo;
-  m_hide=1;
+  m_hide=0;
 }
 
 template<class T> void Optionpk<T>::setAll(const std::string& shortName, const 
std::string& longName, const std::string& helpInfo,const T& defaultValue, short 
hide)

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-grass/pktools.git

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to