ZenLib
File.h
Go to the documentation of this file.
1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  * Use of this source code is governed by a zlib-style license that can
4  * be found in the License.txt file in the root of the source tree.
5  */
6 
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // File functions
10 //
11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 
13 //---------------------------------------------------------------------------
14 #ifndef ZenLib_FileH
15 #define ZenLib_FileH
16 //---------------------------------------------------------------------------
17 
18 //---------------------------------------------------------------------------
19 #include "ZenLib/Ztring.h"
20 
21 //---------------------------------------------------------------------------
22 
23 namespace ZenLib
24 {
25 
26 //***************************************************************************
27 /// @brief File manipulation
28 //***************************************************************************
29 
30 class File
31 {
32 public :
33  //---------------------------------------------------------------------------
34  /// @brief Options for Open method
35  enum access_t
36  {
37  Access_Read = 0, ///< Read permission
38  Access_Write = 1, ///< Write permission
39  Access_Read_Write = 2, ///< Read and Write permissions
40  Access_Write_Append = 3, ///< Write permission without deleting old file
41  Access_Write_Excluding = 4 ///< Write permission preventing reading
42  };
43 
44  //---------------------------------------------------------------------------
45  /// @brief Options for Move method
46  enum move_t
47  {
48  FromBegin = 0, ///< Begin of file
49  FromCurrent = 1, ///< Current position
50  FromEnd = 2 ///< End of file
51  };
52 
53  //Constructor/Destructor
54  File ();
56  ~File ();
57 
58  //Open/close
59  bool Open (const tstring &File_Name, access_t Access=Access_Read);
60  bool Create(const ZenLib::Ztring &File_Name, bool OverWrite=true);
61  void Close ();
62 
63  //Read/Write
64  size_t Read (int8u* Buffer, size_t Buffer_Size);
65  size_t Write (const int8u* Buffer, size_t Buffer_Size);
66  size_t Write (const Ztring &ToWrite);
67  bool Truncate (int64u Offset=(int64u)-1);
68 
69  //Moving
70  bool GoTo (int64s Position, move_t MoveMethod=FromBegin);
71  int64u Position_Get ();
72 
73  //Attributes
74  int64u Size_Get();
79  bool Opened_Get();
80 
81  //Helpers
82  static int64u Size_Get(const Ztring &File_Name);
83  static Ztring Created_Get(const Ztring &File_Name);
84  static Ztring Modified_Get(const Ztring &File_Name);
85  static bool Exists(const Ztring &File_Name);
86  static bool Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
87  static bool Move(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
88  static bool Delete(const Ztring &File_Name);
89 
90  //Temp
92  int64u Position; //Position is saved, may be not good because position may change
93  int64u Size; //Size is saved, may be not good because size may change
94  void* File_Handle;
95 };
96 
97 } //NameSpace
98 
99 #endif