byte_filer.h

Go to the documentation of this file.
00001 #ifndef BYTE_FILER_CLASS
00002 #define BYTE_FILER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : byte_filer                                                        *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/astring.h>
00019 #include <basis/byte_array.h>
00020 #include <basis/definitions.h>
00021 
00022 namespace filesystem {
00023 
00024 // forward declarations.
00025 class file_hider;
00026 
00028 
00029 class byte_filer
00030 {
00031 public:
00032   byte_filer();
00034 
00036   byte_filer(const basis::astring &filename, const basis::astring &permissions);
00038 
00050   byte_filer(const char *filename, const char *permissions);
00052 
00053   byte_filer(bool auto_close, void *opened);
00055 
00059   ~byte_filer();
00060 
00061   static size_t file_size_limit();
00063 
00065   bool open(const basis::astring &filename, const basis::astring &permissions);
00067 
00069   void close();
00071 
00073   basis::astring filename() const;
00075 
00076   bool good();
00078 
00079   size_t length();
00081 
00084   size_t tell();
00086 
00088   void flush();
00090 
00091   enum origins {
00092     FROM_START,    
00093     FROM_END,      
00094     FROM_CURRENT   
00095   };
00096 
00097   bool seek(int where, origins origin = FROM_START);
00099 
00103   bool eof();
00105 
00106   int read(basis::abyte *buffer, int buffer_size);
00108 
00110   int write(const basis::abyte *buffer, int buffer_size);
00112 
00113   int read(basis::byte_array &buffer, int desired_size);
00115   int write(const basis::byte_array &buffer);
00117 
00118   int read(basis::astring &buffer, int desired_size);
00120 
00126   int write(const basis::astring &buffer, bool add_null = false);
00128 
00132   int getline(basis::abyte *buffer, int desired_size);
00134   int getline(basis::byte_array &buffer, int desired_size);
00136   int getline(basis::astring &buffer, int desired_size);
00138 
00139   bool truncate();
00141 
00142   void *file_handle();
00144 
00146 private:
00147   file_hider *_handle;  
00148   basis::astring *_filename;  
00149   bool _auto_close;  
00150 
00151   // not to be called.
00152   byte_filer(const byte_filer &);
00153   byte_filer &operator =(const byte_filer &);
00154 };
00155 
00156 } //namespace.
00157 
00158 #endif
00159 
Generated on Sat Jan 28 04:22:18 2012 for hoople2 project by  doxygen 1.6.3