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   bool ChangeTo (const char* filename)
00054   {
00055     if (!vfs) return false;
00056 
00057     csString dir(filename);
00058     dir.Truncate(dir.FindLast('/'));
00059     vfs->PushDir ();
00060     popCount++;
00061 
00062     return vfs->ChDir (dir);
00063   }
00064 
00069   bool ChangeToFull (const char* filename)
00070   {
00071     if (!vfs) return false;
00072 
00073     // We must make a copy of the filename because it can be a direct
00074     // pointer to vfs->GetCwd() and vfs->PushDir() corrupts that pointer.
00075     csString copy (filename);
00076 
00077     vfs->PushDir ();
00078     popCount++;
00079 
00080     return vfs->ChDir (copy);
00081   }
00082 
00089   void PushDir ()
00090   {
00091     vfs->PushDir ();
00092     popCount++;
00093   }
00094 };

Generated for Crystal Space 2.0 by doxygen 1.7.6.1