llfile.h

Go to the documentation of this file.
00001 
00035 #ifndef LL_LLFILE_H
00036 #define LL_LLFILE_H
00037 
00043 typedef FILE    LLFILE;
00044 
00045 #include <fstream>
00046 
00047 #ifdef LL_WINDOWS
00048 #define USE_LLFILESTREAMS       1
00049 #else
00050 #define USE_LLFILESTREAMS       0
00051 #endif
00052 
00053 
00054 #if LL_WINDOWS
00055 // windows version of stat function and stat data structure are called _stat
00056 typedef struct _stat    llstat;
00057 #else
00058 #include <sys/stat.h>
00059 typedef struct stat             llstat;
00060 #endif
00061 
00062 class   LLFile
00063 {
00064 public:
00065         // All these functions take UTF8 path/filenames.
00066         static  LLFILE* fopen(const char* filename,const char* accessmode);     /* Flawfinder: ignore */
00067         static  LLFILE* _fsopen(const char* filename,const char* accessmode,int sharingFlag);
00068 
00069         // perms is a permissions mask like 0777 or 0700.  In most cases it will
00070         // be overridden by the user's umask.  It is ignored on Windows.
00071         static  int             mkdir(const char* filename, int perms = 0700);
00072 
00073         static  int             rmdir(const char* filename);
00074         static  int             remove(const char* filename);
00075         static  int             rename(const char* filename,const char* newname);
00076         static  int             stat(const char*        filename,llstat*        file_status);
00077         static  LLFILE *        _Fiopen(const char *filename, std::ios::openmode mode,int);     // protection currently unused
00078 };
00079 
00080 
00081 #if USE_LLFILESTREAMS
00082 
00083 class   llifstream      :       public  std::basic_istream < char , std::char_traits < char > >
00084 {
00085         // input stream associated with a C stream
00086 public:
00087         typedef std::basic_ifstream<char,std::char_traits < char > > _Myt;
00088         typedef std::basic_filebuf<char,std::char_traits< char > > _Myfb;
00089         typedef std::basic_ios<char,std::char_traits< char > > _Myios;
00090 
00091         llifstream()
00092                 : std::basic_istream<char,std::char_traits< char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false)
00093         {       // construct unopened
00094         }
00095 
00096         explicit llifstream(const char *_Filename,
00097                 ios_base::openmode _Mode = ios_base::in,
00098                 int _Prot = (int)ios_base::_Openprot);
00099 
00100         explicit llifstream(_Filet *_File)
00101                 : std::basic_istream<char,std::char_traits< char > >(NULL,true),
00102                         _Filebuffer(new _Myfb(_File)),
00103                         _ShouldClose(false)
00104         {       // construct with specified C stream
00105         }
00106         virtual ~llifstream();
00107 
00108         _Myfb *rdbuf() const
00109         {       // return pointer to file buffer
00110                 return _Filebuffer;
00111         }
00112         bool is_open() const;
00113         void open(const char* _Filename,        /* Flawfinder: ignore */
00114                 ios_base::openmode _Mode = ios_base::in,
00115                 int _Prot = (int)ios_base::_Openprot);  
00116         void close();
00117 
00118 private:
00119         _Myfb* _Filebuffer;     // the file buffer
00120         bool _ShouldClose;
00121 };
00122 
00123 
00124 class   llofstream      :       public  std::basic_ostream< char , std::char_traits < char > >
00125 {
00126 public:
00127         typedef std::basic_ostream< char , std::char_traits < char > > _Myt;
00128         typedef std::basic_filebuf< char , std::char_traits < char > > _Myfb;
00129         typedef std::basic_ios<char,std::char_traits < char > > _Myios;
00130 
00131         llofstream()
00132                 : std::basic_ostream<char,std::char_traits < char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false)
00133         {       // construct unopened
00134         }
00135 
00136         explicit llofstream(const char *_Filename,
00137                 std::ios_base::openmode _Mode = ios_base::out,
00138                 int _Prot = (int)std::ios_base::_Openprot);
00139         
00140 
00141         explicit llofstream(_Filet *_File)
00142                 : std::basic_ostream<char,std::char_traits < char > >(NULL,true),
00143                         _Filebuffer(new _Myfb(_File)),//_File)
00144                         _ShouldClose(false)
00145         {       // construct with specified C stream
00146         }
00147 
00148         virtual ~llofstream();
00149 
00150         _Myfb *rdbuf() const
00151         {       // return pointer to file buffer
00152                 return _Filebuffer;
00153         }
00154 
00155         bool is_open() const;
00156 
00157         void open(const char *_Filename,ios_base::openmode _Mode = ios_base::out,int _Prot = (int)ios_base::_Openprot); /* Flawfinder: ignore */
00158 
00159         void close();
00160 
00161 private:
00162         _Myfb *_Filebuffer;     // the file buffer
00163         bool _ShouldClose;
00164 };
00165 
00166 
00167 
00168 #else
00169 //Use standard file streams on non windows platforms
00170 #define llifstream      std::ifstream
00171 #define llofstream      std::ofstream
00172 
00173 #endif
00174 
00182 std::streamsize llifstream_size(llifstream& fstr);
00183 std::streamsize llofstream_size(llofstream& fstr);
00184 
00185 #endif // not LL_LLFILE_H

Generated on Fri May 16 08:32:03 2008 for SecondLife by  doxygen 1.5.5