Ice Sheet System Model  4.18
Code documentation
Options.h
Go to the documentation of this file.
1 #ifndef _CONTAINER_OPTIONS_H_
2 #define _CONTAINER_OPTIONS_H_
3 
4 /*forward declarations */
5 class Option;
6 #include "../../datastructures/datastructures.h"
7 #include "./GenericOption.h"
8 
9 class Options: public DataSet{
10 
11  public:
12 
13  /*constructors, destructors*/
14  Options();
15  ~Options();
16 
17  /*numerics*/
18  int AddOption(Option* in_oobject);
19  Option* GetOption(const char* name);
20 
21  template <class OptionType> void Get(OptionType* pvalue,const char* name){ /*{{{*/
22 
23  /*Get option*/
24  GenericOption<OptionType>* genericoption=xDynamicCast<GenericOption<OptionType>*>(GetOption(name));
25 
26  /*If the pointer is not NULL, the option has been found*/
27  if(genericoption){
28  genericoption->Get(pvalue);
29  }
30  /*Else, the Option does not exist, no default provided*/
31  else{
32  _error_("option of name \"" << name << "\" not found, and no default value has been provided");
33  }
34  }
35  /*}}}*/
36  template <class OptionType> void Get(OptionType* pvalue,const char* name,OptionType default_value){ /*{{{*/
37 
38  /*Get option*/
39  GenericOption<OptionType>* genericoption=xDynamicCast<GenericOption<OptionType>*>(GetOption(name));
40 
41  /*If the pointer is not NULL, the option has been found*/
42  if(genericoption){
43  genericoption->Get(pvalue);
44  }
45  else{
46  if(GetOption(name)) _printf_("WARNING: option "<<name<<" found but fetched format not consistent, defaulting...\n");
47  *pvalue=default_value;
48  }
49  }
50  /*}}}*/
51 
52 };
53 
54 #endif //ifndef _INPUTS_H_
55 
56 template <> inline void Options::Get(char** pvalue,const char* name,char* default_value){ /*{{{*/
57 
58  /*Get option*/
59  GenericOption<char*>* genericoption=xDynamicCast<GenericOption<char*>*>(GetOption(name));
60 
61  /*If the pointer is not NULL, the option has been found*/
62  if(genericoption){
63  genericoption->Get(pvalue);
64  }
65  else{
66  /*Make a copy*/
67  int stringsize=strlen(default_value)+1;
68  char* outstring=xNew<char>(stringsize);
69  xMemCpy<char>(outstring,default_value,stringsize);
70  *pvalue=outstring;
71  }
72 }
73 /*}}}*/
Options
Definition: Options.h:9
GenericOption.h
: header file for generic option object
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
Options::Get
void Get(OptionType *pvalue, const char *name, OptionType default_value)
Definition: Options.h:36
Options::~Options
~Options()
Definition: Options.cpp:27
Options::Get
void Get(OptionType *pvalue, const char *name)
Definition: Options.h:21
Option
Definition: Option.h:13
Options::GetOption
Option * GetOption(const char *name)
Definition: Options.cpp:67
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
GenericOption::Get
void Get(OptionType *pvalue)
Definition: GenericOption.h:66
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
Options::AddOption
int AddOption(Option *in_oobject)
Definition: Options.cpp:33
Options::Options
Options()
Definition: Options.cpp:23
GenericOption
Definition: GenericOption.h:22