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