IODA Bundle
ToolFactory.h
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 #ifndef ToolFactory_H
11 #define ToolFactory_H
12 
13 //#include "TestCase.h"
14 
15 namespace odc {
16 namespace tool {
17 
18  namespace test { class TestCase; }
19  class Tool;
20 
22 public:
23  static Tool* createTool(const std::string& name, int argc, char **argv);
24 
25  static void printToolHelp(const std::string&, std::ostream &);
26  static void printToolUsage(const std::string& name, std::ostream &);
27  static void printToolsHelp(std::ostream &);
28  static std::vector<odc::tool::test::TestCase*>* testCases(const std::vector<std::string>& = matchAll);
29 
30  static void listTools(std::ostream&);
31 
32  virtual Tool* create(int argc, char **argv) = 0;
33 
34  virtual void help(std::ostream &) = 0;
35  virtual void usage(const std::string&, std::ostream &) = 0;
36  virtual bool experimental() = 0;
37 
38 protected:
39  AbstractToolFactory(const std::string& name);
40  virtual ~AbstractToolFactory ();
41 
42 private:
43  static AbstractToolFactory& findTool(const std::string &name);
44  static std::map<std::string, AbstractToolFactory *> *toolFactories;
45  static const std::vector<std::string> matchAll;
46 };
47 
48 
49 template <class T>
51 public:
52  ToolFactory (const std::string& name) : AbstractToolFactory(name) {}
53 
54  Tool* create(int argc, char **argv) { return new T(argc, argv); }
55 
56  void help(std::ostream &o) { T::help(o); }
57  void usage(const std::string &name, std::ostream &o) { T::usage(name, o); }
59 };
60 
61 } // namespace tool
62 } // namespace odc
63 
64 #endif
65 
static void printToolHelp(const std::string &, std::ostream &)
Definition: ToolFactory.cc:89
static AbstractToolFactory & findTool(const std::string &name)
Definition: ToolFactory.cc:78
static std::vector< odc::tool::test::TestCase * > * testCases(const std::vector< std::string > &=matchAll)
Definition: ToolFactory.cc:42
static std::map< std::string, AbstractToolFactory * > * toolFactories
Definition: ToolFactory.h:44
static void listTools(std::ostream &)
Definition: ToolFactory.cc:123
static void printToolUsage(const std::string &name, std::ostream &)
Definition: ToolFactory.cc:95
virtual Tool * create(int argc, char **argv)=0
AbstractToolFactory(const std::string &name)
Definition: ToolFactory.cc:152
static Tool * createTool(const std::string &name, int argc, char **argv)
Definition: ToolFactory.cc:143
virtual void help(std::ostream &)=0
static void printToolsHelp(std::ostream &)
Definition: ToolFactory.cc:101
virtual void usage(const std::string &, std::ostream &)=0
static const std::vector< std::string > matchAll
Definition: ToolFactory.h:45
ToolFactory(const std::string &name)
Definition: ToolFactory.h:52
Tool * create(int argc, char **argv)
Definition: ToolFactory.h:54
void help(std::ostream &o)
Definition: ToolFactory.h:56
void usage(const std::string &name, std::ostream &o)
Definition: ToolFactory.h:57
Definition: ColumnInfo.h:23
subroutine usage()
Definition: odc_ls.f90:59