diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-06-03 07:18:23 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-06-03 07:18:23 +0000 |
commit | f16f239688b632fc54684c3e0e1430fd89a67db5 (patch) | |
tree | 6a6d4f3b5d5f4974af4c3cc47c7892e46c5ef201 /src/filemgr.cpp | |
parent | 4f1e5849d4a48eb674d81164ba4baba4ad51a89f (diff) | |
download | build-f16f239688b632fc54684c3e0e1430fd89a67db5.tar.gz build-f16f239688b632fc54684c3e0e1430fd89a67db5.tar.bz2 build-f16f239688b632fc54684c3e0e1430fd89a67db5.tar.xz build-f16f239688b632fc54684c3e0e1430fd89a67db5.zip |
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.
Diffstat (limited to 'src/filemgr.cpp')
-rw-r--r-- | src/filemgr.cpp | 46 |
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 | |||
3 | FileMgr::FileMgr() : | ||
4 | iNextId( 1 ) | ||
5 | { | ||
6 | } | ||
7 | |||
8 | FileMgr::~FileMgr() | ||
9 | { | ||
10 | for( FileHash::iterator i = hFile.begin(); i; i++ ) | ||
11 | { | ||
12 | delete *i; | ||
13 | } | ||
14 | } | ||
15 | |||
16 | int FileMgr::open( const Bu::String &sPath, int iMode ) | ||
17 | { | ||
18 | hFile.insert( iNextId, new Bu::File( sPath, iMode ) ); | ||
19 | return iNextId++; | ||
20 | } | ||
21 | |||
22 | Bu::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 | |||
34 | void 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 | |||