← Back to team overview

kicad-developers team mailing list archive

Re: Using FILE_LINE_READER in pcbnew

 

Marco,


*))))))))) 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
whitespace,
   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
introduce
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
new/filter_reader.cpp.

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!

Dick


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


/**
 * Class FILTER_READER
 * reads lines of text from another LINE_READER, but only returns non-comment
 * lines and non-blank lines from its ReadLine() function.
 */
class FILTER_READER : public LINE_READER
{
    LINE_READER&  reader;

public:

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

    unsigned ReadLine() throw( IO_ERROR )
    {
        unsigned ret;

        while( ( ret = reader.ReadLine() ) != 0 )
        {
            if( !strchr( "#\n\r", reader[0] ) )
                break;
        }
        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

References