From 01ea77ed88269930688f41449168103dbbbc1985 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Fri, 1 Oct 2021 16:51:36 +0200 Subject: Refactor class Fl_Image_Reader to FLTK coding style ... and separate constructors for memory reader with and w/o length argument for better documentation. --- src/Fl_Image_Reader.h | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'src/Fl_Image_Reader.h') diff --git a/src/Fl_Image_Reader.h b/src/Fl_Image_Reader.h index e9b2937b2..ef327922a 100644 --- a/src/Fl_Image_Reader.h +++ b/src/Fl_Image_Reader.h @@ -29,25 +29,27 @@ #include -class Fl_Image_Reader -{ +class Fl_Image_Reader { public: // Create the reader. - Fl_Image_Reader() : - pIsFile(0), pIsData(0), - pFile(0L), pData(0L), - pStart(0L), - pEnd((const unsigned char *)(-1L)), - pName(0L), - pError(0) - {} + Fl_Image_Reader() + : is_file_(0) + , is_data_(0) + , file_(0L) + , data_(0L) + , start_(0L) + , end_((const unsigned char *)(-1L)) + , name_(0L) + , error_(0) {} // Initialize the reader to access the file system, filename is copied // and stored. int open(const char *filename); // Initialize the reader for memory access, name is copied and stored - int open(const char *imagename, const unsigned char *data, const long datasize = -1); + int open(const char *imagename, const unsigned char *data, const size_t datasize); + // Deprecated, DO NOT USE! + int open(const char *imagename, const unsigned char *data); // Close and destroy the reader ~Fl_Image_Reader(); @@ -62,9 +64,7 @@ public: unsigned int read_dword(); // Read a 32-bit signed integer, LSB-first - int read_long() { - return (int)read_dword(); - } + int read_long() { return (int)read_dword(); } // Move the current read position to a byte offset from the beginning // of the file or the original start address in memory @@ -75,36 +75,33 @@ public: long tell() const; // Get the current EOF or error status of the file or data block - int error() const { - return pError; - } + int error() const { return error_; } // return the name or filename for this reader - const char *name() const { return pName; } + const char *name() const { return name_; } // skip a given number of bytes void skip(unsigned int n) { seek(tell() + n); } private: - // open() sets this if we read from a file - char pIsFile; + char is_file_; // open() sets this if we read from memory - char pIsData; + char is_data_; // a pointer to the opened file - FILE *pFile; + FILE *file_; // a pointer to the current byte in memory - const unsigned char *pData; + const unsigned char *data_; // a pointer to the start of the image data - const unsigned char *pStart; + const unsigned char *start_; // a pointer to the end of image data if reading from memory, otherwise undefined // note: currently (const unsigned char *)(-1L) if end of memory is not available // ... which means "unlimited" - const unsigned char *pEnd; + const unsigned char *end_; // a copy of the name associated with this reader - char *pName; + char *name_; // a flag to store EOF or error status - int pError; + int error_; }; #endif // FL_IMAGE_READER_H -- cgit v1.2.3