Cafu Engine
File_local.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_LOCAL_HPP_INCLUDED
8 #define CAFU_FILESYS_FILE_LOCAL_HPP_INCLUDED
9 
10 #include <fstream>
11 
12 #include "File.hpp"
13 
14 
15 namespace cf
16 {
17  namespace FileSys
18  {
19  class LocalInFileT : public InFileI
20  {
21  public:
22 
23  /// Constructor.
24  LocalInFileT(const std::string& BaseName_, const std::string& FullName_);
25 
26  // Implement all the (pure) virtual methods of the FileI and InFileI interfaces.
27  bool IsOpen() const;
28  const std::string& GetBaseName() const;
29  const std::string& GetFullName() const;
30  uint64_t GetPos() const;
31  bool Seek(int32_t Offset, SeekFromT SeekFrom);
32  uint32_t Read(char* Buffer, uint32_t Size);
33  uint64_t GetSize() const;
34 
35 
36  private:
37 
38  std::string BaseName; ///< The relative name of the file, agnostic of the local path.
39  std::string FullName; ///< The BaseName prepended by the local path.
40  mutable std::ifstream ifs; ///< The input file stream.
41  };
42 
43 
44  class LocalOutFileT : public OutFileI
45  {
46  public:
47 
48  /// Constructor.
49  LocalOutFileT(const std::string& BaseName_, const std::string& FullName_);
50 
51  // Implement all the (pure) virtual methods of the FileI and OutFileI interfaces.
52  bool IsOpen() const;
53  const std::string& GetBaseName() const;
54  const std::string& GetFullName() const;
55  uint64_t GetPos() const;
56  bool Seek(int32_t Offset, SeekFromT SeekFrom);
57  void Write(const char* Buffer, uint32_t Size);
58 
59 
60  private:
61 
62  std::string BaseName; ///< The relative name of the file, agnostic of the local path.
63  std::string FullName; ///< The BaseName prepended by the local path.
64  mutable std::ofstream ofs; ///< The output file stream.
65  };
66  }
67 }
68 
69 #endif
void Write(const char *Buffer, uint32_t Size)
Writes the contents of Buffer, which has size Size, into the file.
Definition: File_local.cpp:144
bool Seek(int32_t Offset, SeekFromT SeekFrom)
Modifies the position of the read/write pointer in the file.
Definition: File_local.cpp:131
uint32_t Read(char *Buffer, uint32_t Size)
Reads Size bytes into the Buffer.
Definition: File_local.cpp:70
Definition: File.hpp:55
const std::string & GetFullName() const
Returns the full name of this file.
Definition: File_local.cpp:40
uint64_t GetSize() const
Returns the size of the file.
Definition: File_local.cpp:78
bool IsOpen() const
Returns whether the file has successfully been opened and is still open.
Definition: File_local.cpp:99
LocalInFileT(const std::string &BaseName_, const std::string &FullName_)
Constructor.
Definition: File_local.cpp:12
LocalOutFileT(const std::string &BaseName_, const std::string &FullName_)
Constructor.
Definition: File_local.cpp:91
uint64_t GetPos() const
Returns the current read/write position in the file.
Definition: File_local.cpp:46
SeekFromT
The values of this enumeration define from where the seek operation applies the offset.
Definition: File.hpp:28
Definition: File_local.hpp:19
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_local.cpp:113
bool IsOpen() const
Returns whether the file has successfully been opened and is still open.
Definition: File_local.cpp:20
Definition: File.hpp:68
Definition: File_local.hpp:44
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_local.cpp:34
bool Seek(int32_t Offset, SeekFromT SeekFrom)
Modifies the position of the read/write pointer in the file.
Definition: File_local.cpp:52
const std::string & GetFullName() const
Returns the full name of this file.
Definition: File_local.cpp:119
uint64_t GetPos() const
Returns the current read/write position in the file.
Definition: File_local.cpp:125