C++ main module for emicrom Package  1.0
CORE_Run.h
Go to the documentation of this file.
1 #ifndef CORE_Run_H
2 #define CORE_Run_H
3 
4 #include "CORE_VectorReader.h"
5 #include "CORE_Object.h"
6 #include "CORE_Out.h"
7 #include "CORE_Exception.h"
8 #include "CORE_ClassFactory.h"
9 
11 
12 
38 class CORE_Run : public virtual CORE_Object {
40 
41  //attributes
42 private :
43 
45  static tString VERSION;
46  static SP::CORE_ClassFactory CLASS_FACTORY;
47 
48 protected:
49  // CONSTRUCTORS
52  CORE_Run(void);
53 
54  // DESTRUCTORS
57  virtual ~CORE_Run(void);
58 
59 
60 
61 public :
62  // CREATE class
65  static inline SP::CORE_Run New() {
66  SP::CORE_Run p(new CORE_Run(),CORE_Run::Delete());
67  p->setThis(p);
68  return p;
69  }
70 
71  //SET & GET methods
72 
76  inline void setSoftName(const tString& soft) {
77  mSoftName=soft;
78  }
82  inline const tString& getSoftName() const {
83  return mSoftName;
84  }
85 
90  inline static void setVersion(const tString& version) {
91  VERSION=version;
92  }
96  inline static tString getVersion() {
97  return VERSION;
98  }
99 
103  static inline void setClassFactory(SP::CORE_ClassFactory cf) {
104  CLASS_FACTORY=cf;
105  }
109  static inline CORE_ClassFactory & getClassFactory() {
110  if (CLASS_FACTORY.get()==null) throw CORE_Exception("common/core",
111  "CORE_Run::getClassFactory()",
112  "global variable CORE_Run::CLASS_FACTORY not set");
113  return *CLASS_FACTORY.get();
114  }
115 
116 
117 
118  // MAIN Method
119 
120 public:
124  static void createIO(const map<tString,tString>& options);
125 
126 
127 
143  virtual tBoolean run(int argc,char* argv[]) const;
144 
145 protected:
149  virtual void createClassFactories(const map<tString,tString>& options) const{
150  }
161  virtual tBoolean make(const map<tString,tString>&options,const tString& arg) const {
162 
163 
164  if (arg.compare("tests")==0) return makeTests(options);
165  else if (arg.compare("performance")==0) return makePerformance(options);
166  else if (arg.compare("help")==0) {
167  cout << man();
168  return true;
169  }
170  else if (arg.compare("type")==0) return makeType();
171  else if (arg.compare("validation")==0) return makeValidation(options);
172  else if (arg.compare("run")==0) return makeRun(options);
173  else {
174  CORE_Object::out() << arg << " unrecognized.\n";
175  cout << arg << " unrecognized.\n";
176  return false;
177  }
178  }
179 
180 
181 
182 
183 protected:
187  tString man() const;
188 
192  virtual tBoolean makeType() const;
193 
197  virtual tBoolean makeValidation(const map<tString,tString>&options) const {
198  return true;
199  }
200 
205  virtual tBoolean makeTests(const map<tString,tString>&options) const ;
206 
211  virtual tBoolean makePerformance(const map<tString,tString>&options) const ;
212 
213 public:
218  virtual tBoolean makeRun(const map<tString,tString>&options) const {
219  return true;
220  }
221 
222 
223 
224 private:
230  static void readOptions(int argc,char *argv[],map<tString,tString>& options);
231 
232 
233 public:
241  static tString readOption(const tString& opt,int argc,char *argv[],tBoolean& isExists);
242 
243 public:
247  virtual void initOptions(map<tString,tString>& options) const;
248 
252  virtual void initManOptions(map<tString,map<tString,tString> >& options) const;
253 
254 protected:
260  virtual void readOptionsFromCommandLine(int argc,char *argv[],map<tString,tString>& options) const {
261  readOptions(argc,argv,options);
262  }
263 
264 public:
270  virtual void readOptionsFromFile(const tString& fileName,
271  map<tString,tString>& options) const;
276  tBoolean saveOptionsToFile(const tString& fileName,
277  const map<tString,tString>& options) const;
283  tBoolean saveOptionsToFile(const tString& fileName,
284  const map<tString,map<tString,tString> >& manOptions,
285  const map<tString,tString>& options) const;
286 
293  const map<tString,tString>& options) const;
294 
302  const map<tString,map<tString,tString> >& manOptions,
303  const map<tString,tString>& options) const;
304 
305 public:
306 
312  static tString readPath(const tString& path);
313 
319  static tString readFile(const tString& path, const tString& fn);
325  template<class T>
326  inline static tBoolean readVector(const tString& str,CORE_Array<T>& value) {
327  tString s=str;
328  tBoolean succeeds=CORE_VectorReader::readVector(s,value);
329  return succeeds;
330  }
336  inline static tBoolean readVector(const tString& str,vector<tReal>& value) {
337  tString s=str;
338  tBoolean succeeds=CORE_VectorReader::readVector(s,value);
339  return succeeds;
340  }
346  inline static tBoolean readVector(const tString& str,tReal value[3]) {
347 
348  vector<tReal> vs;
349  tString s=str;
351  tFlag i,p=(vs.size()<3)?vs.size():3;
352  for (i=0;i<p;i++) value[i]=vs[i];
353  return succeeds;
354  }
360  inline static tBoolean readVector(const tString& str,int value[3]) {
361  tReal rv[3];
362  tString s=str;
363  tBoolean succeeds=readVector(s,rv);
364  for (tFlag i=0;i<3;i++) value[i]=(int) rv[i];
365  return succeeds;
366  }
372  inline static tBoolean readVector(const tString& str,tBoolean value[3]) {
373  vector<tBoolean> vs;
374  tString s=str;
376  tFlag i,p=(vs.size()<3)?vs.size():3;
377  for (i=0;i<p;i++) value[i]=vs[i];
378  return succeeds;
379  }
380 
385  static tBoolean readBoolean(const tString& fn);
390  static tInteger readInt(const tString& fn);
395  static tReal readReal(const tString& fn);
396 
397 
398 
399 
400 };
401 
402 
403 #endif
DEFINE_SPTR(CORE_Run)
static void readOptions(int argc, char *argv[], map< tString, tString > &options)
read the options
Definition: CORE_Run.cpp:403
static tString readPath(const tString &path)
read the path from options
Definition: CORE_Run.cpp:318
CORE_Run(void)
create
Definition: CORE_Run.cpp:11
virtual tBoolean makeValidation(const map< tString, tString > &options) const
compare the result with validated results
Definition: CORE_Run.h:197
void setSoftName(const tString &soft)
set soft name
Definition: CORE_Run.h:76
virtual void initManOptions(map< tString, map< tString, tString > > &options) const
init the man options by theme
Definition: CORE_Run.cpp:198
This class is a Run class for Common package.
Definition: CORE_Run.h:38
CORE_Out & printOptions(CORE_Out &out, const map< tString, tString > &options) const
print the options
Definition: CORE_Run.cpp:513
static tReal readReal(const tString &fn)
read real
Definition: CORE_Run.cpp:351
virtual ~CORE_Run(void)
destroy
Definition: CORE_Run.cpp:15
static tString VERSION
Definition: CORE_Run.h:45
virtual tBoolean makeRun(const map< tString, tString > &options) const
run the program
Definition: CORE_Run.h:218
static tBoolean readVector(const tString &str, CORE_Array< T > &value)
read a double vector
Definition: CORE_Run.h:326
static tBoolean readVector(const tString &str, vector< tReal > &value)
read a double vector
Definition: CORE_Run.h:336
virtual void readOptionsFromFile(const tString &fileName, map< tString, tString > &options) const
read the options from the file
Definition: CORE_Run.cpp:570
static SP::CORE_Run New()
create a new class
Definition: CORE_Run.h:65
static tString readOption(const tString &opt, int argc, char *argv[], tBoolean &isExists)
read the option with name from the command line
Definition: CORE_Run.cpp:355
tString mSoftName
Definition: CORE_Run.h:44
#define tBoolean
Definition: types.h:139
const tString & getSoftName() const
get soft name
Definition: CORE_Run.h:82
#define null
Definition: types.h:144
virtual tBoolean make(const map< tString, tString > &options, const tString &arg) const
make the arg in parameter
Definition: CORE_Run.h:161
static tInteger readInt(const tString &fn)
read int
Definition: CORE_Run.cpp:348
virtual tBoolean run(int argc, char *argv[]) const
run the program
Definition: CORE_Run.cpp:21
static void setVersion(const tString &version)
set the version
Definition: CORE_Run.h:90
tBoolean saveOptionsToFile(const tString &fileName, const map< tString, tString > &options) const
save the options to the file
Definition: CORE_Run.cpp:522
static tBoolean readVector(tString &str, vector< T > &vs)
read vector of string str v=[x,y,z,t] or x,y,z,t
Definition: CORE_VectorReader.hpp:7
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
SP_OBJECT(CORE_Run)
virtual void createClassFactories(const map< tString, tString > &options) const
create the class factories from options
Definition: CORE_Run.h:149
this class describes an array
Definition: CORE_Array.h:19
static tString readFile(const tString &path, const tString &fn)
read the file name from options
Definition: CORE_Run.cpp:327
virtual void readOptionsFromCommandLine(int argc, char *argv[], map< tString, tString > &options) const
read the options from the commanand line
Definition: CORE_Run.h:260
static tBoolean readVector(const tString &str, tReal value[3])
read a double vector
Definition: CORE_Run.h:346
virtual tBoolean makeTests(const map< tString, tString > &options) const
run the tests
Definition: CORE_Run.cpp:103
static tBoolean readVector(const tString &str, int value[3])
read an int vector
Definition: CORE_Run.h:360
virtual tBoolean makePerformance(const map< tString, tString > &options) const
run the performance tests
Definition: CORE_Run.cpp:113
abstract base class for most classes.
Definition: CORE_Object.h:53
#define tString
Definition: types.h:135
static void createIO(const map< tString, tString > &options)
read the options for log
Definition: CORE_Run.cpp:254
static void setClassFactory(SP::CORE_ClassFactory cf)
set the class factory to create classes
Definition: CORE_Run.h:103
static CORE_Out & out()
get the output
Definition: CORE_Object.h:198
this class describes a class factory to generate classes for User Interface Software ...
Definition: CORE_ClassFactory.h:18
this class describes the output by default write on standart output
Definition: CORE_Out.h:22
tString man() const
return the man
Definition: CORE_Run.cpp:140
virtual void initOptions(map< tString, tString > &options) const
init the default options
Definition: CORE_Run.cpp:223
static SP::CORE_ClassFactory CLASS_FACTORY
Definition: CORE_Run.h:46
static CORE_ClassFactory & getClassFactory()
get the class factory to create classes
Definition: CORE_Run.h:109
#define tReal
Definition: types.h:118
static tString getVersion()
get the version
Definition: CORE_Run.h:96
virtual tBoolean makeType() const
print the types used in the program
Definition: CORE_Run.cpp:124
#define tInteger
Definition: types.h:90
static tBoolean readVector(const tString &str, tBoolean value[3])
read a boolean vector
Definition: CORE_Run.h:372
static tBoolean readBoolean(const tString &fn)
read boolean from string
Definition: CORE_Run.cpp:340
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74