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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: wxConfigPathChanger Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
<tbody>
<tr>
<td id="projectlogo">
<a href="http://www.wxwidgets.org/" target="_new">
<img alt="wxWidgets" src="logo.png"/>
</a>
</td>
<td style="padding-left: 0.5em; text-align: right;">
<span id="projectnumber">Version: 3.0.2</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Categories</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="annotated.html"><span>Class List</span></a></li>
<li><a href="classes.html"><span>Class Index</span></a></li>
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> |
<a href="classwx_config_path_changer-members.html">List of all members</a> </div>
<div class="headertitle">
<div class="title">wxConfigPathChanger Class Reference<div class="ingroups"><a class="el" href="group__group__class__cfg.html">Application and System configuration</a></div></div> </div>
</div><!--header-->
<div class="contents">
<p><code>#include <wx/config.h></code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>A handy little class which changes the current path in a wxConfig object and restores it in dtor. </p>
<p>Declaring a local variable of this type, it's possible to work in a specific directory and ensure that the path is automatically restored when the function returns.</p>
<p>For example: </p>
<div class="fragment"><div class="line"><span class="comment">// this function loads somes settings from the given wxConfig object;</span></div>
<div class="line"><span class="comment">// the path selected inside it is left unchanged</span></div>
<div class="line"><span class="keywordtype">bool</span> LoadMySettings(<a class="code" href="classwx_config_base.html" title="wxConfigBase defines the basic interface of all config classes.">wxConfigBase</a>* cfg)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="classwx_config_path_changer.html" title="A handy little class which changes the current path in a wxConfig object and restores it in dtor...">wxConfigPathChanger</a> changer(cfg, <span class="stringliteral">"/Foo/Data/SomeString"</span>);</div>
<div class="line"> <a class="code" href="classwx_string.html" title="String class for passing textual data to or receiving it from wxWidgets.">wxString</a> str;</div>
<div class="line"> <span class="keywordflow">if</span> ( !config-><a class="code" href="classwx_config_base.html#af89fb6c338f200bec028480ac0f3b1d8" title="Read a string from the key, returning true if the value was read.">Read</a>(<span class="stringliteral">"SomeString"</span>, &str) ) {</div>
<div class="line"> <a class="code" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError</a>(<span class="stringliteral">"Couldn't read SomeString!"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>; </div>
<div class="line"> <span class="comment">// NOTE: without wxConfigPathChanger it would be easy to forget to</span></div>
<div class="line"> <span class="comment">// set the old path back into the wxConfig object before this return!</span></div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// do something useful with SomeString...</span></div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>; <span class="comment">// again: wxConfigPathChanger dtor will restore the original wxConfig path</span></div>
<div class="line">}</div>
</div><!-- fragment --><h2></h2>
<div><span class="lib">Library:</span>  <span class="lib_text"><a class="el" href="page_libs.html#page_libs_wxbase">wxBase</a></span></div><div><span class="category">Category:</span>  <span class="category_text"><a class="el" href="group__group__class__cfg.html">Application and System configuration</a></span></div> </div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a60bd80a11d785b8ca7c4cb9fb97dd6a9"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_config_path_changer.html#a60bd80a11d785b8ca7c4cb9fb97dd6a9">wxConfigPathChanger</a> (const <a class="el" href="classwx_config_base.html">wxConfigBase</a> *pContainer, const <a class="el" href="classwx_string.html">wxString</a> &strEntry)</td></tr>
<tr class="memdesc:a60bd80a11d785b8ca7c4cb9fb97dd6a9"><td class="mdescLeft"> </td><td class="mdescRight">Changes the path of the given <a class="el" href="classwx_config_base.html" title="wxConfigBase defines the basic interface of all config classes.">wxConfigBase</a> object so that the key <em>strEntry</em> is accessible (for read or write). <a href="#a60bd80a11d785b8ca7c4cb9fb97dd6a9"></a><br/></td></tr>
<tr class="separator:a60bd80a11d785b8ca7c4cb9fb97dd6a9"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a09ab9763983e12e69a03c45c68e39a4e"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_config_path_changer.html#a09ab9763983e12e69a03c45c68e39a4e">~wxConfigPathChanger</a> ()</td></tr>
<tr class="memdesc:a09ab9763983e12e69a03c45c68e39a4e"><td class="mdescLeft"> </td><td class="mdescRight">Restores the path selected, inside the wxConfig object passed to the ctor, to the path which was selected when the <a class="el" href="classwx_config_path_changer.html" title="A handy little class which changes the current path in a wxConfig object and restores it in dtor...">wxConfigPathChanger</a> ctor was called. <a href="#a09ab9763983e12e69a03c45c68e39a4e"></a><br/></td></tr>
<tr class="separator:a09ab9763983e12e69a03c45c68e39a4e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ac822f3e59e19bf8fd764dee3b60b2a24"><td class="memItemLeft" align="right" valign="top">const <a class="el" href="classwx_string.html">wxString</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_config_path_changer.html#ac822f3e59e19bf8fd764dee3b60b2a24">Name</a> () const </td></tr>
<tr class="memdesc:ac822f3e59e19bf8fd764dee3b60b2a24"><td class="mdescLeft"> </td><td class="mdescRight">Returns the name of the key which was passed to the ctor. <a href="#ac822f3e59e19bf8fd764dee3b60b2a24"></a><br/></td></tr>
<tr class="separator:ac822f3e59e19bf8fd764dee3b60b2a24"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ad5fb2a36e44d511dba8a575667c4ff1f"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_config_path_changer.html#ad5fb2a36e44d511dba8a575667c4ff1f">UpdateIfDeleted</a> ()</td></tr>
<tr class="memdesc:ad5fb2a36e44d511dba8a575667c4ff1f"><td class="mdescLeft"> </td><td class="mdescRight">This method must be called if the original path inside the wxConfig object (i.e. <a href="#ad5fb2a36e44d511dba8a575667c4ff1f"></a><br/></td></tr>
<tr class="separator:ad5fb2a36e44d511dba8a575667c4ff1f"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="a60bd80a11d785b8ca7c4cb9fb97dd6a9"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxConfigPathChanger::wxConfigPathChanger </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classwx_config_base.html">wxConfigBase</a> * </td>
<td class="paramname"><em>pContainer</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classwx_string.html">wxString</a> & </td>
<td class="paramname"><em>strEntry</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Changes the path of the given <a class="el" href="classwx_config_base.html" title="wxConfigBase defines the basic interface of all config classes.">wxConfigBase</a> object so that the key <em>strEntry</em> is accessible (for read or write). </p>
<p>In other words, the ctor uses <a class="el" href="classwx_config_base.html#ad290d3fe7fad4f39a4bb2959db89b379" title="Set current path: if the first character is '/', it is the absolute path, otherwise it is a relative ...">wxConfigBase::SetPath()</a> with everything which precedes the last slash of <em>strEntry</em>, so that: </p>
<div class="fragment"><div class="line"><a class="code" href="classwx_config_path_changer.html#a60bd80a11d785b8ca7c4cb9fb97dd6a9" title="Changes the path of the given wxConfigBase object so that the key strEntry is accessible (for read or...">wxConfigPathChanger</a>(<a class="code" href="classwx_config_base.html#a61bfb04c1c133190b3e851b252ed1c60" title="Get the current config object.">wxConfigBase::Get</a>(), <span class="stringliteral">"/MyProgram/SomeKeyName"</span>);</div>
</div><!-- fragment --><p> has the same effect of: </p>
<div class="fragment"><div class="line"><a class="code" href="classwx_config_path_changer.html#a60bd80a11d785b8ca7c4cb9fb97dd6a9" title="Changes the path of the given wxConfigBase object so that the key strEntry is accessible (for read or...">wxConfigPathChanger</a>(<a class="code" href="classwx_config_base.html#a61bfb04c1c133190b3e851b252ed1c60" title="Get the current config object.">wxConfigBase::Get</a>(), <span class="stringliteral">"/MyProgram/"</span>);</div>
</div><!-- fragment -->
</div>
</div>
<a class="anchor" id="a09ab9763983e12e69a03c45c68e39a4e"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxConfigPathChanger::~wxConfigPathChanger </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Restores the path selected, inside the wxConfig object passed to the ctor, to the path which was selected when the <a class="el" href="classwx_config_path_changer.html" title="A handy little class which changes the current path in a wxConfig object and restores it in dtor...">wxConfigPathChanger</a> ctor was called. </p>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="ac822f3e59e19bf8fd764dee3b60b2a24"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">const <a class="el" href="classwx_string.html">wxString</a>& wxConfigPathChanger::Name </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns the name of the key which was passed to the ctor. </p>
<p>The "name" is just anything which follows the last slash of the string given to the ctor. </p>
</div>
</div>
<a class="anchor" id="ad5fb2a36e44d511dba8a575667c4ff1f"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void wxConfigPathChanger::UpdateIfDeleted </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This method must be called if the original path inside the wxConfig object (i.e. </p>
<p>the current path at the moment of creation of this <a class="el" href="classwx_config_path_changer.html" title="A handy little class which changes the current path in a wxConfig object and restores it in dtor...">wxConfigPathChanger</a> object) could have been deleted, thus preventing <a class="el" href="classwx_config_path_changer.html" title="A handy little class which changes the current path in a wxConfig object and restores it in dtor...">wxConfigPathChanger</a> from restoring the not existing (any more) path.</p>
<p>If the original path doesn't exist any more, the path will be restored to the deepest still existing component of the old path. </p>
</div>
</div>
</div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:45 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>
|