<!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>Crystal Space 1.2.1: cstool/vfsdirchange.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>cstool/vfsdirchange.h</h1><a href="vfsdirchange_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2005 by Jorrit Tyberghein</span> <a name="l00003"></a>00003 <span class="comment"> (C) 2005 by Frank Richter</span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00006"></a>00006 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00007"></a>00007 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00008"></a>00008 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"></span> <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00016"></a>00016 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00017"></a>00017 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00018"></a>00018 <span class="comment">*/</span> <a name="l00019"></a>00019 <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="vfs_8h.html" title="Virtual File System SCF interface.">iutil/vfs.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="csstring_8h.html" title="String utility class.">csutil/csstring.h</a>"</span> <a name="l00026"></a>00026 <a name="l00031"></a><a class="code" href="classcsVfsDirectoryChanger.html">00031</a> <span class="keyword">class </span><a class="code" href="classcsVfsDirectoryChanger.html" title="Helper class to change the current VFS directory and restore the previous directory...">csVfsDirectoryChanger</a> <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <a class="code" href="classcsRef.html" title="A smart pointer.">csRef<iVFS></a> vfs; <a name="l00038"></a>00038 <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> popCount; <a name="l00039"></a>00039 <span class="keyword">public</span>: <a name="l00041"></a><a class="code" href="classcsVfsDirectoryChanger.html#099b0cce77fa3c7518aea39f87a6848f">00041</a> <a class="code" href="classcsVfsDirectoryChanger.html#099b0cce77fa3c7518aea39f87a6848f" title="Create instance.">csVfsDirectoryChanger</a> (<a class="code" href="structiVFS.html" title="The Virtual Filesystem Class is intended to be the only way for Crystal Space engine...">iVFS</a>* vfs) : vfs(vfs), popCount(0) { } <a name="l00043"></a><a class="code" href="classcsVfsDirectoryChanger.html#4dec5a5654c0382679c2a57bb0f7c0f8">00043</a> <a class="code" href="classcsVfsDirectoryChanger.html#4dec5a5654c0382679c2a57bb0f7c0f8" title="Destroy instance. Restores the old directory if ChangeTo() was called.">~csVfsDirectoryChanger</a>() <a name="l00044"></a>00044 { <a name="l00045"></a>00045 <span class="keywordflow">while</span> (popCount--) vfs->PopDir(); <a name="l00046"></a>00046 } <a name="l00053"></a><a class="code" href="classcsVfsDirectoryChanger.html#56c2978e303462165e8fab5f39485ca0">00053</a> <span class="keywordtype">void</span> <a class="code" href="classcsVfsDirectoryChanger.html#56c2978e303462165e8fab5f39485ca0" title="Change to the directory filename is in.">ChangeTo</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>* filename) <a name="l00054"></a>00054 { <a name="l00055"></a>00055 <span class="keywordflow">if</span> (!vfs) <span class="keywordflow">return</span>; <a name="l00056"></a>00056 <span class="keyword">const</span> <span class="keywordtype">char</span>* slash = strrchr (filename, <span class="charliteral">'/'</span>); <a name="l00057"></a>00057 <span class="keywordflow">if</span> (slash != 0) <a name="l00058"></a>00058 { <a name="l00059"></a>00059 <a class="code" href="classcsString.html" title="Thin wrapper around csStringFast&lt;&gt; with its default buffer size.">csString</a> dir; <a name="l00060"></a>00060 dir.<a class="code" href="classcsStringBase.html#6bb4fbecd065935ea4c6e0d9420a4b3f" title="Replace contents of this string with the contents of another.">Replace</a> (filename, slash - filename); <a name="l00061"></a>00061 vfs->PushDir (); <a name="l00062"></a>00062 vfs->ChDir (dir); <a name="l00063"></a>00063 popCount++; <a name="l00064"></a>00064 } <a name="l00065"></a>00065 } <a name="l00072"></a><a class="code" href="classcsVfsDirectoryChanger.html#e36127c7dba3a300f006a9bee025a5be">00072</a> <span class="keywordtype">void</span> <a class="code" href="classcsVfsDirectoryChanger.html#e36127c7dba3a300f006a9bee025a5be" title="Just pushes the current directory, but doesn&#39;t change it in anyway - useful when...">PushDir</a> () <a name="l00073"></a>00073 { <a name="l00074"></a>00074 vfs->PushDir (); <a name="l00075"></a>00075 popCount++; <a name="l00076"></a>00076 } <a name="l00077"></a>00077 }; </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>