﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-iwangchuchu-最新评论</title><link>http://www.cppblog.com/iwangchuchu/CommentsRSS.aspx</link><description>海阔天空</description><language>zh-cn</language><pubDate>Fri, 23 Apr 2010 08:47:52 GMT</pubDate><lastBuildDate>Fri, 23 Apr 2010 08:47:52 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: [转载]低耦合模块间的通信组件：两个模板</title><link>http://www.cppblog.com/iwangchuchu/archive/2010/04/21/113100.html#113144</link><dc:creator>Kevin Lynx</dc:creator><author>Kevin Lynx</author><pubDate>Wed, 21 Apr 2010 08:31:00 GMT</pubDate><guid>http://www.cppblog.com/iwangchuchu/archive/2010/04/21/113100.html#113144</guid><description><![CDATA[不明真相地路过。。。<img src ="http://www.cppblog.com/iwangchuchu/aggbug/113144.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iwangchuchu/" target="_blank">Kevin Lynx</a> 2010-04-21 16:31 <a href="http://www.cppblog.com/iwangchuchu/archive/2010/04/21/113100.html#113144#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: STL容器实现IniFileParser</title><link>http://www.cppblog.com/iwangchuchu/archive/2010/04/08/110323.html#111944</link><dc:creator>jmchxy</dc:creator><author>jmchxy</author><pubDate>Thu, 08 Apr 2010 04:17:00 GMT</pubDate><guid>http://www.cppblog.com/iwangchuchu/archive/2010/04/08/110323.html#111944</guid><description><![CDATA[//===============================================<br>bool JFileConfig::getValue(LPCTSTR sectionName, LPCTSTR name, JConfigVal&amp; rval)const<br>{<br>	// 查找节<br>	JString jstrSection(sectionName);<br>	JString jstrName(name);<br>	bool bRet = false;<br>	// 查看是否已经存在<br>	ConstSectionIter iter = findSection( jstrSection );<br>	// 存在节<br>	if(iter == m_Sections.end())<br>	{<br>		return false;<br>	}<br>	return iter-&gt;get(jstrName, rval);<br>}<br><br>/////////////////////////////////////////////		<br>// 装载配置信息, 从文件或其他媒介<br>/////////////////////////////////////////////<br>#ifdef _DEBUG<br>#define _OUTPUT_STATE<br>#endif<br>bool JFileConfig::load(LPCTSTR  pszFilename)<br>{<br>	JStdioFile  inifile(pszFilename, JFileBase::modeRead);<br>	JString     CurSection;<br><br>	while(!inifile.eof())<br>	{<br>		//逐行分析数据<br>		JString     line = inifile.getline();<br>		// 去掉末尾的行计数符<br>		line.chomp();<br>		if(line.length() == 0)<br>		{<br>			continue;	//跳过空行<br>		}<br>		// 如果是注释行, 跳过<br>		//    ; 和 # 开始的行是注释<br>		if( (line[0] == _T(';'))||(line[0] == _T('#')))<br>		{<br>			continue;<br>		}<br>		if(line[0] == _T('['))<br>		{<br>			//是节名?<br>			int i = line.find( _T(']') );<br>			if(i &gt; 0)<br>			{// 节名, 取出节的名字, 创建节<br>				CurSection = line.substr(1, i-1);<br>				createSection(CurSection);<br>#ifdef _OUTPUT_STATE	//调试用<br>				_tprintf( _T(&quot;create seciton: %s\n&quot;), CurSection.c_str());<br>#endif<br>			}<br>			continue;	//错误的行直接跳过<br>		}<br>		else<br>		{	// 名/值 对定义的行, 查找 '=' 字符<br>			int i = line.find( _T('='));<br>			if(i &lt;= 0)<br>			{<br>				continue;	//没有 = 字符, 跳过<br>			}<br>			JString strName  = line.substr(0, i);<br>			strName.TrimRight();<br>			JString strValue = line.substr(i + 1, -1);<br>			strValue.TrimLeft();<br>			// 插入值<br>			setString(CurSection, strName, strValue);<br>		}<br>	}<br>	return true;<br>}<br><br>//-------------------------------------<br>// 保存配置到文件<br>//-------------------------------------<br>bool JFileConfig::save(LPCTSTR  pszFilename)const<br>{<br>	JFile   inifile(pszFilename, JFileBase::modeWrite|JFileBase::modeCreate);<br>	JString strLine(128);<br><br>	for(ConstSectionIter sectIter = m_Sections.begin(); <br>		sectIter != m_Sections.end(); <br>		++sectIter)<br>	{<br>		// 当前节的名字<br>		const JString&amp; sectionNmae = sectIter-&gt;m_strSectionName;<br>		// 写入节名<br>		strLine.clear();<br>		strLine += _T(&quot;[&quot;);<br>		strLine += sectionNmae;<br>		strLine += _T(&quot;]\r\n&quot;);<br>		inifile.write(strLine.c_str(), strLine.length());<br>		// 当前节对应的map<br>		const Dict&amp; CurSection = sectIter-&gt;m_Items;<br>		// 遍历名字/值<br>		ConstDictIterator dictIter = CurSection.begin();<br>		while(dictIter != CurSection.end())<br>		{<br>			const JString&amp; name  = dictIter-&gt;first;<br>			const JConfigVal&amp; value = dictIter-&gt;second;<br>			strLine.clear();<br>			strLine += name;<br>			strLine +=  _T(&quot;=&quot;);<br>			strLine += value.toString();<br>			strLine += _T(&quot;\r\n&quot;);<br>			inifile.write(strLine.c_str(), strLine.length());<br>			++dictIter;<br>		}<br>	}<br>	return true;<br>}<br><br>回复不能太长， 这是我的库中定义的 inifile 处理类<img src ="http://www.cppblog.com/iwangchuchu/aggbug/111944.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iwangchuchu/" target="_blank">jmchxy</a> 2010-04-08 12:17 <a href="http://www.cppblog.com/iwangchuchu/archive/2010/04/08/110323.html#111944#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: STL容器实现IniFileParser</title><link>http://www.cppblog.com/iwangchuchu/archive/2010/04/08/110323.html#111940</link><dc:creator>jmchxy</dc:creator><author>jmchxy</author><pubDate>Thu, 08 Apr 2010 04:12:00 GMT</pubDate><guid>http://www.cppblog.com/iwangchuchu/archive/2010/04/08/110323.html#111940</guid><description><![CDATA[#ifndef __JFILECONFIG_H__<br>#define __JFILECONFIG_H__<br>/////////////////////////////////////////////<br>///   JFileConfig  ini文件操作类<br>/////////////////////////////////////////////<br>#include &quot;jconfig.h&quot;<br>#include &lt;map&gt;<br>#include &lt;vector&gt;<br><br>namespace jlib<br>{<br><br>// ini 文件中名字不分大小写<br>struct SectionLess<br>{<br>	bool operator() (const JString&amp; Key1, const JString&amp; Key2)const<br>	{<br>		return Key1.compareNoCase(Key2) &lt; 0;<br>	}<br>};<br>//-------------------------------------------<br>// 定义foreach 函数需要使用的函数类型<br>//     pArg 为传递给 函数的数据<br>//-------------------------------------------<br>typedef bool (*FOREACHFUNC)(const JString&amp; section, const JString&amp; name, JConfigVal&amp; value, LPVOID pArg);<br>class JLIBAPI JFileConfig: JConfigBase<br>{<br>public:<br>	// 构造析构函数<br>	JFileConfig();<br>	virtual ~JFileConfig();<br>public:<br>	// 装载配置信息, 从文件或其他媒介<br>	virtual bool  load(LPCTSTR  pszFilename);<br>	// 保存配置到文件<br>	virtual bool  save(LPCTSTR  pszFilename)const;<br>	// 获取配置信息, key, name, 获得value<br>	// 读取失败返回 false<br>	// 获取通用类型的值<br>	virtual bool  getValue(LPCTSTR sectionName, LPCTSTR name, JConfigVal&amp; jRval)const;<br>	//		获取整数值<br>	virtual bool  getInt(LPCTSTR  sectionName, LPCTSTR name, int&amp; iRval)const;<br>	//		获取字符串<br>	virtual bool  getString(LPCTSTR sectionName, LPCTSTR name,  JString&amp; szRval)const;<br>	//      设置配置, 如果没有则创建指定名/值<br>	// 设置通用类型的值<br>	virtual bool  setValue(LPCTSTR sectionName, LPCTSTR name, const JConfigVal&amp; jVal);<br>	// 设置整型的值<br>	virtual bool  setInt(LPCTSTR  sectionName, LPCTSTR name, int iVal);<br>	//		设置字符串值, 如果没有则创建指定名/值<br>	virtual bool  setString(LPCTSTR sectionName, LPCTSTR name, LPCTSTR szVal);<br>	//--------------------------------------------------<br>	//		遍历函数<br>	//   如果用户定义的遍历函数返回了 false, 结束遍历<br>	bool  foreach(FOREACHFUNC fpForeach, LPVOID pArgs);<br>	//========================================<br>	#ifdef _UNIT_TEST_	//单元测试, 遍历一个ini文件<br>		static void unitTest(LPCTSTR filename);<br>	#endif	//_UNIT_TEST_	<br>	//========================================<br>public:<br>	/////////////////////////////////////////////<br>	///   配置节信息<br>	/////////////////////////////////////////////<br>	typedef  std::map&lt;JString, JConfigVal, SectionLess&gt;  Dict;<br>	typedef  std::map&lt;JString, JConfigVal, SectionLess&gt;::iterator  DictIterator;<br>	typedef  std::map&lt;JString, JConfigVal, SectionLess&gt;::const_iterator  ConstDictIterator;<br>	// 结点信息<br>	struct JConfigSection<br>	{<br>		JString	     m_strSectionName;		//节名<br>		Dict         m_Items;	//名/值對<br>	public:<br>		JConfigSection(): m_strSectionName(), m_Items() { }<br>		~JConfigSection(){ m_Items.clear(); }<br>		// 加入一个 名/值 对<br>		bool set(const  JString&amp; name, const JConfigVal&amp; value)<br>		{<br>			// 查找内容<br>			DictIterator iter  = m_Items.find( name );<br>			if(iter ==  m_Items.end())<br>			{<br>				// 没找到, 插入<br>				m_Items.insert( Dict::value_type( name, value));<br>			}<br>			// 如果已存在, 修改<br>			m_Items[name] = value;<br>			return true;<br>		}<br>		bool get(JString&amp; name, JConfigVal&amp; value)const<br>		{<br>			// 查找内容<br>			ConstDictIterator iter  = m_Items.find( name );<br>			if(iter ==  m_Items.end())<br>			{<br>				// 没找到, <br>				return false;<br>			}<br>			// 如果已存在, 返回<br>			value = iter-&gt;second;<br>			return true;<br>		}<br>	};<br>private:<br>	// <br>	typedef std::vector&lt;JConfigSection&gt;::iterator  SectionIter;<br>	typedef std::vector&lt;JConfigSection&gt;::const_iterator  ConstSectionIter;<br>	// 创建一个节<br>	bool createSection(const JString&amp; sectionName); <br>	// 查找节, 返回对应的索引<br>	//      如果不存在, 返回 end(), <br>	ConstSectionIter  findSection(const  JString&amp; sectionName)const;<br>	SectionIter  findSection(const  JString&amp; sectionName);<br>	// const static int MAX_SECTION = 10;	//最多的节数<br>private:<br>	std::vector&lt;JConfigSection&gt;  m_Sections;<br>	//  不允许拷贝对象<br>	DECLARE_NO_COPY_CLASS(JFileConfig);<br>};<br><br>}	//end namespace<br><br>#endif //__JFILECONFIG_H__<img src ="http://www.cppblog.com/iwangchuchu/aggbug/111940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iwangchuchu/" target="_blank">jmchxy</a> 2010-04-08 12:12 <a href="http://www.cppblog.com/iwangchuchu/archive/2010/04/08/110323.html#111940#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: STL容器实现IniFileParser</title><link>http://www.cppblog.com/iwangchuchu/archive/2010/03/29/110323.html#110882</link><dc:creator>淡月清风</dc:creator><author>淡月清风</author><pubDate>Mon, 29 Mar 2010 08:29:00 GMT</pubDate><guid>http://www.cppblog.com/iwangchuchu/archive/2010/03/29/110323.html#110882</guid><description><![CDATA[哇，完全没有注释<img src ="http://www.cppblog.com/iwangchuchu/aggbug/110882.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iwangchuchu/" target="_blank">淡月清风</a> 2010-03-29 16:29 <a href="http://www.cppblog.com/iwangchuchu/archive/2010/03/29/110323.html#110882#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: STL容器实现IniFileParser</title><link>http://www.cppblog.com/iwangchuchu/archive/2010/03/23/110323.html#110369</link><dc:creator>萌萌</dc:creator><author>萌萌</author><pubDate>Tue, 23 Mar 2010 12:03:00 GMT</pubDate><guid>http://www.cppblog.com/iwangchuchu/archive/2010/03/23/110323.html#110369</guid><description><![CDATA[你不写提要 怎么看啊<img src ="http://www.cppblog.com/iwangchuchu/aggbug/110369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iwangchuchu/" target="_blank">萌萌</a> 2010-03-23 20:03 <a href="http://www.cppblog.com/iwangchuchu/archive/2010/03/23/110323.html#110369#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: STL容器实现IniFileParser</title><link>http://www.cppblog.com/iwangchuchu/archive/2010/03/23/110323.html#110338</link><dc:creator>陈梓瀚(vczh)</dc:creator><author>陈梓瀚(vczh)</author><pubDate>Tue, 23 Mar 2010 03:23:00 GMT</pubDate><guid>http://www.cppblog.com/iwangchuchu/archive/2010/03/23/110323.html#110338</guid><description><![CDATA[<a target="_new" href="http://www.cppblog.com/vczh/archive/2010/03/07/109103.html">http://www.cppblog.com/vczh/archive/2010/03/07/109103.html</a><img src ="http://www.cppblog.com/iwangchuchu/aggbug/110338.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iwangchuchu/" target="_blank">陈梓瀚(vczh)</a> 2010-03-23 11:23 <a href="http://www.cppblog.com/iwangchuchu/archive/2010/03/23/110323.html#110338#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>