GetoptParser.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00024 //----------------------------------------------------------------------
00025 #ifndef ICL_CORE_CONFIG_GETOPT_PARSER_H_INCLUDED
00026 #define ICL_CORE_CONFIG_GETOPT_PARSER_H_INCLUDED
00027 
00028 #include "icl_core/BaseTypes.h"
00029 #include "icl_core/Deprecate.h"
00030 #include "icl_core/List.h"
00031 #include "icl_core/Map.h"
00032 #include "icl_core/Vector.h"
00033 #include "icl_core_config/ImportExport.h"
00034 #include "icl_core_config/GetoptParameter.h"
00035 #include "icl_core_config/GetoptPositionalParameter.h"
00036 
00037 namespace icl_core {
00038 namespace config {
00039 
00054 class ICL_CORE_CONFIG_IMPORT_EXPORT Getopt
00055 {
00056 public:
00057   enum ParameterRegistrationCheck
00058   {
00059     ePRC_Strict, 
00060     ePRC_Relaxed 
00061   };
00062   typedef ICL_CORE_VC_DEPRECATE ParameterRegistrationCheck tParameterRegistrationCheck ICL_CORE_GCC_DEPRECATE;
00063 
00064   enum CommandLineCleaning
00065   {
00066     eCLC_None,   
00067     eCLC_Cleanup 
00068   };
00069   typedef ICL_CORE_VC_DEPRECATE CommandLineCleaning tCommandLineCleaning ICL_CORE_GCC_DEPRECATE;
00070 
00071   struct KeyValue
00072   {
00073     KeyValue(const icl_core::String& key, const icl_core::String& value)
00074       : m_key(key),
00075         m_value(value)
00076     { }
00077 
00078     icl_core::String m_key;
00079     icl_core::String m_value;
00080   };
00081   typedef icl_core::List<KeyValue> KeyValueList;
00082 
00085   static Getopt& instance();
00086 
00091   void activateExtraCmdParams(const icl_core::String& delimiter = "--");
00092 
00095   void addParameter(const GetoptParameter& parameter);
00096 
00099   void addParameter(const GetoptParameterList& parameters);
00100 
00103   void addParameter(const GetoptPositionalParameter& parameter);
00104 
00108   void addParameter(const GetoptPositionalParameterList& parameters);
00109 
00116   bool initialize(int& argc, char *argv[], bool remove_read_arguments);
00117 
00130   bool initialize(int& argc, char *argv[], CommandLineCleaning cleanup = eCLC_None,
00131                   ParameterRegistrationCheck registration_check = ePRC_Strict);
00132 
00135   bool isInitialized() const { return m_initialized; }
00136 
00138   int &argc();
00139 
00141   char** argv() const;
00142 
00145   icl_core::String extraCmdParam(size_t index) const;
00146 
00149   size_t extraCmdParamCount() const;
00150 
00156   icl_core::String paramOpt(const icl_core::String& name) const;
00157 
00160   bool paramOptPresent(const icl_core::String& name) const;
00161 
00164   KeyValueList paramPrefixOpt(const icl_core::String& prefix) const;
00165 
00168   bool paramPrefixOptPresent(const icl_core::String& prefix) const;
00169 
00174   icl_core::String paramNonOpt(size_t index) const;
00175 
00178   size_t paramNonOptCount() const;
00179 
00182   icl_core::String programName() const;
00183 
00186   icl_core::String programVersion() const;
00187 
00190   void setProgramVersion(icl_core::String const & version);
00191 
00194   void setProgramDescription(icl_core::String const & description);
00195 
00198   icl_core::String programDescription() const;
00199 
00202   void printHelp() const;
00203 
00205 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00206 
00210   ICL_CORE_VC_DEPRECATE_STYLE static Getopt& Instance() ICL_CORE_GCC_DEPRECATE_STYLE;
00211 
00215   ICL_CORE_VC_DEPRECATE_STYLE void ActivateExtraCmdParams(const icl_core::String& delimiter = "--")
00216     ICL_CORE_GCC_DEPRECATE_STYLE;
00217 
00221   ICL_CORE_VC_DEPRECATE_STYLE void AddParameter(const GetoptParameter& parameter)
00222     ICL_CORE_GCC_DEPRECATE_STYLE;
00223 
00227   ICL_CORE_VC_DEPRECATE_STYLE void AddParameter(const GetoptParameterList& parameters)
00228     ICL_CORE_GCC_DEPRECATE_STYLE;
00229 
00233   ICL_CORE_VC_DEPRECATE_STYLE bool Initialize(int& argc, char *argv[], bool remove_read_arguments)
00234     ICL_CORE_GCC_DEPRECATE_STYLE;
00235 
00239   ICL_CORE_VC_DEPRECATE_STYLE bool Initialize(int& argc, char *argv[],
00240                                               CommandLineCleaning cleanup = eCLC_None,
00241                                               ParameterRegistrationCheck registration_check = ePRC_Strict)
00242     ICL_CORE_GCC_DEPRECATE_STYLE;
00243 
00247   ICL_CORE_VC_DEPRECATE_STYLE bool IsInitialized() const ICL_CORE_GCC_DEPRECATE_STYLE;
00248 
00252   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String ExtraCmdParam(size_t index) const
00253     ICL_CORE_GCC_DEPRECATE_STYLE;
00254 
00258   ICL_CORE_VC_DEPRECATE_STYLE size_t ExtraCmdParamCount() const ICL_CORE_GCC_DEPRECATE_STYLE;
00259 
00263   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String ParamOpt(const icl_core::String& name) const
00264     ICL_CORE_GCC_DEPRECATE_STYLE;
00265 
00269   ICL_CORE_VC_DEPRECATE_STYLE bool ParamOptPresent(const icl_core::String& name) const
00270     ICL_CORE_GCC_DEPRECATE_STYLE;
00271 
00275   ICL_CORE_VC_DEPRECATE_STYLE KeyValueList ParamPrefixOpt(const icl_core::String& prefix) const
00276     ICL_CORE_GCC_DEPRECATE_STYLE;
00277 
00281   ICL_CORE_VC_DEPRECATE_STYLE bool ParamPrefixOptPresent(const icl_core::String& prefix) const
00282     ICL_CORE_GCC_DEPRECATE_STYLE;
00283 
00287   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String ParamNonOpt(size_t index) const ICL_CORE_GCC_DEPRECATE_STYLE;
00288 
00292   ICL_CORE_VC_DEPRECATE_STYLE size_t ParamNonOptCount() const ICL_CORE_GCC_DEPRECATE_STYLE;
00293 
00297   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String ProgramName() const ICL_CORE_GCC_DEPRECATE_STYLE;
00298 
00302   ICL_CORE_VC_DEPRECATE_STYLE void PrintHelp() const ICL_CORE_GCC_DEPRECATE_STYLE;
00303 
00304 #endif
00305 
00306 
00307 private:
00308   Getopt();
00309 
00310   typedef icl_core::Map<icl_core::String, GetoptParameter> ParameterMap;
00311   ParameterMap m_parameters;
00312   ParameterMap m_prefix_parameters;
00313   ParameterMap m_short_parameters;
00314   ParameterMap m_short_prefix_parameters;
00315   GetoptPositionalParameterList m_required_positional_parameters;
00316   GetoptPositionalParameterList m_optional_positional_parameters;
00317   bool m_extra_cmd_param_activated;
00318   icl_core::String m_extra_cmd_param_delimiter;
00319 
00320   bool m_initialized;
00321 
00322   int m_argc;
00323   char** m_argv;
00324   icl_core::String m_program_name;
00325   icl_core::String m_program_version;
00326   icl_core::String m_program_description;
00327   icl_core::Vector<icl_core::String> m_param_non_opt;
00328   icl_core::Map<icl_core::String, icl_core::String> m_param_opt;
00329   icl_core::Map<icl_core::String, KeyValueList> m_prefix_param_opt;
00330   icl_core::Vector<icl_core::String> m_extra_cmd_param;
00331 };
00332 
00333 }
00334 }
00335 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03