00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef ST_GET_CONFIG_VALUE_HH
00058 #define ST_GET_CONFIG_VALUE_HH
00059
00060 #include "Stiostream.h"
00061 #include <Stsstream.h>
00062 #include <string>
00063 #include "StGlobals.hh"
00064 #if !defined(ST_NO_NAMESPACES)
00065 using std::string;
00066 #endif
00067
00068 template<class T>
00069 void StGetConfigValue(const char* filename, const char* name, T& value)
00070 {
00071 ifstream ifs(filename);
00072 if (!ifs) return;
00073
00074 string line;
00075 StSizeType pos;
00076 while (ifs.good() && !ifs.eof()) {
00077 #if defined(__SUNPRO_CC)
00078 char c; line.erase();
00079 while ((c = ifs.get()) && c != '\n' && !ifs.eof()) line += c;
00080 #else
00081 getline(ifs,line,'\n');
00082 #endif
00083 if ((pos = line.find('#')) != StNPOS)
00084 line.erase(pos,line.length());
00085 if ((pos = line.find("//")) != StNPOS)
00086 line.erase(pos,line.length());
00087 if ((pos = line.find(name)) != StNPOS) {
00088 if ((pos = line.find(':')) != StNPOS) {
00089 line.erase(0,pos+1);
00090 istrstream ist(line.c_str());
00091 ist >> value;
00092 return;
00093 }
00094 }
00095 }
00096 return;
00097 }
00098
00099
00100 template<class T>
00101 void StGetConfigValue(const char* filename, const char* name, T& value, int nitems)
00102 {
00103 ifstream ifs(filename);
00104 if (!ifs) return;
00105
00106 string line;
00107 StSizeType pos;
00108 while (ifs.good() && !ifs.eof()) {
00109 #if defined(__SUNPRO_CC)
00110 char c; line.erase();
00111 while ((c = ifs.get()) && c != '\n' && !ifs.eof()) line += c;
00112 #else
00113 getline(ifs,line,'\n');
00114 #endif
00115 if ((pos = line.find('#')) != StNPOS)
00116 line.erase(pos,line.length());
00117 if ((pos = line.find("//")) != StNPOS)
00118 line.erase(pos,line.length());
00119 if ((pos = line.find(name)) != StNPOS) {
00120 if ((pos = line.find(':')) != StNPOS) {
00121 line.erase(0,pos+1);
00122 istrstream ist(line.c_str());
00123 for (int i=0; i<nitems; i++)
00124 ist >> value[i];
00125 }
00126 }
00127 }
00128 }
00129
00130 #endif