From 2337b83ba624ed67f0169fe6dc8a1951cb83cb57 Mon Sep 17 00:00:00 2001 From: jean-pierre charras <jp.charras@wanadoo.fr> Date: Sun, 12 Nov 2017 18:29:56 +0100 Subject: [PATCH] richio.h, class LINE_READER: prefix variable member names by "m_", like in other classes in Kicad. --- common/filter_reader.cpp | 36 ++-- common/richio.cpp | 165 +++++++++---------- include/richio.h | 48 +++--- tools/io_benchmark/stdstream_line_reader.cpp | 16 +- 4 files changed, 131 insertions(+), 134 deletions(-) diff --git a/common/filter_reader.cpp b/common/filter_reader.cpp index 820cc18384..30c1d29566 100644 --- a/common/filter_reader.cpp +++ b/common/filter_reader.cpp @@ -32,20 +32,20 @@ FILTER_READER::FILTER_READER( LINE_READER& aReader ) : LINE_READER( 1 ), reader( aReader ) { - // Not using our own line buffer, will be using aReader's. This changes - // the meaning of this->line to be merely a pointer to aReader's line, which of course + // Not using our own m_line buffer, will be using aReader's. This changes + // the meaning of this->m_line to be merely a pointer to aReader's m_line, which of course // is not owned here. - delete [] line; + delete [] m_line; - line = 0; + m_line = 0; } FILTER_READER::~FILTER_READER() { - // Our 'line' points to aReader's, and he will delete that buffer. + // Our 'm_line' points to aReader's, and he will delete that buffer. // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own. - line = 0; + m_line = 0; } @@ -59,10 +59,10 @@ char* FILTER_READER::ReadLine() break; } - line = reader.Line(); - length = reader.Length(); + m_line = reader.Line(); + m_length = reader.Length(); - return length ? line : NULL; + return m_length ? m_line : NULL; } @@ -70,20 +70,20 @@ WHITESPACE_FILTER_READER::WHITESPACE_FILTER_READER( LINE_READER& aReader ) : LINE_READER( 1 ), reader( aReader ) { - // Not using our own line buffer, will be using aReader's. This changes - // the meaning of this->line to be merely a pointer to aReader's line, which of course + // Not using our own m_line buffer, will be using aReader's. This changes + // the meaning of this->m_line to be merely a pointer to aReader's m_line, which of course // is not owned here. - delete [] line; + delete [] m_line; - line = 0; + m_line = nullptr; } WHITESPACE_FILTER_READER::~WHITESPACE_FILTER_READER() { - // Our 'line' points to aReader's, and he will delete that buffer. + // Our 'm_line' points to aReader's, and he will delete that buffer. // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own. - line = 0; + m_line = nullptr; } @@ -100,8 +100,8 @@ char* WHITESPACE_FILTER_READER::ReadLine() break; } - line = s; - length = reader.Length(); + m_line = s; + m_length = reader.Length(); - return length ? line : NULL; + return m_length ? m_line : NULL; } diff --git a/common/richio.cpp b/common/richio.cpp index 35359b56e0..72ae9391c7 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> - * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -100,76 +100,76 @@ std::string StrPrintf( const char* format, ... ) //-----<LINE_READER>------------------------------------------------------ LINE_READER::LINE_READER( unsigned aMaxLineLength ) : - length( 0 ), lineNum( 0 ), line( NULL ), - capacity( 0 ), maxLineLength( aMaxLineLength ) + m_length( 0 ), m_lineNum( 0 ), m_line( NULL ), + m_capacity( 0 ), m_maxLineLength( aMaxLineLength ) { if( aMaxLineLength != 0 ) { // start at the INITIAL size, expand as needed up to the MAX size in maxLineLength - capacity = LINE_READER_LINE_INITIAL_SIZE; + m_capacity = LINE_READER_LINE_INITIAL_SIZE; // but never go above user's aMaxLineLength, and leave space for trailing nul - if( capacity > aMaxLineLength+1 ) - capacity = aMaxLineLength+1; + if( m_capacity > aMaxLineLength+1 ) + m_capacity = aMaxLineLength+1; // Be sure there is room for a null EOL char, so reserve at least capacity+1 bytes // to ensure capacity line lenght and avoid corner cases // Use capacity+5 to cover and corner case - line = new char[capacity+5]; + m_line = new char[m_capacity+5]; - line[0] = '\0'; + m_line[0] = '\0'; } } LINE_READER::~LINE_READER() { - delete[] line; + delete[] m_line; } -void LINE_READER::expandCapacity( unsigned newsize ) +void LINE_READER::expandCapacity( unsigned aNewsize ) { - // length can equal maxLineLength and nothing breaks, there's room for + // m_length can equal maxLineLength and nothing breaks, there's room for // the terminating nul. cannot go over this. - if( newsize > maxLineLength+1 ) - newsize = maxLineLength+1; + if( aNewsize > m_maxLineLength+1 ) + aNewsize = m_maxLineLength+1; - if( newsize > capacity ) + if( aNewsize > m_capacity ) { - capacity = newsize; + m_capacity = aNewsize; // resize the buffer, and copy the original data // Be sure there is room for the null EOL char, so reserve capacity+1 bytes // to ensure capacity line lenght. Use capacity+5 to cover and corner case - char* bigger = new char[capacity+5]; + char* bigger = new char[m_capacity+5]; - wxASSERT( capacity >= length+1 ); + wxASSERT( m_capacity >= m_length+1 ); - memcpy( bigger, line, length ); - bigger[length] = 0; + memcpy( bigger, m_line, m_length ); + bigger[m_length] = 0; - delete[] line; - line = bigger; + delete[] m_line; + m_line = bigger; } } FILE_LINE_READER::FILE_LINE_READER( const wxString& aFileName, unsigned aStartingLineNumber, unsigned aMaxLineLength ): - LINE_READER( aMaxLineLength ), iOwn( true ) + LINE_READER( aMaxLineLength ), m_iOwn( true ) { - fp = wxFopen( aFileName, wxT( "rt" ) ); + m_fp = wxFopen( aFileName, wxT( "rt" ) ); - if( !fp ) + if( !m_fp ) { wxString msg = wxString::Format( _( "Unable to open filename '%s' for reading" ), aFileName.GetData() ); THROW_IO_ERROR( msg ); } - source = aFileName; - lineNum = aStartingLineNumber; + m_source = aFileName; + m_lineNum = aStartingLineNumber; } @@ -177,107 +177,104 @@ FILE_LINE_READER::FILE_LINE_READER( FILE* aFile, const wxString& aFileName, bool doOwn, unsigned aStartingLineNumber, unsigned aMaxLineLength ) : - LINE_READER( aMaxLineLength ), - iOwn( doOwn ), - fp( aFile ) + LINE_READER( aMaxLineLength ), m_iOwn( doOwn ), m_fp( aFile ) { - source = aFileName; - lineNum = aStartingLineNumber; + m_source = aFileName; + m_lineNum = aStartingLineNumber; } FILE_LINE_READER::~FILE_LINE_READER() { - if( iOwn && fp ) - fclose( fp ); + if( m_iOwn && m_fp ) + fclose( m_fp ); } char* FILE_LINE_READER::ReadLine() { - length = 0; + m_length = 0; for(;;) { - if( length >= maxLineLength ) + if( m_length >= m_maxLineLength ) THROW_IO_ERROR( _( "Maximum line length exceeded" ) ); - if( length >= capacity ) - expandCapacity( capacity * 2 ); + if( m_length >= m_capacity ) + expandCapacity( m_capacity * 2 ); // faster, POSIX compatible fgetc(), no locking. - int cc = getc_unlocked( fp ); + int cc = getc_unlocked( m_fp ); if( cc == EOF ) break; - line[ length++ ] = (char) cc; + m_line[ m_length++ ] = (char) cc; if( cc == '\n' ) break; } - line[ length ] = 0; + m_line[ m_length ] = 0; - // lineNum is incremented even if there was no line read, because this + // m_lineNum is incremented even if there was no line read, because this // leads to better error reporting when we hit an end of file. - ++lineNum; + ++m_lineNum; - return length ? line : NULL; + return m_length ? m_line : NULL; } STRING_LINE_READER::STRING_LINE_READER( const std::string& aString, const wxString& aSource ): LINE_READER( LINE_READER_LINE_DEFAULT_MAX ), - lines( aString ), - ndx( 0 ) + m_lines( aString ), m_ndx( 0 ) { // Clipboard text should be nice and _use multiple lines_ so that // we can report _line number_ oriented error messages when parsing. - source = aSource; + m_source = aSource; } STRING_LINE_READER::STRING_LINE_READER( const STRING_LINE_READER& aStartingPoint ): LINE_READER( LINE_READER_LINE_DEFAULT_MAX ), - lines( aStartingPoint.lines ), - ndx( aStartingPoint.ndx ) + m_lines( aStartingPoint.m_lines ), + m_ndx( aStartingPoint.m_ndx ) { // since we are keeping the same "source" name, for error reporting purposes // we need to have the same notion of line number and offset. - source = aStartingPoint.source; - lineNum = aStartingPoint.lineNum; + m_source = aStartingPoint.m_source; + m_lineNum = aStartingPoint.m_lineNum; } char* STRING_LINE_READER::ReadLine() { - size_t nlOffset = lines.find( '\n', ndx ); + size_t nlOffset = m_lines.find( '\n', m_ndx ); if( nlOffset == std::string::npos ) - length = lines.length() - ndx; + m_length = m_lines.length() - m_ndx; else - length = nlOffset - ndx + 1; // include the newline, so +1 + m_length = nlOffset - m_ndx + 1; // include the newline, so +1 - if( length ) + if( m_length ) { - if( length >= maxLineLength ) + if( m_length >= m_maxLineLength ) THROW_IO_ERROR( _("Line length exceeded") ); - if( length+1 > capacity ) // +1 for terminating nul - expandCapacity( length+1 ); + if( m_length+1 > m_capacity ) // +1 for terminating nul + expandCapacity( m_length+1 ); - wxASSERT( ndx + length <= lines.length() ); + wxASSERT( m_ndx + m_length <= m_lines.length() ); - memcpy( line, &lines[ndx], length ); - ndx += length; + memcpy( m_line, &m_lines[m_ndx], m_length ); + m_ndx += m_length; } - ++lineNum; // this gets incremented even if no bytes were read - line[length] = 0; + ++m_lineNum; // this gets incremented even if no bytes were read + m_line[m_length] = 0; - return length ? line : NULL; + return m_length ? m_line : NULL; } @@ -285,21 +282,21 @@ INPUTSTREAM_LINE_READER::INPUTSTREAM_LINE_READER( wxInputStream* aStream, const LINE_READER( LINE_READER_LINE_DEFAULT_MAX ), m_stream( aStream ) { - source = aSource; + m_source = aSource; } char* INPUTSTREAM_LINE_READER::ReadLine() { - length = 0; + m_length = 0; for(;;) { - if( length >= maxLineLength ) + if( m_length >= m_maxLineLength ) THROW_IO_ERROR( _( "Maximum line length exceeded" ) ); - if( length + 1 > capacity ) - expandCapacity( capacity * 2 ); + if( m_length + 1 > m_capacity ) + expandCapacity( m_capacity * 2 ); // this read may fail, docs say to test LastRead() before trusting cc. char cc = m_stream->GetC(); @@ -307,19 +304,19 @@ char* INPUTSTREAM_LINE_READER::ReadLine() if( !m_stream->LastRead() ) break; - line[ length++ ] = cc; + m_line[ m_length++ ] = cc; if( cc == '\n' ) break; } - line[ length ] = 0; + m_line[ m_length ] = 0; - // lineNum is incremented even if there was no line read, because this + // m_lineNum is incremented even if there was no line read, because this // leads to better error reporting when we hit an end of file. - ++lineNum; + ++m_lineNum; - return length ? line : NULL; + return m_length ? m_line : NULL; } @@ -375,18 +372,18 @@ int OUTPUTFORMATTER::vprint( const char* fmt, va_list ap ) // we make a copy of va_list ap for the second call, if happens va_list tmp; va_copy( tmp, ap ); - int ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap ); + int ret = vsnprintf( &m_buffer[0], m_buffer.size(), fmt, ap ); - if( ret >= (int) buffer.size() ) + if( ret >= (int) m_buffer.size() ) { - buffer.resize( ret + 1000 ); - ret = vsnprintf( &buffer[0], buffer.size(), fmt, tmp ); + m_buffer.resize( ret + 1000 ); + ret = vsnprintf( &m_buffer[0], m_buffer.size(), fmt, tmp ); } va_end( tmp ); // Release the temporary va_list, initialised from ap if( ret > 0 ) - write( &buffer[0], ret ); + write( &m_buffer[0], ret ); return ret; } @@ -497,20 +494,20 @@ std::string OUTPUTFORMATTER::Quotew( const wxString& aWrapee ) void STRING_FORMATTER::write( const char* aOutBuf, int aCount ) { - mystring.append( aOutBuf, aCount ); + m_mystring.append( aOutBuf, aCount ); } void STRING_FORMATTER::StripUseless() { - std::string copy = mystring; + std::string copy = m_mystring; - mystring.clear(); + m_mystring.clear(); for( std::string::iterator i=copy.begin(); i!=copy.end(); ++i ) { if( !isspace( *i ) && *i!=')' && *i!='(' && *i!='"' ) { - mystring += *i; + m_mystring += *i; } } } @@ -563,9 +560,9 @@ void STREAM_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) // a file it should only go through the loop once. for( int total = 0; total<aCount; total += lastWrite ) { - lastWrite = os.Write( aOutBuf, aCount ).LastWrite(); + lastWrite = m_os.Write( aOutBuf, aCount ).LastWrite(); - if( !os.IsOk() ) + if( !m_os.IsOk() ) { THROW_IO_ERROR( _( "OUTPUTSTREAM_OUTPUTFORMATTER write error" ) ); } diff --git a/include/richio.h b/include/richio.h index f3a81cdc76..427a35650a 100644 --- a/include/richio.h +++ b/include/richio.h @@ -81,22 +81,22 @@ std::string class LINE_READER { protected: - unsigned length; ///< no. bytes in line before trailing nul. - unsigned lineNum; + unsigned m_length; ///< no. bytes in line before trailing nul. + unsigned m_lineNum; - char* line; ///< the read line of UTF8 text - unsigned capacity; ///< no. bytes allocated for line. + char* m_line; ///< the read line of UTF8 text + unsigned m_capacity; ///< no. bytes allocated for line. - unsigned maxLineLength; ///< maximum allowed capacity using resizing. + unsigned m_maxLineLength; ///< maximum allowed capacity using resizing. - wxString source; ///< origin of text lines, e.g. filename or "clipboard" + wxString m_source; ///< origin of text lines, e.g. filename or "clipboard" /** * Function expandCapacity * will expand the capacity of @a line up to maxLineLength but not greater, so * be careful about making assumptions of @a capacity after calling this. */ - void expandCapacity( unsigned newsize ); + void expandCapacity( unsigned aNewsize ); public: @@ -129,7 +129,7 @@ public: */ virtual const wxString& GetSource() const { - return source; + return m_source; } /** @@ -138,7 +138,7 @@ public: */ char* Line() const { - return line; + return m_line; } /** @@ -158,7 +158,7 @@ public: */ virtual unsigned LineNumber() const { - return lineNum; + return m_lineNum; } /** @@ -167,7 +167,7 @@ public: */ unsigned Length() const { - return length; + return m_length; } }; @@ -181,8 +181,8 @@ class FILE_LINE_READER : public LINE_READER { protected: - bool iOwn; ///< if I own the file, I'll promise to close it, else not. - FILE* fp; ///< I may own this file, but might not. + bool m_iOwn; ///< if I own the file, I'll promise to close it, else not. + FILE* m_fp; ///< I may own this file, but might not. public: @@ -241,8 +241,8 @@ public: */ void Rewind() { - rewind( fp ); - lineNum = 0; + rewind( m_fp ); + m_lineNum = 0; } }; @@ -254,8 +254,8 @@ public: class STRING_LINE_READER : public LINE_READER { protected: - std::string lines; - size_t ndx; + std::string m_lines; + size_t m_ndx; public: @@ -326,7 +326,7 @@ public: */ class OUTPUTFORMATTER { - std::vector<char> buffer; + std::vector<char> m_buffer; char quoteChar[2]; int sprint( const char* fmt, ... ); @@ -335,7 +335,7 @@ class OUTPUTFORMATTER protected: OUTPUTFORMATTER( int aReserve = OUTPUTFMTBUFZ, char aQuoteChar = '"' ) : - buffer( aReserve, '\0' ) + m_buffer( aReserve, '\0' ) { quoteChar[0] = aQuoteChar; quoteChar[1] = '\0'; @@ -444,7 +444,7 @@ public: */ class STRING_FORMATTER : public OUTPUTFORMATTER { - std::string mystring; + std::string m_mystring; public: @@ -463,7 +463,7 @@ public: */ void Clear() { - mystring.clear(); + m_mystring.clear(); } /** @@ -474,7 +474,7 @@ public: const std::string& GetString() { - return mystring; + return m_mystring; } protected: @@ -525,7 +525,7 @@ protected: */ class STREAM_OUTPUTFORMATTER : public OUTPUTFORMATTER { - wxOutputStream& os; + wxOutputStream& m_os; public: /** @@ -535,7 +535,7 @@ public: */ STREAM_OUTPUTFORMATTER( wxOutputStream& aStream, char aQuoteChar = '"' ) : OUTPUTFORMATTER( OUTPUTFMTBUFZ, aQuoteChar ), - os( aStream ) + m_os( aStream ) { } diff --git a/tools/io_benchmark/stdstream_line_reader.cpp b/tools/io_benchmark/stdstream_line_reader.cpp index 8fe530db75..efacddf208 100644 --- a/tools/io_benchmark/stdstream_line_reader.cpp +++ b/tools/io_benchmark/stdstream_line_reader.cpp @@ -29,15 +29,15 @@ STDISTREAM_LINE_READER::STDISTREAM_LINE_READER() : LINE_READER( 0 ), m_stream( nullptr ) { - line = nullptr; - lineNum = 0; + m_line = nullptr; + m_lineNum = 0; } STDISTREAM_LINE_READER::~STDISTREAM_LINE_READER() { // this is only a view into a string, it cant be deleted by the base - line = nullptr; + m_line = nullptr; } @@ -47,14 +47,14 @@ char* STDISTREAM_LINE_READER::ReadLine() m_buffer.append( 1, '\n' ); - length = m_buffer.size(); - line = (char*) m_buffer.data(); //ew why no const?? + m_length = m_buffer.size(); + m_line = (char*) m_buffer.data(); //ew why no const?? // lineNum is incremented even if there was no line read, because this // leads to better error reporting when we hit an end of file. - ++lineNum; + ++m_lineNum; - return m_stream->eof() ? nullptr : line; + return m_stream->eof() ? nullptr : m_line; } @@ -79,7 +79,7 @@ IFSTREAM_LINE_READER::IFSTREAM_LINE_READER( const wxFileName& aFileName ) : setStream( m_fStream ); - source = aFileName.GetFullName(); + m_source = aFileName.GetFullName(); }