Reader.h 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) 2008 Baidu.com, Inc. All Rights Reserved
 * $Id: Reader.h,v 1.5 2009/02/13 15:25:31 yingxiang Exp $ 
 * 
 **************************************************************************/



/**
 * @file Reader.h
 * @author yingxiang(com@baidu.com)
 * @date 2008/12/21 16:09:58
 * @version $Revision: 1.5 $ 
 * @brief 
 *  
 **/


#ifndef  __READER_H_
#define  __READER_H_

#include "RawData.h"
#include "Configure.h"
#include <sys/uio.h>

namespace comcfg{
#define REBUILD_CONF "REBUILD_CONF"
	class Reader{
			RawData _fd;
		public:
			int read(const char * file, Configure * cfg);
			char * getRebuildBuffer(size_t size);
			int rebuild(Configure * cfg);
			char * dump(size_t *);
			Reader();
		private:
			int build(Configure * cfg);
			int push(Configure * cfg, const char * buf, size_t length);
			struct pair_t{
				str_t key;
				str_t value;
			};
			int sectionParser(const char * buf, size_t length, str_t * str);
			int keyParser(const char * buf, size_t length, pair_t * pair);
			int getWord(const char * from, const char * to, str_t * str);
			void getCommentUpwards(str_t &comment, int line);
			int isCommentLine(const char *);//comment line or blank line
			friend class ConfigUnit;
			friend class Configure;
			friend class ConfigGroup;
			friend int cb_dumpConf(ConfigUnit *, void *);
			str_t _cur_file;
			int _cur_line;
			bool _isRebuild;
	};
}
















#endif  //__READER_H_

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