Cafu Engine
File.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_FILESYS_FILE_HPP_INCLUDED
8 #define CAFU_FILESYS_FILE_HPP_INCLUDED
9 
10 #include <string>
11 
12 #if defined(_WIN32) && _MSC_VER<1600
13 #include "pstdint.h" // Paul Hsieh's portable implementation of the stdint.h header.
14 #else
15 #include <stdint.h>
16 #endif
17 
18 
19 namespace cf
20 {
21  namespace FileSys
22  {
23  class FileI
24  {
25  public:
26 
27  /// The values of this enumeration define from where the seek operation applies the offset.
28  enum SeekFromT { FROM_BEGINNING, FROM_CURRENT_POS, FROM_END };
29 
30 
31  /// The virtual destructor, so that derived classes can safely be deleted via a FileI (base class) pointer.
32  virtual ~FileI() { }
33 
34  /// Returns whether the file has successfully been opened and is still open.
35  virtual bool IsOpen() const=0;
36 
37  /// Returns the base name of this file. The base name is relative to and agnostic of the file system this file is in.
38  virtual const std::string& GetBaseName() const=0;
39 
40  /// Returns the full name of this file. The full name is the base name prepended by the file system specific path/URL.
41  /// TODO: Have a GetFileSys() method instead???
42  virtual const std::string& GetFullName() const=0;
43 
44  /// Returns the current read/write position in the file.
45  virtual uint64_t GetPos() const=0;
46 
47  /// Modifies the position of the read/write pointer in the file.
48  /// @param Offset How much to move the pointer.
49  /// @param SeekFrom Defines from where the offset is applied, see SeekFromT for possible values.
50  /// @returns true if the seek operation was successful, false otherwise.
51  virtual bool Seek(int32_t Offset, SeekFromT SeekFrom)=0;
52  };
53 
54 
55  class InFileI : public FileI
56  {
57  public:
58 
59  /// Reads Size bytes into the Buffer.
60  /// @returns How many bytes have actually been read.
61  virtual uint32_t Read(char* Buffer, uint32_t Size)=0;
62 
63  /// Returns the size of the file.
64  virtual uint64_t GetSize() const=0;
65  };
66 
67 
68  class OutFileI : public FileI
69  {
70  public:
71 
72  /// Writes the contents of Buffer, which has size Size, into the file.
73  virtual void Write(const char* Buffer, uint32_t Size)=0;
74  };
75  }
76 }
77 
78 #endif
Definition: File.hpp:55
virtual ~FileI()
The virtual destructor, so that derived classes can safely be deleted via a FileI (base class) pointe...
Definition: File.hpp:32
virtual bool Seek(int32_t Offset, SeekFromT SeekFrom)=0
Modifies the position of the read/write pointer in the file.
virtual const std::string & GetBaseName() const =0
Returns the base name of this file. The base name is relative to and agnostic of the file system this...
virtual void Write(const char *Buffer, uint32_t Size)=0
Writes the contents of Buffer, which has size Size, into the file.
SeekFromT
The values of this enumeration define from where the seek operation applies the offset.
Definition: File.hpp:28
virtual uint32_t Read(char *Buffer, uint32_t Size)=0
Reads Size bytes into the Buffer.
virtual uint64_t GetSize() const =0
Returns the size of the file.
virtual const std::string & GetFullName() const =0
Returns the full name of this file.
Definition: File.hpp:68
Definition: File.hpp:23
virtual uint64_t GetPos() const =0
Returns the current read/write position in the file.
virtual bool IsOpen() const =0
Returns whether the file has successfully been opened and is still open.