Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Platform/Aperios1.3.2/File.h

Go to the documentation of this file.

    00001 /**
    00002 * @file Platform/Aperios1.3.2/File.h
    00003 *
    00004 * Declaration of class File for Aperios 1.3.2.
    00005 */
    00006
    00007 #ifndef __File_h__
    00008 #define __File_h__
    00009
    00010 #ifdef __GNUC__
    00011 #include <stdio.h>
    00012 #define OFS
    00013 #else
    00014 #include <FileSystem/futil.h>
    00015 #endif
    00016
    00017 /**
    00018 * This class provides basic file input/output capabilies.
    00019 */
    00020 class File
    00021 {
    00022 private:
    00023   OFS::FILE* stream; /**< File handle. */
    00024   char buf[65536]; /**< A buffer to reduce the number of operation system calls. */
    00025   unsigned int bufSize, /**< The number of bytes in the buffer while reading. */
    00026     index; /**< The next byte in the buffer to read/write. */
    00027   bool isWrite; /**< Is this a write stream? */
    00028 public:
    00029 /**
    00030 * Constructor.
    00031 * @param name File name or path. If it is a relative path, it is assumed
    00032 *             to be relative to the path for configuration files. Otherwise,
    00033 *             the path is used directly.
    00034 * @param mode File open mode as used by fopen defined in stdio.h.
    00035   */
    00036   File(const char* name,const char* mode);
    00037
    00038   /**
    00039   * Destructor.
    00040   */
    00041   ~File();
    00042
    00043   /**
    00044   * The function read a number of bytes from the file to a certain
    00045   * memory location.
    00046   * @param p The start of the memory space the data is written to.
    00047   * @param size The number of bytes read from the file.
    00048   */
    00049   void read(void* p,unsigned size);
    00050
    00051   /**
    00052   * The function writes a number of bytes from a certain memory
    00053   * location into the file.
    00054   * @param p The start of the memory space the data is read from.
    00055   * @param size The number of bytes written into the file.
    00056   */
    00057   void write(const void *p,unsigned size);
    00058
    00059   /**
    00060   * The function implements printf for the stream represented by
    00061   * instances of this class.
    00062   * @param format Format string as used by printf defined in stdio.h.
    00063   * @param ... See printf in stdio.h.
    00064   */
    00065   void printf(const char* format, ...);
    00066
    00067   /**
    00068   * The function returns whether the file represented by an
    00069   * object of this class actually exists.
    00070   * @return The existence of the file.
    00071   */
    00072   bool exists() const {return stream != 0;}
    00073
    00074   /**
    00075   * The function returns whether the end of the file represented
    00076   * by an object of this class was reached.
    00077   * @return End of file reached?
    00078   */
    00079   bool eof() const;
    00080
    00081   /**
    00082   * The function returns the current GT directory,
    00083   * e.g. /MS/OPENR/APP or <...>/GT2003 or /usr/local/GT2003
    00084   * @return The current GTDir
    00085   */
    00086   static char* getGTDir();
    00087 };
    00088
    00089 #endif // __FILE_H__