FRED
|
00001 /* 00002 Copyright 2009 by the University of Pittsburgh 00003 Licensed under the Academic Free License version 3.0 00004 See the file "LICENSE" for more information 00005 */ 00006 00007 // 00008 // 00009 // File Params.h 00010 // 00011 #ifndef _FRED_PARAMS_H 00012 #define _FRED_PARAMS_H 00013 00014 #define MAX_PARAMS 1000 00015 #define MAX_PARAM_SIZE 1024 00016 00017 #include <stdlib.h> 00018 #include <stdio.h> 00019 #include <string.h> 00020 #include <string> 00021 #include <vector> 00022 #include <map> 00023 00024 using namespace std; 00025 00033 class Params { 00034 00035 public: 00041 static int get_param(char *s, int *p); 00042 00048 static int get_param(char *s, unsigned long *p); 00049 00055 static int get_param(char *s, double *p); 00056 00062 static int get_param(char *s, float *p); 00063 00069 static int get_param(char *s, char *p); 00070 00076 static int get_param(char *s, string &p); 00077 00085 static int read_parameters(char *paramfile); 00086 00092 static int get_param_vector(char *s, vector < int > &p); 00093 00099 static int get_param_vector(char *s, vector < double > &p); 00100 00101 00102 static int get_param_vector(char *s, double *p); 00103 00109 static int get_param_matrix(char *s, double ***p); 00110 00111 static int get_param_map(char *s, map<string, double> *p); 00112 static int get_double_indexed_param_map(string s, int index_i, int index_j, map<string, double> *p); 00113 static int get_indexed_param_map(string s, int index, map<string, double> *p); 00114 00119 static bool does_param_exist(char *s); 00120 00125 static bool does_param_exist(string s); 00126 00127 template <typename T> 00128 static int get_param_from_string(string s, T *p){ 00129 char st[80]; 00130 sprintf(st,"%s",s.c_str()); 00131 int err = get_param(st,p); 00132 return err; 00133 } 00134 00135 template <typename T> 00136 static int get_indexed_param(string s, int index, T *p){ 00137 char st[80]; 00138 sprintf(st, "%s[%d]",s.c_str(),index); 00139 int err = get_param(st,p); 00140 return err; 00141 } 00142 00143 template <typename T> 00144 static int get_double_indexed_param(string s, int index_i, int index_j, T* p){ 00145 char st[80]; 00146 sprintf(st, "%s[%d][%d]",s.c_str(),index_i,index_j); 00147 int err = get_param(st,p); 00148 return err; 00149 } 00150 00151 template <typename T> 00152 static int get_indexed_param_vector(string s, int index, T* p){ 00153 char st[80]; 00154 sprintf(st, "%s[%d]",s.c_str(),index); 00155 int err = get_param_vector(st,p); 00156 return err; 00157 } 00158 00159 template <typename T> 00160 static int get_double_indexed_param_vector(string s, int index_i, int index_j, T* p) { 00161 char st[80]; 00162 sprintf(st, "%s[%d][%d]",s.c_str(),index_i,index_j); 00163 int err = get_param_vector(st,p); 00164 return err; 00165 } 00166 00167 private: 00168 static char param_name[][MAX_PARAM_SIZE]; 00169 static char param_value[][MAX_PARAM_SIZE]; 00170 static int param_count; 00171 00172 }; 00173 00174 #endif // _FRED_PARAMS_H