ZenLib
File.h
Go to the documentation of this file.
1 // ZenLib::File - File functions
2 // Copyright (C) 2007-2010 MediaArea.net SARL, Info@MediaArea.net
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would be
15 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
18 // 3. This notice may not be removed or altered from any source distribution.
19 //
20 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 // File functions
24 //
25 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 
27 //---------------------------------------------------------------------------
28 #ifndef ZenLib_FileH
29 #define ZenLib_FileH
30 //---------------------------------------------------------------------------
31 
32 //---------------------------------------------------------------------------
33 #include "ZenLib/Conf.h"
34 #include "ZenLib/Ztring.h"
35 //---------------------------------------------------------------------------
36 
37 namespace ZenLib
38 {
39 
40 //***************************************************************************
41 /// @brief File manipulation
42 //***************************************************************************
43 
44 class File
45 {
46 public :
47  //---------------------------------------------------------------------------
48  /// @brief Options for Open method
49  enum access_t
50  {
51  Access_Read = 0, ///< Read permission
52  Access_Write = 1, ///< Write permission
53  Access_Read_Write = 2, ///< Read and Write permissions
54  Access_Write_Append = 3, ///< Write permission without deleting old file
55  Access_Write_Excluding = 4 ///< Write permission preventing reading
56  };
57 
58  //---------------------------------------------------------------------------
59  /// @brief Options for Move method
60  enum move_t
61  {
62  FromBegin = 0, ///< Begin of file
63  FromCurrent = 1, ///< Current position
64  FromEnd = 2 ///< End of file
65  };
66 
67  //Constructor/Destructor
68  File ();
70  ~File ();
71 
72  //Open/close
73  bool Open (const tstring &File_Name, access_t Access=Access_Read);
74  bool Create(const ZenLib::Ztring &File_Name, bool OverWrite=true);
75  void Close ();
76 
77  //Read/Write
78  size_t Read (int8u* Buffer, size_t Buffer_Size);
79  size_t Write (const int8u* Buffer, size_t Buffer_Size);
80  size_t Write (const Ztring &ToWrite);
81  bool Truncate (int64u Offset=(int64u)-1);
82 
83  //Moving
84  bool GoTo (int64s Position, move_t MoveMethod=FromBegin);
85  int64u Position_Get ();
86 
87  //Attributes
88  int64u Size_Get();
93  bool Opened_Get();
94 
95  //Helpers
96  static int64u Size_Get(const Ztring &File_Name);
97  static Ztring Created_Get(const Ztring &File_Name);
98  static Ztring Modified_Get(const Ztring &File_Name);
99  static bool Exists(const Ztring &File_Name);
100  static bool Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
101  static bool Move(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
102  static bool Delete(const Ztring &File_Name);
103 
104  //Temp
106  int64u Position; //Position is saved, may be not good because position may change
107  int64u Size; //Size is saved, may be not good because size may change
108  void* File_Handle;
109 };
110 
111 } //NameSpace
112 
113 #endif