test_demo.cpp 1.5 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/***************************************************************************
 * 
 * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved
 * $Id: test_demo.cpp,v 1.5 2009/02/13 15:25:31 yingxiang Exp $ 
 * 
 **************************************************************************/



/**
 * @file test_demo.cpp
 * @author yingxiang(com@baidu.com)
 * @date 2009/01/06 16:50:46
 * @version $Revision: 1.5 $ 
 * @brief 
 *  
 **/

#include "Configure.h"
#include <iostream>

int main(){
	//comcfg :: Log :: openLowLevel();
	comcfg :: Configure conf;
	int ret = conf.load("", "test.conf");
	if(ret != 0){
		return 0;
	}

	try{
		std::cout<< "Module Name : " << conf["module"].to_bsl_string() << std::endl;
		size_t num = conf["server"].size();
		std::cout<< "We have " << num << " servers." << std::endl;
		for(size_t i = 0; i < num; ++i){
			printf("Server[%d] is : ip = %s, port = %d\n", 
					(int)i,
				conf["server"][i]["ip"].to_cstr(), 
				conf["server"][i]["port"].to_int32() );
		}
	}
	catch(comcfg :: ConfigException e){
		std::cerr << "Something error  "<< e.what() << std::endl; 
	}
	catch(...){
		std::cerr << "What's wrong?" << std::endl;
	}
	size_t sz;
	printf("\n-------dump-------\n%s\n--------print---------\n", conf.dump(&sz));
	conf.print();
	comcfg::Configure nxt;
	char * b = nxt.getRebuildBuffer(sz);
	memcpy(b, conf.dump(NULL), sz);
	nxt.rebuild();
	printf("----nxt.print----\n");
	nxt.print();
	return 0;
}


















/* vim: set ts=4 sw=4 sts=4 tw=100 */