odindata/step.h
1 /***************************************************************************
2  step.h - description
3  -------------------
4  begin : Sat Dec 30 2006
5  copyright : (C) 2000-2015 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef STEP_H
19 #define STEP_H
20 
21 #include <odindata/data.h>
22 
28 
34 template<class T>
35 class Step {
36 
37  public:
38 
39  virtual ~Step() {}
40 
44  virtual STD_string label() const = 0;
45 
49  virtual STD_string description() const = 0;
50 
54  virtual T* allocate() const = 0;
55 
59  virtual void init() = 0;
60 
64  T* clone() const;
65 
69  void set_args(const STD_string& argstr);
70 
71 
75  STD_string args_description() const;
76 
77 
81  unsigned int numof_args() const {return args.numof_pars();}
82 
83 
87  void append_opts(LDRblock& parblock);
88 
89 
90  protected:
91 
92 
96  void append_arg(LDRbase& arg, const STD_string& arglabel);
97 
98 
99  const char* c_label() const {if(!label_cache.size()) label_cache=label(); return label_cache.c_str();} // For Debug
100 
101  private:
102 
103  LDRblock args;
104  mutable STD_string label_cache;
105 };
106 
107 
109 
114 template<class T>
115 class StepFactory {
116 
117  public:
118 
122  StepFactory(LDRblock* parblock=0);
123 
124  ~StepFactory();
125 
129  T* create(const STD_string& label) const;
130 
134  STD_string manual() const;
135 
139  STD_string get_cmdline_usage(const STD_string& lineprefix) const;
140 
141  private:
142 
143  typedef STD_map<STD_string,T*> StepMap;
144  StepMap templates;
145 
146  mutable STD_list<T*> garbage;
147 
148 };
149 
150 
153 #endif
154 
virtual void init()=0
unsigned int numof_args() const
Definition: odindata/step.h:81
T * clone() const
Definition: step_code.h:5
void append_opts(LDRblock &parblock)
Definition: step_code.h:52
virtual STD_string description() const =0
virtual T * allocate() const =0
virtual STD_string label() const =0
void append_arg(LDRbase &arg, const STD_string &arglabel)
Definition: step_code.h:58
STD_string args_description() const
Definition: step_code.h:34
void set_args(const STD_string &argstr)
Definition: step_code.h:14
unsigned int numof_pars() const