jianyuh / csv-parser-cplusplus

Automatically exported from code.google.com/p/csv-parser-cplusplus
GNU General Public License v3.0
0 stars 0 forks source link

Support for non stdio file systems #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
* Attempt to use with non stdio file system

What is the expected output? What do you see instead?
* Use file IO routines specified by user.

What version of the product are you using? On what operating system?
* Development platform is Windows 7 64, latest csv-parser.

Please provide any additional information below.
* Please find attached modified versions of the .cpp/.hpp which implements 
support for custom file IO routines. I am using these locally and they work 
correctly (the default behaviour will be to use stdio).

Original issue reported on code.google.com by st...@pawprintgames.com on 21 Aug 2014 at 9:07

Attachments:

GoogleCodeExporter commented 9 years ago
Also, here is an example of a custom file IO being used:

class PiCsvParser : public csv_parser, CsvParserFileSystem
{
public:

  PiCsvParser( const char * filename, FileSystem::FileDomain domain )
  {
    if ( m_FileHandle = Pi.File.Open( filename, FileSystem::READ, domain ) != FileSystem::FileHandleInvalid )
    {
      init( this );
    }
  }

  virtual ~PiCsvParser( )
  {
    if ( m_FileHandle )
    {
      Pi.File.Close( m_FileHandle );
      m_FileHandle = FileSystem::FileHandleInvalid;
    }
  }

  // CsvParserFileSystem implementation.
  void Rewind( )
  {
    if ( m_FileHandle != FileSystem::FileHandleInvalid )
    {
      Pi.File.Seek( m_FileHandle, 0, FileSystem::START );
    }
  }
  long Tell( )
  {
    if ( m_FileHandle != FileSystem::FileHandleInvalid )
    {
      return Pi.File.Tell( m_FileHandle );
    }
    return 0;
  }
  int GetC( )
  {
    return Pi.File.GetC( m_FileHandle );
  }
  int Seek( long offset, int origin )
  {
    return Pi.File.Seek( m_FileHandle, offset, ( FileSystem::FileSeekMode ) origin );
  }
  size_t Read( void * dstBuffer, size_t elementSize, size_t count )
  {
    return Pi.File.Read( dstBuffer, elementSize, count, m_FileHandle );
  }

private:
  FileSystem::FileHandle  m_FileHandle;
};

Original comment by st...@pawprintgames.com on 21 Aug 2014 at 9:09