← Back to team overview

kicad-developers team mailing list archive

Re: Using FILE_LINE_READER in pcbnew



*))))))))) First the good:

1) The idea of passing a LINE_READER* to the major functions is correct
   I think.  For example, this is good:

-bool DIMENSION::ReadDimensionDescr( FILE* File, int* LineNum )
+bool DIMENSION::ReadDimensionDescr( LINE_READER* aReader )

2) Not worrying about the trailing /r/n or /n or /r at the end of line is good.
   I think and would hope that client code is not going to be too affected
   because you removed the strtok() call.  /n and /r/n or /r is all just
   no different than a tab or space, at least to me or code I would write.
   But it depends on client code, I assume you have some feel for how stupid
   the client code might be in this regard.  Your risk is low here and the
   strtok() being removed is reasonable.

*)))))))) Then the bad:

I don't like the GetLineD() introduction. I would say just overload
GetLine() since
it returns the same type.  Code can use either, with *same* function name.
This way existing code is not affected by this change in direction.

I am not that fond of GetLine() in any case, and surely would not want to
it into places that it is not already being used.  All it does now is strip out
blank lines and comments.  For an alternative, made possible by a commit I
just made
this evening to base class LINE_READER, take a look at class

If you like this, move it up into /include and /common library.  Otherwise,
it can just stay in /new as an example or for future reference.

filter_reader.cpp is *also* attached for reference.

Thank you for your efforts!


#include <richio.h>
#include <string.h>

 * reads lines of text from another LINE_READER, but only returns non-comment
 * lines and non-blank lines from its ReadLine() function.
    LINE_READER&  reader;


     * Constructor ( LINE_READER& )
     * does not take ownership over @a aReader, so will not destroy it.
       reader( aReader )

    unsigned ReadLine() throw( IO_ERROR )
        unsigned ret;

        while( ( ret = reader.ReadLine() ) != 0 )
            if( !strchr( "#\n\r", reader[0] ) )
        return ret;

    const wxString& GetSource() const
        return reader.GetSource();

    char* Line() const
        return reader.Line();

    unsigned LineNumber() const
        return reader.LineNumber();

    unsigned Length() const
        return reader.Length();

Follow ups