IODA Bundle
ToolRunnerApplication.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file ToolRunnerApplication.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, Feb 2009
14 
15 #include "eckit/filesystem/PathName.h"
16 
17 #include "odc/tools/Tool.h"
18 #include "odc/tools/ToolFactory.h"
20 
21 using namespace eckit;
22 
23 namespace odc {
24 namespace tool {
25 
26 ToolRunnerApplication::ToolRunnerApplication (int argc, char **argv, bool createCommandLineTool, bool deleteTool)
27 : ODBApplication(argc, argv),
28  tool_(!createCommandLineTool ? 0 : AbstractToolFactory::createTool(PathName(argv[1]).baseName(), argc - 1, argv + 1)),
29  deleteTool_(deleteTool)
30 {}
31 
33 : ODBApplication(argc, argv),
34  tool_(&tool),
35  deleteTool_(false)
36 {}
37 
39 {
40  if (deleteTool_) delete tool_;
41 }
42 
44 {
45  tool_ = tool;
46 }
47 
49 {
50  if (tool_ == 0)
51  {
52  std::cerr << name() << ": Unknown command '" << argv(1) << "'" << std::endl;
53  return;
54  }
55 
56  tool_->run();
57 
58  if (deleteTool_)
59  {
60  delete tool_;
61  tool_ = 0;
62  }
63 }
64 
65 
66 int ToolRunnerApplication::printHelp(std::ostream &out)
67 {
68  if (tool_ == 0)
69  {
70  std::cerr << name() << ": Unknown command '" << argv(1) << "'" << std::endl;
71  return 1;
72  }
73  //tool_->help(out);
74  return 0;
75 }
76 
77 } // namespace tool
78 } // namespace odc
79 
virtual void run()=0
ToolRunnerApplication(int argc, char **argv, bool createCommandLineTool=true, bool deleteTool=true)
Definition: ColumnInfo.h:23