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 namespace ZenLib
00023 {
00024 
00025 //***************************************************************************
00026 /// @brief File manipulation
00027 //***************************************************************************
00028 
00029 class File
00030 {
00031 public :
00032     //---------------------------------------------------------------------------
00033     /// @brief Options for Open method
00034     enum access_t
00035     {
00036         Access_Read                 = 0,            ///< Read permission
00037         Access_Write                = 1,            ///< Write permission
00038         Access_Read_Write           = 2,            ///< Read and Write permissions
00039         Access_Write_Append         = 3,            ///< Write permission without deleting old file
00040         Access_Write_Excluding      = 4             ///< Write permission preventing reading
00041     };
00042 
00043     //---------------------------------------------------------------------------
00044     /// @brief Options for Move method
00045     enum move_t
00046     {
00047         FromBegin                   = 0,            ///< Begin of file
00048         FromCurrent                 = 1,            ///< Current position
00049         FromEnd                     = 2             ///< End of file
00050     };
00051 
00052     //Constructor/Destructor
00053     File  ();
00054     File  (ZenLib::Ztring File_Name, access_t Access=Access_Read);
00055     ~File ();
00056 
00057     //Open/close
00058     bool Open  (const tstring &File_Name, access_t Access=Access_Read);
00059     bool Create(const ZenLib::Ztring &File_Name, bool OverWrite=true);
00060     void Close ();
00061 
00062     //Read/Write
00063     size_t Read  (int8u* Buffer, size_t Buffer_Size);
00064     size_t Write (const int8u* Buffer, size_t Buffer_Size);
00065     size_t Write (const Ztring &ToWrite);
00066     bool   Truncate (int64u Offset=(int64u)-1);
00067 
00068     //Moving
00069     bool GoTo (int64s Position, move_t MoveMethod=FromBegin);
00070     int64u Position_Get ();
00071 
00072     //Attributes
00073     int64u Size_Get();
00074     Ztring Created_Get();
00075     Ztring Created_Local_Get();
00076     Ztring Modified_Get();
00077     Ztring Modified_Local_Get();
00078     bool   Opened_Get();
00079 
00080     //Helpers
00081     static int64u   Size_Get(const Ztring &File_Name);
00082     static Ztring   Created_Get(const Ztring &File_Name);
00083     static Ztring   Modified_Get(const Ztring &File_Name);
00084     static bool     Exists(const Ztring &File_Name);
00085     static bool     Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
00086     static bool     Move(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
00087     static bool     Delete(const Ztring &File_Name);
00088 
00089     //Temp
00090     Ztring File_Name;
00091     int64u Position; //Position is saved, may be not good because position may change
00092     int64u Size; //Size is saved, may be not good because size may change
00093     void*  File_Handle;
00094 };
00095 
00096 } //NameSpace
00097 
00098 #endif