ctkVTKCommandOptions.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. /*=========================================================================
  11. Program: ParaView
  12. Module: $RCSfile: vtkCommandOptions.h,v $
  13. Copyright (c) Kitware, Inc.
  14. All rights reserved.
  15. See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
  16. This software is distributed WITHOUT ANY WARRANTY; without even
  17. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  18. PURPOSE. See the above copyright notice for more information.
  19. =========================================================================*/
  20. #ifndef __ctkVTKCommandOptions_h
  21. #define __ctkVTKCommandOptions_h
  22. // Qt includes
  23. #include <QStringList>
  24. // CTK includes
  25. #include <ctkPimpl.h>
  26. // STD includes
  27. #include <vector>
  28. #include <string>
  29. #include "CTKVisualizationVTKCoreExport.h"
  30. class QSettings;
  31. class ctkVTKCommandOptionsPrivate;
  32. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKCommandOptions
  33. {
  34. public:
  35. /// Constructors
  36. explicit ctkVTKCommandOptions(QSettings* _settings);
  37. virtual ~ctkVTKCommandOptions();
  38. virtual void printAdditionalInfo();
  39. enum
  40. {
  41. ALL = 0,
  42. QSETTINGS_ONLY = 0x1
  43. };
  44. ///
  45. /// Parse the arguments
  46. bool parse(int argc, const char* const argv[]);
  47. ///
  48. /// If parse return False, this function will return the unparsed arguments
  49. QStringList remainingArguments();
  50. void remainingArguments(int* argc, char*** argv);
  51. ///
  52. /// Return True if flag '--ignore-rest' has been specified
  53. bool ignoreRest()const;
  54. ///
  55. /// If any, return the list of ignored arguments
  56. QStringList ignoredArguments()const;
  57. ///
  58. /// Get the index of the last parsed argument.
  59. int indexOfLastParsedArgument();
  60. ///
  61. /// Was help selected?
  62. bool helpSelected()const;
  63. QString help();
  64. ///
  65. /// Should user settings be considered ?
  66. bool disableSettings()const;
  67. ///
  68. /// Set/Get the type of the process for this set of options.
  69. /// GUI application, Batch, Daemon, etc ...
  70. int processType()const;
  71. void setProcessType(int p);
  72. ///
  73. /// Convenient method to get associated Settings object
  74. QSettings* settings()const;
  75. ///
  76. /// In case of unknown argument, return its name.
  77. QString unknownArgument()const;
  78. ///
  79. /// Get the error message if Parse returned 0.
  80. QString errorMessage()const;
  81. protected:
  82. /// Add a command line argument.
  83. /// For each argument added there is a long version --long and a short version -l,
  84. /// a help string, and a variable that is set to the value of the option.
  85. /// The types can be int, QString, boolean (set to 1 if argument is present) or QStringList.
  86. /// Also deprecated arguments can be added with only a help string. The help
  87. /// string should say that the argument is deprecated and suggest the
  88. /// alternative argument to use.
  89. void addBooleanArgument(const char* longarg, const char* shortarg,
  90. bool* var, const char* arghelp, bool defaultValue = false,
  91. int type=ALL);
  92. void addDeprecatedArgument(const char* longarg, const char* shortarg,
  93. const char* arghelp, int type=ALL);
  94. void addArgument(const char* longarg, const char* shortarg,
  95. int* var, const char* arghelp, int defaultValue = 0, int type=ALL);
  96. void addArgument(const char* longarg, const char* shortarg,
  97. QString* var, const char* arghelp,
  98. const QString& defaultValue = QString(), int type=ALL);
  99. void addArgument(const char* longarg, const char* shortarg,
  100. QStringList* var, const char* arghelp,
  101. const QStringList& defaultValue = QStringList(), int type=ALL);
  102. /// Initialize arguments.
  103. virtual void initialize();
  104. /// Disable current settings
  105. virtual void disableCurrentSettings() = 0;
  106. ///
  107. /// After parsing, process extra option dependencies.
  108. virtual bool postProcess(int argc, const char* const* argv);
  109. /// This method is called when wrong argument is found. If it returns False, then
  110. /// the parsing will fail.
  111. virtual bool wrongArgument(const char* argument);
  112. /// This method is called when a deprecated argument is found. If it returns False, then
  113. /// the parsing will fail.
  114. virtual bool deprecatedArgument(const char* argument);
  115. private:
  116. CTK_DECLARE_PRIVATE(ctkVTKCommandOptions);
  117. };
  118. #endif