Cafu Engine
File_memory.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_MEMORY_HPP_INCLUDED
8 #define CAFU_FILESYS_FILE_MEMORY_HPP_INCLUDED
9 
10 #include "File.hpp"
11 #include "Templates/Array.hpp"
12 
13 
14 namespace cf
15 {
16  namespace FileSys
17  {
18  class MemoryInFileT : public InFileI
19  {
20  public:
21 
22  /// Constructor. Creates an empty memory file for reading.
23  /// Note that because the file is empty, the code that created the file should use the GetBuffer() method to set the initial contents.
24  MemoryInFileT(const std::string& FileName_);
25 
26  /// Returns a reference to the buffer that keeps the contents of this file.
27  ArrayT<char>& GetBuffer() { return Buffer; }
28 
29  /// Returns a const reference to the buffer that keeps the contents of this file.
30  const ArrayT<char>& GetBuffer() const { return Buffer; }
31 
32 
33  // Implement all the (pure) virtual methods of the FileI and InFileI interfaces.
34  bool IsOpen() const;
35  const std::string& GetBaseName() const;
36  const std::string& GetFullName() const;
37  uint64_t GetPos() const;
38  bool Seek(int32_t Offset, SeekFromT SeekFrom);
39  uint32_t Read(char* Buffer, uint32_t Size);
40  uint64_t GetSize() const;
41 
42 
43  private:
44 
45  std::string FileName; ///< The name of the file.
46  ArrayT<char> Buffer; ///< The contents of the file.
47  unsigned long ReadPos; ///< The position from which the next read operation starts.
48  };
49 
50 
51  /* class MemoryOutFileT : public OutFileI
52  {
53  public:
54 
55  /// Constructor.
56  MemoryOutFileT(const std::string& FileName_);
57 
58  // Implement all the (pure) virtual methods of the FileI and OutFileI interfaces.
59  bool IsOpen() const;
60  const std::string& GetBaseName() const;
61  const std::string& GetFullName() const;
62  uint64_t GetPos() const;
63  bool Seek(int32_t Offset, SeekFromT SeekFrom);
64  void Write(const char* Buffer, uint32_t Size);
65 
66 
67  private:
68 
69  // ...
70  }; */
71  }
72 }
73 
74 #endif
bool Seek(int32_t Offset, SeekFromT SeekFrom)
Modifies the position of the read/write pointer in the file.
Definition: File_memory.cpp:44
Definition: File.hpp:55
bool IsOpen() const
Returns whether the file has successfully been opened and is still open.
Definition: File_memory.cpp:20
const std::string & GetFullName() const
Returns the full name of this file.
Definition: File_memory.cpp:32
const ArrayT< char > & GetBuffer() const
Returns a const reference to the buffer that keeps the contents of this file.
Definition: File_memory.hpp:30
Definition: File_memory.hpp:18
ArrayT< char > & GetBuffer()
Returns a reference to the buffer that keeps the contents of this file.
Definition: File_memory.hpp:27
uint32_t Read(char *Buffer, uint32_t Size)
Reads Size bytes into the Buffer.
Definition: File_memory.cpp:76
SeekFromT
The values of this enumeration define from where the seek operation applies the offset.
Definition: File.hpp:28
const std::string & GetBaseName() const
Returns the base name of this file. The base name is relative to and agnostic of the file system this...
Definition: File_memory.cpp:26
MemoryInFileT(const std::string &FileName_)
Constructor.
Definition: File_memory.cpp:13
uint64_t GetPos() const
Returns the current read/write position in the file.
Definition: File_memory.cpp:38
uint64_t GetSize() const
Returns the size of the file.
Definition: File_memory.cpp:91