VersionVisitor.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
  2. /******************************************************************************
  3. *
  4. * file: VersionVisitor.h
  5. *
  6. * Copyright (c) 2003, Michael E. Smoot .
  7. * All rights reserved.
  8. *
  9. * See the file COPYING in the top directory of this distribution for
  10. * more information.
  11. *
  12. * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. * DEALINGS IN THE SOFTWARE.
  19. *
  20. *****************************************************************************/
  21. #ifndef TCLAP_VERSION_VISITOR_H
  22. #define TCLAP_VERSION_VISITOR_H
  23. #include <tclap/CmdLineInterface.h>
  24. #include <tclap/CmdLineOutput.h>
  25. #include <tclap/Visitor.h>
  26. namespace TCLAP {
  27. /**
  28. * A Visitor that will call the version method of the given CmdLineOutput
  29. * for the specified CmdLine object and then exit.
  30. */
  31. class VersionVisitor: public Visitor
  32. {
  33. private:
  34. /**
  35. * Prevent accidental copying
  36. */
  37. VersionVisitor(const VersionVisitor& rhs);
  38. VersionVisitor& operator=(const VersionVisitor& rhs);
  39. protected:
  40. /**
  41. * The CmdLine of interest.
  42. */
  43. CmdLineInterface* _cmd;
  44. /**
  45. * The output object.
  46. */
  47. CmdLineOutput** _out;
  48. public:
  49. /**
  50. * Constructor.
  51. * \param cmd - The CmdLine the output is generated for.
  52. * \param out - The type of output.
  53. */
  54. VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out )
  55. : Visitor(), _cmd( cmd ), _out( out ) { }
  56. /**
  57. * Calls the version method of the output object using the
  58. * specified CmdLine.
  59. */
  60. void visit() {
  61. (*_out)->version(*_cmd);
  62. throw ExitException(0);
  63. }
  64. };
  65. }
  66. #endif