#ifndef AASPI_FRAMEWORK_H #define AASPI_FRAMEWORK_H #include #include #include "aaspi_types.h" #include "aaspi_dict.h" #include "aaspi_file.h" class AASPI_Framework { public: AASPI_Framework(); ~AASPI_Framework(); void init(); void set_argvec(int argc, char **argv); void set_arg(int pos, char *arg); // Fortran90 support void set_arg_count(int len); // Fortran90 support string datapath() { // Override default datapath with command line entry if (cmdDict().is_defined("datapath")) { return cmdDict().get_string("datapath"); } return data_path; } AASPI_Dictionary cmdDict() { return cmdline_dict; } static string getHostName(); static string getUserName(); static string getHomeDir(); static string getTime(); string progName() { return prog_name; } string hostName() { return getHostName(); } string userName() { return getUserName(); } string homeDir() { return getHomeDir(); } AASPI_File *get_file_in(const string &tag); AASPI_File *get_file_out(const string &tag, int dform=AASPI_File::xdr_float, int esz=4); AASPI_File *get_file_out_no_binary(const string &tag, int dform = AASPI_File::xdr_float, int esz = 4); AASPI_File *get_file_out_force_aaspi_binary(const string &tag, int dform = AASPI_File::xdr_float, int esz = 4); AASPI_File *get_file_opened(const string &tag); void close_file(const string &tag); void close_all_files(); bool has_param(const string &tag) { return cmdline_dict.is_defined(tag); } string get_param_string(const string &tag, const string &defval=""); int get_param_int(const string &tag, int defval=0); aaspi_int64 get_param_int64(const string &tag, aaspi_int64 defval=0); float get_param_float(const string &tag, float defval=0.f); double get_param_double(const string &tag, double defval=0.); bool get_param_boolean(const string &tag, bool defval=false); string get_hist_string(const string &ftag, const string &tag, const string &defval=""); int get_hist_int(const string &ftag, const string &tag, int defval=0); aaspi_int64 get_hist_int64(const string &ftag, const string &tag, aaspi_int64 defval=0); float get_hist_float(const string &ftag, const string &tag, float defval=0.f); double get_hist_double(const string &ftag, const string &tag, double defval=0.); inline static string getDatapath(int argc = 0, char **argv = 0) { AASPI_Framework t_afw; if (argc && argv) t_afw.set_argvec(argc,argv); t_afw.init(); return t_afw.datapath(); } bool InsidePolygon(float x, float y, float *pol_x, float *pol_y, int n); protected: string prog_name; // argv[0] hopefully vector argvec; AASPI_Dictionary cmdline_dict; AASPI_Dictionary in_dict; string data_path; map file_map; // File mapping typedef map::iterator file_map_iterator; void setup_datapath(); string read_datapath_file(const string &fname); string hostname_fixup(const string &hname); // Fix up arguments dequoted by shell (commandline) static string requote_arg(const string &arg); static string str_getenv(const string &vname); }; // Inlined command line dictionary functions inline string AASPI_Framework::get_param_string(const string &tag, const string &defval) { return cmdline_dict.get_string(tag,defval); } inline int AASPI_Framework::get_param_int(const string &tag, int defval) { return cmdline_dict.get_int(tag,defval); } inline aaspi_int64 AASPI_Framework::get_param_int64(const string &tag, aaspi_int64 defval) { return cmdline_dict.get_int64(tag,defval); } inline float AASPI_Framework::get_param_float(const string &tag, float defval) { return cmdline_dict.get_float(tag,defval); } inline double AASPI_Framework::get_param_double(const string &tag, double defval) { return cmdline_dict.get_double(tag,defval); } inline bool AASPI_Framework::get_param_boolean(const string &tag, bool defval) { return cmdline_dict.get_boolean(tag,defval); } #endif