CrystalSpace

Public API Reference

cstool/vfsdirchange.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005 by Jorrit Tyberghein
00003               (C) 2005 by Frank Richter
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00024 #include "iutil/vfs.h"
00025 #include "csutil/csstring.h"
00026 
00031 class csVfsDirectoryChanger
00032 {
00033   csRef<iVFS> vfs;
00038   uint popCount;
00039 public:
00041   csVfsDirectoryChanger (iVFS* vfs) : vfs(vfs), popCount(0) { }
00043   ~csVfsDirectoryChanger()
00044   {
00045     while (popCount--) vfs->PopDir();
00046   }
00053   void ChangeTo (const char* filename)
00054   {
00055     if (!vfs) return;
00056     const char* slash = strrchr (filename, '/');
00057     if (slash != 0)
00058     {
00059       csString dir;
00060       dir.Replace (filename, slash - filename);
00061       vfs->PushDir ();
00062       vfs->ChDir (dir);
00063       popCount++;
00064     }
00065   }
00072   void PushDir ()
00073   {
00074     vfs->PushDir ();
00075     popCount++;
00076   }
00077 };

Generated for Crystal Space 1.0.2 by doxygen 1.4.7