aboutsummaryrefslogtreecommitdiff
path: root/src/filemgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/filemgr.cpp')
-rw-r--r--src/filemgr.cpp46
1 files changed, 46 insertions, 0 deletions
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 @@
1#include "filemgr.h"
2
3FileMgr::FileMgr() :
4 iNextId( 1 )
5{
6}
7
8FileMgr::~FileMgr()
9{
10 for( FileHash::iterator i = hFile.begin(); i; i++ )
11 {
12 delete *i;
13 }
14}
15
16int FileMgr::open( const Bu::String &sPath, int iMode )
17{
18 hFile.insert( iNextId, new Bu::File( sPath, iMode ) );
19 return iNextId++;
20}
21
22Bu::File &FileMgr::get( int iId )
23{
24 try
25 {
26 return *hFile.get( iId );
27 }
28 catch(...)
29 {
30 throw Bu::ExceptionBase("Invalid file handle accessed.");
31 }
32}
33
34void FileMgr::close( int iId )
35{
36 try
37 {
38 delete hFile.get( iId );
39 hFile.erase( iId );
40 }
41 catch(...)
42 {
43 throw Bu::ExceptionBase("Invalid file handle accessed.");
44 }
45}
46