summaryrefslogtreecommitdiff
path: root/src/stable/file.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
committerMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
commit469bbcf0701e1eb8a6670c23145b0da87357e178 (patch)
treeb5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/file.h
parentee1b79396076edc4e30aefb285fada03bb45e80d (diff)
downloadlibbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/file.h')
-rw-r--r--src/stable/file.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/stable/file.h b/src/stable/file.h
new file mode 100644
index 0000000..e3225fa
--- /dev/null
+++ b/src/stable/file.h
@@ -0,0 +1,106 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_FILE_H
9#define BU_FILE_H
10
11#include <stdint.h>
12#include <sys/types.h>
13
14#include "bu/stream.h"
15#include "bu/string.h"
16#include "bu/exceptionbase.h"
17
18namespace Bu
19{
20 subExceptionDecl( FileException );
21
22 /**
23 * A file stream.
24 *@ingroup Streams
25 */
26 class File : public Bu::Stream
27 {
28 public:
29 File( const Bu::String &sName, int iFlags );
30 File( int fd );
31 virtual ~File();
32
33 virtual void close();
34 virtual Bu::size read( void *pBuf, Bu::size nBytes );
35 virtual Bu::size write( const void *pBuf, Bu::size nBytes );
36 using Stream::write;
37
38 virtual Bu::size tell();
39 virtual void seek( Bu::size offset );
40 virtual void setPos( Bu::size pos );
41 virtual void setPosEnd( Bu::size pos );
42 virtual bool isEos();
43 virtual bool isOpen();
44
45 virtual void flush();
46
47 virtual bool canRead();
48 virtual bool canWrite();
49
50 virtual bool isReadable();
51 virtual bool isWritable();
52 virtual bool isSeekable();
53
54 virtual bool isBlocking();
55 virtual void setBlocking( bool bBlocking=true );
56
57 enum {
58 // Flags
59 Read = 0x01, ///< Open file for reading
60 Write = 0x02, ///< Open file for writing
61 Create = 0x04, ///< Create file if it doesn't exist
62 Truncate = 0x08, ///< Truncate file if it does exist
63 Append = 0x10, ///< Always append on every write
64 NonBlock = 0x20, ///< Open file in non-blocking mode
65 Exclusive = 0x44, ///< Create file, if it exists then fail
66
67 // Helpful mixes
68 ReadWrite = 0x03, ///< Open for reading and writing
69 WriteNew = 0x0E ///< Create a file (or truncate) for writing.
70 /// Same as Write|Create|Truncate
71 };
72
73 virtual void setSize( Bu::size iSize );
74
75 virtual size getSize() const;
76 virtual size getBlockSize() const;
77 virtual Bu::String getLocation() const;
78
79 /**
80 * Create a temp file and return its handle. The file is opened
81 * Read/Write.
82 *@param sName (Bu::String) Give in the form: "/tmp/tmpfileXXXXXXXX"
83 * It will alter your (sName) setting the 'X's to random
84 * characters.
85 *@returns (Bu::File) A file object representing your temp file.
86 */
87 static Bu::File tempFile( Bu::String &sName );
88
89#ifndef WIN32
90 /**
91 * Change the file access permissions.
92 *@param t (mode_t) The new file access permissions.
93 */
94 void chmod( mode_t t );
95#endif
96
97 private:
98 int getPosixFlags( int iFlags );
99
100 private:
101 int fd;
102 bool bEos;
103 };
104}
105
106#endif