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

Generated on Thu Jul 1 06:08:30 2010 for Second Life Viewer by  doxygen 1.4.7