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{
32public :
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 ();
55 File (ZenLib::Ztring File_Name, access_t Access=Access_Read);
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();
75 Ztring Created_Get();
76 Ztring Created_Local_Get();
77 Ztring Modified_Get();
78 Ztring Modified_Local_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
91 Ztring File_Name;
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
Ztring.h
ZenLib::File
File manipulation.
Definition: File.h:31
ZenLib::File::Size
int64u Size
Definition: File.h:93
ZenLib::File::move_t
move_t
Options for Move method.
Definition: File.h:47
ZenLib::File::FromCurrent
@ FromCurrent
Current position.
Definition: File.h:49
ZenLib::File::FromEnd
@ FromEnd
End of file.
Definition: File.h:50
ZenLib::File::FromBegin
@ FromBegin
Begin of file.
Definition: File.h:48
ZenLib::File::Size_Get
static int64u Size_Get(const Ztring &File_Name)
ZenLib::File::Created_Get
static Ztring Created_Get(const Ztring &File_Name)
ZenLib::File::Read
size_t Read(int8u *Buffer, size_t Buffer_Size)
ZenLib::File::Move
static bool Move(const Ztring &Source, const Ztring &Destination, bool OverWrite=false)
ZenLib::File::Create
bool Create(const ZenLib::Ztring &File_Name, bool OverWrite=true)
ZenLib::File::Truncate
bool Truncate(int64u Offset=(int64u) -1)
ZenLib::File::Write
size_t Write(const int8u *Buffer, size_t Buffer_Size)
ZenLib::File::GoTo
bool GoTo(int64s Position, move_t MoveMethod=FromBegin)
ZenLib::File::Copy
static bool Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite=false)
ZenLib::File::Close
void Close()
ZenLib::File::Modified_Get
static Ztring Modified_Get(const Ztring &File_Name)
ZenLib::File::~File
~File()
ZenLib::File::access_t
access_t
Options for Open method.
Definition: File.h:36
ZenLib::File::Access_Read_Write
@ Access_Read_Write
Read and Write permissions.
Definition: File.h:39
ZenLib::File::Access_Read
@ Access_Read
Read permission.
Definition: File.h:37
ZenLib::File::Access_Write
@ Access_Write
Write permission.
Definition: File.h:38
ZenLib::File::Access_Write_Append
@ Access_Write_Append
Write permission without deleting old file.
Definition: File.h:40
ZenLib::File::Access_Write_Excluding
@ Access_Write_Excluding
Write permission preventing reading.
Definition: File.h:41
ZenLib::File::Modified_Local_Get
Ztring Modified_Local_Get()
ZenLib::File::Created_Local_Get
Ztring Created_Local_Get()
ZenLib::File::Position
int64u Position
Definition: File.h:92
ZenLib::File::Open
bool Open(const tstring &File_Name, access_t Access=Access_Read)
ZenLib::File::File
File(ZenLib::Ztring File_Name, access_t Access=Access_Read)
ZenLib::File::Write
size_t Write(const Ztring &ToWrite)
ZenLib::File::Delete
static bool Delete(const Ztring &File_Name)
ZenLib::File::Modified_Get
Ztring Modified_Get()
ZenLib::File::Exists
static bool Exists(const Ztring &File_Name)
ZenLib::File::File_Name
Ztring File_Name
Definition: File.h:91
ZenLib::File::Position_Get
int64u Position_Get()
ZenLib::File::File
File()
ZenLib::File::Opened_Get
bool Opened_Get()
ZenLib::File::Created_Get
Ztring Created_Get()
ZenLib::File::Size_Get
int64u Size_Get()
ZenLib::File::File_Handle
void * File_Handle
Definition: File.h:94
ZenLib::Ztring
String manipulation (based on std::(w)string)
Definition: Ztring.h:50
ZenLib
Definition: BitStream.h:24
ZenLib::tstring
std::basic_string< Char, std::char_traits< Char >, std::allocator< Char > > tstring
Definition: Ztring.h:28