[ <- Previous Page ] | [ ^ Table Of Contents ^ ] | [ Next Page -> ] |
Configuration files are used for providing runtime configuration information to programs. Class zProf is used by zWebit programs to read configuration files and gather needed run time data at start up.
Method/Function | Description | Return Code |
---|---|---|
zProf | Class constructor. | |
int init (const zString& ProfName) | Initialize the class with a valid profile file name. ProfName includes directory and file name. | 0 Success -1 Error |
void done ( ) | This method closes the input file and should be called after parsing the zProf profile is complete. | |
int getValforKey (const zString &key, zString& result) | This routine pulls a value for key and loads the data in result. | -1 Error 0 Success |
int getValforKey (const zString &key, zString& result, int occ) | This routine pulls a value for key and loads the data in result for occurence, occ | -1 Error 0 Success |
# # Lines which begin with a # are comment lines # # IP=127.0.0.1 PORT=12345 # TESTVAL=1 TESTVAL=2 # #
/* zprof1 test program Copyright (c) 2000 HSC GNU/GPL */ #include#include "../../base/zstring.cpp" #include "../../base/zprof.cpp" using namespace std; int main() { int rc; zProf zp; zString ReturnVal; zString ProfName = "zprof.pro"; // open the profile rc = zp.init( ProfName ); if( rc != 0 ){ cout << "Error opening profile " << ProfName << endl; return 1; } rc = zp.getValForKey( "IP", ReturnVal ); if( rc == 0 ) cout << "Program retrieved IP = " << ReturnVal << endl; else cout << "Could not find paramater IP\n"; rc = zp.getValForKey( "PORT", ReturnVal ); if( rc == 0 ) cout << "Program retrieved IP = " << ReturnVal << endl; else cout << "Could not find paramater PORT\n"; rc = zp.getValForKey( "TESTVAL", ReturnVal, 0 ); if( rc == 0 ) cout << "Program retrieved TESTVAL(0) = " << ReturnVal << endl; else cout << "Could not find paramater TESTVAL(0)\n"; rc = zp.getValForKey( "TESTVAL", ReturnVal, 1 ); if( rc == 0 ) cout << "Program retrieved TESTVAL(1) = " << ReturnVal << endl; else cout << "Could not find paramater TESTVAL(1)\n"; // clean up when we are done zp.done(); return 0; }
Program retrieved IP = 127.0.0.1
Program retrieved IP = 12345
Program retrieved TESTVAL (0) = 1
Program retrieved TESTVAL (1) = 2
[ <- Previous Page ] | [ ^ Table Of Contents ^ ] | [ ^ Top Of Page ^ ] | [ Next Page -> ] |
Visit the GNU home page.
FSF & GNU inquiries & questions to
gnu@gnu.org.
Comments on these web pages to
info@zhsac.com.
Copyright (C) 2003 HealthCare Systems and Consulting
Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.
Last updated: 07/21/2003