Gamma  0.9.5
Generic Synthesis Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
/Users/ljp/code/gamma/trunk/Gamma/File.h
00001 #ifndef GAMMA_FILE_H_INC
00002 #define GAMMA_FILE_H_INC
00003 
00004 /*  Gamma - Generic processing library
00005     See COPYRIGHT file for authors and license information
00006 
00007     File Description:
00008     Basic file i/o classes.
00009 */
00010 
00011 #include <stdio.h>
00012 #include "Gamma/pstdint.h"
00013 
00014 namespace gam{
00015 
00016 class File{
00017 public:
00018 
00021     File(const char * path, const char * mode, bool open=false);
00022 
00023     ~File();
00024 
00025     void close();   
00026     bool open();    
00027 
00028     void mode(const char * v){ mMode=v; }
00029 
00031     uint32_t write(const void * v, int size, int items=1){ return fwrite(v, size, items, mFP); }
00032 
00034     static uint32_t write(const char * path, const void * v, int size, int items=1);
00035 
00037     char * readAll();
00038 
00040     bool opened() const { return 0 != mFP; }
00041     
00043     const char * mode() const { return mMode; }
00044     
00046     const char * path() const { return mPath; }
00047     
00049     int size() const { return mSizeBytes; }
00050 
00052     static bool exists(const char * path);
00053 
00054 protected:
00055     const char * mPath;
00056     const char * mMode;
00057     char * mContent;
00058     int mSizeBytes;
00059     FILE * mFP;
00060     
00061     void freeContent();
00062     void allocContent(int n);
00063     void getSize();
00064 };
00065 
00066 } // gam::
00067 
00068 #endif
00069