From f16f239688b632fc54684c3e0e1430fd89a67db5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 3 Jun 2011 07:18:23 +0000 Subject: I added basic support for "opaque" type variables. I think there's one more tweak to it that I would like to make, but it's fine for now. I also added open, close, read, and write functions. They work just fine, but I'll also add a readLine function, and maybe even a readToken function later. --- src/filemgr.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/filemgr.cpp (limited to 'src/filemgr.cpp') diff --git a/src/filemgr.cpp b/src/filemgr.cpp new file mode 100644 index 0000000..00f0410 --- /dev/null +++ b/src/filemgr.cpp @@ -0,0 +1,46 @@ +#include "filemgr.h" + +FileMgr::FileMgr() : + iNextId( 1 ) +{ +} + +FileMgr::~FileMgr() +{ + for( FileHash::iterator i = hFile.begin(); i; i++ ) + { + delete *i; + } +} + +int FileMgr::open( const Bu::String &sPath, int iMode ) +{ + hFile.insert( iNextId, new Bu::File( sPath, iMode ) ); + return iNextId++; +} + +Bu::File &FileMgr::get( int iId ) +{ + try + { + return *hFile.get( iId ); + } + catch(...) + { + throw Bu::ExceptionBase("Invalid file handle accessed."); + } +} + +void FileMgr::close( int iId ) +{ + try + { + delete hFile.get( iId ); + hFile.erase( iId ); + } + catch(...) + { + throw Bu::ExceptionBase("Invalid file handle accessed."); + } +} + -- cgit v1.2.3