ZenLib
File.h
Go to the documentation of this file.
00001 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
00002  *
00003  *  Use of this source code is governed by a zlib-style license that can
00004  *  be found in the License.txt file in the root of the source tree.
00005  */
00006 
00007 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00008 //
00009 // File functions
00010 //
00011 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00012 
00013 //---------------------------------------------------------------------------
00014 #ifndef ZenLib_FileH
00015 #define ZenLib_FileH
00016 //---------------------------------------------------------------------------
00017 
00018 //---------------------------------------------------------------------------
00019 #include "ZenLib/Ztring.h"
00020 
00021 //---------------------------------------------------------------------------
00022 
00023 namespace ZenLib
00024 {
00025 
00026 //***************************************************************************
00027 /// @brief File manipulation
00028 //***************************************************************************
00029 
00030 class File
00031 {
00032 public :
00033     //---------------------------------------------------------------------------
00034     /// @brief Options for Open method
00035     enum access_t
00036     {
00037         Access_Read                 = 0,            ///< Read permission
00038         Access_Write                = 1,            ///< Write permission
00039         Access_Read_Write           = 2,            ///< Read and Write permissions
00040         Access_Write_Append         = 3,            ///< Write permission without deleting old file
00041         Access_Write_Excluding      = 4             ///< Write permission preventing reading
00042     };
00043 
00044     //---------------------------------------------------------------------------
00045     /// @brief Options for Move method
00046     enum move_t
00047     {
00048         FromBegin                   = 0,            ///< Begin of file
00049         FromCurrent                 = 1,            ///< Current position
00050         FromEnd                     = 2             ///< End of file
00051     };
00052 
00053     //Constructor/Destructor
00054     File  ();
00055     File  (ZenLib::Ztring File_Name, access_t Access=Access_Read);
00056     ~File ();
00057 
00058     //Open/close
00059     bool Open  (const tstring &File_Name, access_t Access=Access_Read);
00060     bool Create(const ZenLib::Ztring &File_Name, bool OverWrite=true);
00061     void Close ();
00062 
00063     //Read/Write
00064     size_t Read  (int8u* Buffer, size_t Buffer_Size);
00065     size_t Write (const int8u* Buffer, size_t Buffer_Size);
00066     size_t Write (const Ztring &ToWrite);
00067     bool   Truncate (int64u Offset=(int64u)-1);
00068 
00069     //Moving
00070     bool GoTo (int64s Position, move_t MoveMethod=FromBegin);
00071     int64u Position_Get ();
00072 
00073     //Attributes
00074     int64u Size_Get();
00075     Ztring Created_Get();
00076     Ztring Created_Local_Get();
00077     Ztring Modified_Get();
00078     Ztring Modified_Local_Get();
00079     bool   Opened_Get();
00080 
00081     //Helpers
00082     static int64u   Size_Get(const Ztring &File_Name);
00083     static Ztring   Created_Get(const Ztring &File_Name);
00084     static Ztring   Modified_Get(const Ztring &File_Name);
00085     static bool     Exists(const Ztring &File_Name);
00086     static bool     Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
00087     static bool     Move(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
00088     static bool     Delete(const Ztring &File_Name);
00089 
00090     //Temp
00091     Ztring File_Name;
00092     int64u Position; //Position is saved, may be not good because position may change
00093     int64u Size; //Size is saved, may be not good because size may change
00094     void*  File_Handle;
00095 };
00096 
00097 } //NameSpace
00098 
00099 #endif