CmdLineInterface.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
  2. /******************************************************************************
  3. *
  4. * file: CmdLineInterface.h
  5. *
  6. * Copyright (c) 2003, Michael E. Smoot .
  7. * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
  8. * Copyright (c) 2017, Google LLC
  9. * All rights reserved.
  10. *
  11. * See the file COPYING in the top directory of this distribution for
  12. * more information.
  13. *
  14. * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. *
  22. *****************************************************************************/
  23. #ifndef TCLAP_COMMANDLINE_INTERFACE_H
  24. #define TCLAP_COMMANDLINE_INTERFACE_H
  25. #include <string>
  26. #include <vector>
  27. #include <list>
  28. #include <iostream>
  29. #include <algorithm>
  30. namespace TCLAP {
  31. class Arg;
  32. class CmdLineOutput;
  33. class XorHandler;
  34. /**
  35. * The base class that manages the command line definition and passes
  36. * along the parsing to the appropriate Arg classes.
  37. */
  38. class CmdLineInterface
  39. {
  40. public:
  41. /**
  42. * Destructor
  43. */
  44. virtual ~CmdLineInterface() {}
  45. /**
  46. * Adds an argument to the list of arguments to be parsed.
  47. * \param a - Argument to be added.
  48. */
  49. virtual void add( Arg& a )=0;
  50. /**
  51. * An alternative add. Functionally identical.
  52. * \param a - Argument to be added.
  53. */
  54. virtual void add( Arg* a )=0;
  55. /**
  56. * Add two Args that will be xor'd.
  57. * If this method is used, add does
  58. * not need to be called.
  59. * \param a - Argument to be added and xor'd.
  60. * \param b - Argument to be added and xor'd.
  61. */
  62. virtual void xorAdd( Arg& a, Arg& b )=0;
  63. /**
  64. * Add a list of Args that will be xor'd. If this method is used,
  65. * add does not need to be called.
  66. * \param xors - List of Args to be added and xor'd.
  67. */
  68. virtual void xorAdd( const std::vector<Arg*>& xors )=0;
  69. /**
  70. * Parses the command line.
  71. * \param argc - Number of arguments.
  72. * \param argv - Array of arguments.
  73. */
  74. virtual void parse(int argc, const char * const * argv)=0;
  75. /**
  76. * Parses the command line.
  77. * \param args - A vector of strings representing the args.
  78. * args[0] is still the program name.
  79. */
  80. void parse(std::vector<std::string>& args);
  81. /**
  82. * Returns the CmdLineOutput object.
  83. */
  84. virtual CmdLineOutput* getOutput()=0;
  85. /**
  86. * \param co - CmdLineOutput object that we want to use instead.
  87. */
  88. virtual void setOutput(CmdLineOutput* co)=0;
  89. /**
  90. * Returns the version string.
  91. */
  92. virtual std::string& getVersion()=0;
  93. /**
  94. * Returns the program name string.
  95. */
  96. virtual std::string& getProgramName()=0;
  97. /**
  98. * Returns the argList.
  99. */
  100. virtual std::list<Arg*>& getArgList()=0;
  101. /**
  102. * Returns the XorHandler.
  103. */
  104. virtual XorHandler& getXorHandler()=0;
  105. /**
  106. * Returns the delimiter string.
  107. */
  108. virtual char getDelimiter()=0;
  109. /**
  110. * Returns the message string.
  111. */
  112. virtual std::string& getMessage()=0;
  113. /**
  114. * Indicates whether or not the help and version switches were created
  115. * automatically.
  116. */
  117. virtual bool hasHelpAndVersion()=0;
  118. /**
  119. * Resets the instance as if it had just been constructed so that the
  120. * instance can be reused.
  121. */
  122. virtual void reset()=0;
  123. };
  124. } //namespace
  125. #endif