|
hipp
1.0
|
00001 /* 00002 Copyright 2011 Certec, Lund University, Sweden 00003 00004 This file is part of HIPP. 00005 00006 HIPP is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 HIPP is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with HIPP. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00027 #include <H3D/INIFile.h> 00028 #include <fstream> 00029 00030 using namespace std; 00031 using namespace H3D; 00032 00033 #define GET4(ENV,GROUP,VAR,DEFAULT) \ 00034 ( getenv(ENV) ? \ 00035 string(getenv(ENV)) : \ 00036 ( ini_file.hasOption(GROUP,VAR) ? \ 00037 ini_file.get( GROUP, VAR ) : \ 00038 DEFAULT ) ) 00039 00040 #define GET_ENV_INI_DEFAULT(ENV,PATH,GROUP,VAR,DEFAULT) \ 00041 ( getenv(ENV) ? \ 00042 string(getenv(ENV)) : \ 00043 ( ini_file.hasOption(GROUP,VAR) ? \ 00044 PATH + ini_file.get( GROUP, VAR ) : \ 00045 DEFAULT ) ) 00046 00047 inline string GET_ENV_INI_DEFAULT_FILE( INIFile &ini_file, 00048 const string &ENV, 00049 const string &DISPLAY_PATH, 00050 const string &COMMON_PATH, 00051 const string &GROUP, 00052 const string &VAR ) { 00053 char *env = getenv(ENV.c_str()); 00054 if( env ) return env; 00055 00056 if( ini_file.hasOption(GROUP,VAR) ) { 00057 string option = ini_file.get( GROUP, VAR ); 00058 string full_path = string(DISPLAY_PATH) + option; 00059 ifstream inp( full_path.c_str() ); 00060 inp.close(); 00061 string r = full_path; 00062 if(!inp.fail()) return full_path; 00063 inp.clear(); 00064 00065 full_path = (COMMON_PATH + option); 00066 inp.open( full_path.c_str() ); 00067 inp.close(); 00068 if(!inp.fail()) return full_path; 00069 } 00070 return ""; 00071 } 00072 00073 #define GET_INT(GROUP,VAR,DEFAULT) \ 00074 ( ini_file.hasOption(GROUP,VAR) ? \ 00075 atoi(ini_file.get( GROUP, VAR ).c_str()) : \ 00076 DEFAULT ) 00077 00078 #define GET_BOOL(GROUP,VAR,DEFAULT) \ 00079 ( ini_file.hasOption(GROUP,VAR) ? \ 00080 ini_file.getBoolean( GROUP, VAR ) : \ 00081 DEFAULT )
1.7.5.1