📄 wg__config__store_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>wg_config_store.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> </center><hr><h1>wg_config_store.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_config_store.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CConfigStore class implementation</span>00004 <span class="comment">//</span>00005 <span class="comment">//</span>00006 <span class="comment">// Copyright (c) 2002 Rob Wiskow</span>00007 <span class="comment">// rob-dev@boxedchaos.com</span>00008 <span class="comment">//</span>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>00011 <span class="comment">// License as published by the Free Software Foundation; either</span>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>00013 <span class="comment">//</span>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00017 <span class="comment">// Lesser General Public License for more details.</span>00018 <span class="comment">//</span>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>00022 <span class="comment">//</span>00023 00024 00025 <span class="preprocessor">#include "wgui_include_config.h"</span>00026 <span class="preprocessor">#include "wg_config_store.h"</span>00027 <span class="preprocessor">#include "std_ex.h"</span>00028 <span class="preprocessor">#include "wg_debug.h"</span>00029 <span class="preprocessor">#include <fstream></span>00030 00031 00032 <span class="keyword">namespace </span>wGui00033 {00034 <a name="l00035"></a><a class="code" href="classwGui_1_1CConfigStore.html#a2">00035</a> std::pair<bool, std::string> CConfigStore::GetStringEntry(std::string sKey)<span class="keyword"> const</span>00036 <span class="keyword"></span>{00037 <span class="keywordtype">bool</span> bSuccess = <span class="keyword">false</span>;00038 std::string sValue = <span class="stringliteral">""</span>;00039 t_SettingsMap::const_iterator iter = m_SettingsMap.find(sKey);00040 <span class="keywordflow">if</span> (iter != m_SettingsMap.end())00041 {00042 bSuccess = <span class="keyword">true</span>;00043 sValue = iter->second;00044 }00045 00046 <span class="keywordflow">return</span> std::make_pair(bSuccess, sValue);00047 }00048 00049 <a name="l00050"></a><a class="code" href="classwGui_1_1CConfigStore.html#a3">00050</a> std::pair<bool, long int> CConfigStore::GetLongIntEntry(std::string sKey)<span class="keyword"> const</span>00051 <span class="keyword"></span>{00052 <span class="keywordtype">bool</span> bSuccess = <span class="keyword">false</span>;00053 <span class="keywordtype">long</span> <span class="keywordtype">int</span> lValue = 0;00054 t_SettingsMap::const_iterator iter = m_SettingsMap.find(sKey);00055 <span class="keywordflow">if</span> (iter != m_SettingsMap.end())00056 {00057 bSuccess = <span class="keyword">true</span>;00058 lValue = stdex::atol(iter->second);00059 }00060 00061 <span class="keywordflow">return</span> std::make_pair(bSuccess, lValue);00062 }00063 00064 <a name="l00065"></a><a class="code" href="classwGui_1_1CConfigStore.html#a4">00065</a> std::pair<bool, double> CConfigStore::GetDoubleEntry(std::string sKey)<span class="keyword"> const</span>00066 <span class="keyword"></span>{00067 <span class="keywordtype">bool</span> bSuccess = <span class="keyword">false</span>;00068 <span class="keywordtype">double</span> dValue = 0.0;00069 t_SettingsMap::const_iterator iter = m_SettingsMap.find(sKey);00070 <span class="keywordflow">if</span> (iter != m_SettingsMap.end())00071 {00072 bSuccess = <span class="keyword">true</span>;00073 dValue = stdex::atod(iter->second);00074 }00075 00076 <span class="keywordflow">return</span> std::make_pair(bSuccess, dValue);00077 }00078 00079 <a name="l00080"></a><a class="code" href="classwGui_1_1CConfigStore.html#a5">00080</a> <span class="keywordtype">void</span> CConfigStore::SetStringEntry(std::string sKey, std::string sValue)00081 {00082 m_SettingsMap[sKey] = sValue;00083 }00084 00085 <a name="l00086"></a><a class="code" href="classwGui_1_1CConfigStore.html#a6">00086</a> <span class="keywordtype">void</span> CConfigStore::SetLongIntEntry(std::string sKey, <span class="keywordtype">long</span> <span class="keywordtype">int</span> lValue)00087 {00088 m_SettingsMap[sKey] = stdex::ltoa(lValue);00089 }00090 00091 <a name="l00092"></a><a class="code" href="classwGui_1_1CConfigStore.html#a7">00092</a> <span class="keywordtype">void</span> CConfigStore::SetDoubleEntry(std::string sKey, <span class="keywordtype">double</span> dValue)00093 {00094 m_SettingsMap[sKey] = stdex::dtoa(dValue);00095 }00096 00097 <a name="l00098"></a><a class="code" href="classwGui_1_1CConfigStore.html#a8">00098</a> <span class="keywordtype">void</span> CConfigStore::RemoveEntry(std::string sKey)00099 {00100 m_SettingsMap.erase(sKey);00101 }00102 00103 <a name="l00104"></a><a class="code" href="classwGui_1_1CConfigStore.html#a9">00104</a> <span class="keywordtype">bool</span> CConfigStore::EntryExists(std::string sKey)<span class="keyword"> const</span>00105 <span class="keyword"></span>{00106 <span class="keywordflow">return</span> (m_SettingsMap.find(sKey) != m_SettingsMap.end());00107 }00108 00109 <a name="l00110"></a><a class="code" href="classwGui_1_1CConfigStore.html#a10">00110</a> <span class="keywordtype">void</span> CConfigStore::StoreToFile(std::string sFilename)<span class="keyword"> const</span>00111 <span class="keyword"></span>{00112 std::ofstream File;00113 00114 File.open(sFilename.c_str(), std::ios::out | std::ios::trunc);00115 <span class="keywordflow">if</span> (File.is_open())00116 {00117 <span class="keywordflow">for</span> (t_SettingsMap::const_iterator iter = m_SettingsMap.begin(); iter != m_SettingsMap.end(); ++iter)00118 {00119 File << iter->first << <span class="stringliteral">" = "</span> << iter->second << std::endl;00120 }00121 File.close();00122 }00123 }00124 00125 <a name="l00126"></a><a class="code" href="classwGui_1_1CConfigStore.html#a11">00126</a> <span class="keywordtype">void</span> CConfigStore::ReadFromFile(std::string sFilename)00127 {00128 std::ifstream File;00129 std::string sBuffer = <span class="stringliteral">""</span>;00130 std::string sKey = <span class="stringliteral">""</span>;00131 std::string sValue = <span class="stringliteral">""</span>;00132 00133 <span class="keywordflow">if</span> (! sFilename.empty())00134 {00135 File.open(sFilename.c_str());00136 <span class="keywordflow">if</span> (File.is_open())00137 {00138 <span class="keywordflow">while</span> (! File.eof())00139 {00140 std::getline(File, sBuffer);00141 <span class="keywordflow">if</span> (sBuffer[0] != <span class="charliteral">'#'</span>)00142 {00143 std::string::size_type splitPoint = sBuffer.find_first_of(<span class="stringliteral">"="</span>);00144 sKey = stdex::TrimString(sBuffer.substr(0, splitPoint));00145 sValue = stdex::TrimString(sBuffer.substr(splitPoint + 1));00146 <span class="keywordflow">if</span> (! sKey.empty())00147 {00148 m_SettingsMap[sKey] = sValue;00149 }00150 }00151 }00152 File.close();00153 }00154 }00155 }00156 00157 <a name="l00158"></a><a class="code" href="classwGui_1_1CConfigStore.html#a12">00158</a> <span class="keywordtype">void</span> CConfigStore::Clear(<span class="keywordtype">void</span>)00159 {00160 m_SettingsMap.clear();00161 }00162 00163 00164 }</pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:22 2003 for wGui by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -