ODIN
odindata/step.h
1 /***************************************************************************
2  step.h - description
3  -------------------
4  begin : Sat Dec 30 2006
5  copyright : (C) 2000-2021 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 
29 
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 
80  STD_string args_values() const;
81 
85  unsigned int numof_args() const {return args.numof_pars();}
86 
87 
91  void append_opts(LDRblock& parblock);
92 
93 
94  protected:
95 
96 
100  void append_arg(LDRbase& arg, const STD_string& arglabel);
101 
102 
103  const char* c_label() const {if(!label_cache.size()) label_cache=label(); return label_cache.c_str();} // For Debug
104 
105  private:
106 
107  LDRblock args;
108  mutable STD_string label_cache;
109 };
110 
111 
113 
118 template<class T>
119 class StepFactory {
120 
121  public:
122 
126  StepFactory(LDRblock* parblock=0);
127 
128  ~StepFactory();
129 
133  T* create(const STD_string& label) const;
134 
138  STD_string manual() const;
139 
143  STD_string get_cmdline_usage(const STD_string& lineprefix) const;
144 
145  private:
146 
147  typedef STD_map<STD_string,T*> StepMap;
148  StepMap templates;
149 
150  mutable STD_list<T*> garbage;
151 
152 };
153 
154 
157 #endif
158 
unsigned int numof_pars() const
STD_string manual() const
Definition: step_code.h:134
T * create(const STD_string &label) const
Definition: step_code.h:108
STD_string get_cmdline_usage(const STD_string &lineprefix) const
Definition: step_code.h:211
StepFactory(LDRblock *parblock=0)
Definition: step_code.h:87
virtual T * allocate() const =0
void append_arg(LDRbase &arg, const STD_string &arglabel)
Definition: step_code.h:76
void set_args(const STD_string &argstr)
Definition: step_code.h:15
virtual STD_string description() const =0
void append_opts(LDRblock &parblock)
Definition: step_code.h:70
unsigned int numof_args() const
Definition: odindata/step.h:85
STD_string args_description() const
Definition: step_code.h:35
STD_string args_values() const
Definition: step_code.h:56
virtual void init()=0
virtual STD_string label() const =0
T * clone() const
Definition: step_code.h:6