File.h

Go to the documentation of this file.
00001 // ZenLib::File - File functions
00002 // Copyright (C) 2007-2010 MediaArea.net SARL, Info@MediaArea.net
00003 //
00004 // This software is provided 'as-is', without any express or implied
00005 // warranty.  In no event will the authors be held liable for any damages
00006 // arising from the use of this software.
00007 //
00008 // Permission is granted to anyone to use this software for any purpose,
00009 // including commercial applications, and to alter it and redistribute it
00010 // freely, subject to the following restrictions:
00011 //
00012 // 1. The origin of this software must not be misrepresented; you must not
00013 //    claim that you wrote the original software. If you use this software
00014 //    in a product, an acknowledgment in the product documentation would be
00015 //    appreciated but is not required.
00016 // 2. Altered source versions must be plainly marked as such, and must not be
00017 //    misrepresented as being the original software.
00018 // 3. This notice may not be removed or altered from any source distribution.
00019 //
00020 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00021 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00022 //
00023 // File functions
00024 //
00025 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00026 
00027 //---------------------------------------------------------------------------
00028 #ifndef ZenLib_FileH
00029 #define ZenLib_FileH
00030 //---------------------------------------------------------------------------
00031 
00032 //---------------------------------------------------------------------------
00033 #include "ZenLib/Conf.h"
00034 #include "ZenLib/Ztring.h"
00035 //---------------------------------------------------------------------------
00036 
00037 namespace ZenLib
00038 {
00039 
00040 //***************************************************************************
00041 /// @brief File manipulation
00042 //***************************************************************************
00043 
00044 class File
00045 {
00046 public :
00047     //---------------------------------------------------------------------------
00048     /// @brief Options for Open method
00049     enum access_t
00050     {
00051         Access_Read                 = 0,            ///< Read permission
00052         Access_Write                = 1,            ///< Write permission
00053         Access_Read_Write           = 2,            ///< Read and Write permissions
00054         Access_Write_Append         = 3,            ///< Write permission without deleting old file
00055         Access_Write_Excluding      = 4             ///< Write permission preventing reading
00056     };
00057 
00058     //---------------------------------------------------------------------------
00059     /// @brief Options for Move method
00060     enum move_t
00061     {
00062         FromBegin                   = 0,            ///< Begin of file
00063         FromCurrent                 = 1,            ///< Current position
00064         FromEnd                     = 2             ///< End of file
00065     };
00066 
00067     //Constructor/Destructor
00068     File  ();
00069     File  (ZenLib::Ztring File_Name, access_t Access=Access_Read);
00070     ~File ();
00071 
00072     //Open/close
00073     bool Open  (const tstring &File_Name, access_t Access=Access_Read);
00074     bool Create(const ZenLib::Ztring &File_Name, bool OverWrite=true);
00075     void Close ();
00076 
00077     //Read/Write
00078     size_t Read  (int8u* Buffer, size_t Buffer_Size);
00079     size_t Write (const int8u* Buffer, size_t Buffer_Size);
00080     size_t Write (const Ztring &ToWrite);
00081     bool   Truncate (int64u Offset=(int64u)-1);
00082 
00083     //Moving
00084     bool GoTo (int64s Position, move_t MoveMethod=FromBegin);
00085     int64u Position_Get ();
00086 
00087     //Attributes
00088     int64u Size_Get();
00089     Ztring Created_Get();
00090     Ztring Created_Local_Get();
00091     Ztring Modified_Get();
00092     Ztring Modified_Local_Get();
00093     bool   Opened_Get();
00094 
00095     //Helpers
00096     static int64u           Size_Get(const Ztring &File_Name);
00097     static Ztring           Created_Get(const Ztring &File_Name);
00098     static Ztring           Modified_Get(const Ztring &File_Name);
00099     static bool             Exists(const Ztring &File_Name);
00100     static bool             Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
00101     static bool             Move(const Ztring &Source, const Ztring &Destination, bool OverWrite=false);
00102     static bool             Delete(const Ztring &File_Name);
00103 
00104     //Temp
00105     Ztring File_Name;
00106     int64u Position; //Position is saved, may be not good because position may change
00107     int64u Size; //Size is saved, may be not good because size may change
00108     void*  File_Handle;
00109 };
00110 
00111 } //NameSpace
00112 
00113 #endif

Generated on Mon May 28 17:35:42 2012 for ZenLib by  doxygen 1.4.7