www.pudn.com > xml2db.rar > config.cpp


/**
 *@file configure.cpp
 *@brief 实现配置信息的读取,提供
 *
 *Author: cuichao@boco.com.cn \n
 *ChangeLog: \n
 *2006-06-22 11:13:57: Create file 
 */

#include 
#include 
#include 
#include "config.h"
#include "chash.h"

using namespace std;

//文件内部变量
static CHash _the_conf;


int load_config(const char * file_name) throw(std::string)
{
     
     int item_count = _the_conf.InsertItemsFromFile(file_name);
     if(item_count > 0)
	  return item_count;
     if(item_count < 0)
     {
	  string errstr = "Fail to read config file. ";
	  errstr += _the_conf.GetError();
	  throw errstr;
     }
     if(item_count == 0)
     {
	  string errstr = "The Config file is empty. ";
	  throw errstr;
     }
     //never go here
     return -1;     
}

const char *get_config_value(const char *name)
{
     CHash::const_iterator item_=_the_conf.find(name);
     if(item_ == _the_conf.end())
     {
	  return NULL;
     }
     return item_->second.c_str();
}