MFile.h

/******************************************************************************** * MFile header * Elgrint library, version 1.0 * Created by Dimitry Rotstein * Copyright(C) 2013 by Miranor * Description: * - Declares MFile class, which handles file input/output operations: opening, * closing, seeking (local files only), writing, and reading * - Write/read functions are operators, so they can be overloaded for any type * - Vector write/read functions are templates, so the work for any type for * which elemental write/read are defined * - As long as only the specified types are used (not compatible types like 'int'), * the resulting file should be platform-independent * - MFile supports local, FTP, and HTTP[S] file streams, but non-trivial setPos * and setSize only work for local files * *******************************************************************************/ #ifndef MIRANOR_ELGRINT_FILE #define MIRANOR_ELGRINT_FILE #include "MString.h" #include "elEnums.h" // MFileMode is used namespace Elgrint { class MFile { public: // Initializers MFile(); explicit MFile(const MString& pathname, MFileMode fm = fmRead); ~MFile(); // General operations void open(const MString& pathname, MFileMode fm = fmRead); void setPos(MFileSize newPos); void truncate(MFileSize bytesToTruncate); void close(); MFile& operator<<(const bool &src); MFile& operator<<(const char &src); MFile& operator<<(const MChar &src); MFile& operator<<(const Int8 &src); MFile& operator<<(const Int16 &src); MFile& operator<<(const Int32 &src); MFile& operator<<(const Int64 &src); MFile& operator<<(const UInt8 &src); MFile& operator<<(const UInt16 &src); MFile& operator<<(const UInt32 &src); MFile& operator<<(const UInt64 &src); MFile& operator<<(const float &src); MFile& operator<<(const double &src); MFile& operator<<(const MString &src); MFile& operator<<(const char src[]); MFile& operator<<(const wchar_t src[]); template <class T> MFile& operator<<(const MVector<T>& src); // Read operation void operator>>(bool &dest); void operator>>(char &dest); void operator>>(MChar &dest); void operator>>(Int8 &dest); void operator>>(Int16 &dest); void operator>>(Int32 &dest); void operator>>(Int64 &dest); void operator>>(UInt8 &dest); void operator>>(UInt16 &dest); void operator>>(UInt32 &dest); void operator>>(UInt64 &dest); void operator>>(float &dest); void operator>>(double &dest); void operator>>(MString &dest); template <class T> void operator>>(MVector<T>& dest); // Revealers bool isOpen () const; // True iff the file is open MString getPathname() const; // Pathname specified at previous 'open' (even if failed) MFileSize getPos () const; // Current offset in bytes from file start MFileSize getSize () const; // File size in bytes bool isEOF () const; // True iff getPos == getSize (for convenience)

...

Miranor Home | About Miranor | About Elgrint | Create account | Login | Account settings | Contact Us | Privacy Policy | Site map

© Copyright 2014 by Miranor. All rights reserved. By using this site you agree to the Terms of Use.

Page last updated on August 10th, 2014.