pktools  2.6.4
Processing Kernel for geospatial data
Optionpk.cc
1 /**********************************************************************
2 Optionpk.cc: source file used for specialization of template class
3 Optionpk defined in Optionpk.h
4 Copyright (C) 2008-2014 Pieter Kempeneers
5 
6 This file is part of pktools
7 
8 pktools is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 pktools is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with pktools. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #include "base/Optionpk.h"
23 
25 template<> inline std::string string2type(std::string const& s){
26  return s;
27 }
28 
30 template<> inline OGRFieldType string2type(std::string const& s){
31  OGRFieldType ftype;
32  int ogr_typecount=11;//hard coded for now!
33  for(int iType = 0; iType < ogr_typecount; ++iType){
34  if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
35  && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),s.c_str()))
36  ftype=(OGRFieldType) iType;
37  }
38  return ftype;
39 }
40 
42 template<> inline std::string type2string(bool const& value){
43  if(value)
44  return("true");
45  else
46  return("false");
47 }
48 
50 template<> inline std::string type2string(std::string const& value){
51  // if(value.empty())
52  // return("<empty string>");
53  // else
54  return(value);
55 }
56 
58 template<> inline std::string type2string(float const& value){
59  std::ostringstream oss;
60  // oss.precision(1);
61  // oss.setf(ios::fixed);
62  oss << value;
63  return oss.str();
64 }
65 
67 template<> inline std::string type2string(double const& value){
68  std::ostringstream oss;
69  // oss.precision(1);
70  // oss.setf(ios::fixed);
71  oss << value;
72  return oss.str();
73 }
74 
76 template<> inline void Optionpk<bool>::setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo);
77 
78 template<> inline void Optionpk<bool>::setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo)
79 {
80  m_shortName=shortName;
81  m_longName=longName;
82  m_hasArgument=false;
83  m_help=helpInfo;
84  m_hide=0;
85 }
86 
88 template<> inline void Optionpk<bool>::setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo,const bool& defaultValue, short hide);
89 
91 template<> inline void Optionpk<bool>::setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo,const bool& defaultValue, short hide)
92 {
93  m_shortName=shortName;
94  m_longName=longName;
95  m_hasArgument=false;
96  m_help=helpInfo;
97  m_defaultValue=defaultValue;
98  m_hasDefault=true;
99  m_hide=hide;
100 }
101 
103 template<> inline Optionpk<bool>::Optionpk(const std::string& shortName, const std::string& longName, const std::string& helpInfo,const bool& defaultValue, short hide)
104 {
105  setAll(shortName,longName,helpInfo,defaultValue, hide);
106 }
107 
108 //specialization (only makes sense for T=std::string), generic function throws exception
109 //find a substring in string option (e.g., option is of type -co INTERLEAVE=BAND)
110 template<> inline std::vector<std::string>::const_iterator Optionpk<std::string>::findSubstring(const std::string& argument) const{
111  std::vector<std::string>::const_iterator opit=this->begin();
112  while(opit!=this->end()){
113  if(opit->find(argument)!=std::string::npos)
114  break;
115  ++opit;
116  }
117  return opit;
118 }
Optionpk()
default constructor
Definition: Optionpk.h:198
std::vector< T >::const_iterator findSubstring(const T &argument) const
Definition: Optionpk.h:160
void setAll(const std::string &shortName, const std::string &longName, const std::string &helpInfo)
set all attributes of the option, except default and hide
Definition: Optionpk.h:277