LCOV - code coverage report
Current view: directory - frmts/grib/degrib18/degrib - memorydatasource.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 43 11 25.6 %
Date: 2011-12-18 Functions: 11 3 27.3 %

       1                 : #include "memorydatasource.h"
       2                 : #include <memory.h>
       3                 : #include <string.h>
       4                 : 
       5               3 : MemoryDataSource::MemoryDataSource(unsigned char * block, long length)
       6                 : : seekPos(0)
       7                 : , blockLength(length)
       8                 : , eof(false)
       9               3 : , memoryBlock(block)
      10                 : {
      11               3 : }
      12                 : 
      13               3 : MemoryDataSource::~MemoryDataSource()
      14                 : {
      15               3 : }
      16                 : 
      17              20 : size_t MemoryDataSource::DataSourceFread(void* lpBuf, size_t size, size_t count)
      18                 : {
      19              20 :         if (seekPos + size * count > (size_t) blockLength)
      20                 :   {
      21               0 :     count = (blockLength - seekPos) / size;
      22               0 :     eof = true;
      23                 :   }
      24                 :   else
      25              20 :     eof = false; // feof also "resets" after a good read
      26                 : 
      27              20 :   memcpy(lpBuf, memoryBlock + seekPos, size * count);
      28              20 :   seekPos += size * count;
      29                 : 
      30              20 :   return count;
      31                 : 
      32                 : }
      33                 : 
      34               0 : int MemoryDataSource::DataSourceFgetc()
      35                 : {
      36               0 :   int returnVal = EOF;
      37               0 :   if (seekPos >= blockLength)
      38               0 :     eof = true;
      39                 :   else
      40                 :   {
      41               0 :     unsigned char c =  *((unsigned char*)(memoryBlock + seekPos));
      42               0 :     ++seekPos;
      43               0 :     returnVal = (int)c;
      44               0 :     eof = false;
      45                 :   }
      46               0 :   return returnVal;   
      47                 : }
      48                 : 
      49               0 : int MemoryDataSource::DataSourceUngetc(int c)
      50                 : {
      51               0 :   eof = false;
      52               0 :   int returnVal = c;
      53               0 :   if ((c != EOF) && (seekPos > 0))
      54                 :   {
      55               0 :     --seekPos;
      56               0 :     *((unsigned char*)(memoryBlock + seekPos)) = c;
      57                 :   }
      58                 :   else
      59               0 :     returnVal = EOF;
      60               0 :   return returnVal;
      61                 : }
      62                 : 
      63               0 : int MemoryDataSource::DataSourceFseek(long offset, int origin)
      64                 : {
      65               0 :   switch (origin)
      66                 :   {
      67                 :     case SEEK_CUR :
      68               0 :       seekPos += offset;
      69               0 :       break;
      70                 :     case SEEK_END :
      71               0 :       seekPos = blockLength + offset; // offset MUST be negative
      72               0 :       break;
      73                 :     case SEEK_SET :
      74               0 :       seekPos = offset;
      75                 :       break;
      76                 :   }
      77                 : 
      78               0 :   eof = false;
      79                 : 
      80               0 :   return 0;
      81                 : }
      82                 : 
      83               0 : int MemoryDataSource::DataSourceFeof()
      84                 : {
      85               0 :   return eof; 
      86                 : }
      87                 : 
      88               0 : long MemoryDataSource::DataSourceFtell()
      89                 : {
      90               0 :   return seekPos;
      91                 : }

Generated by: LCOV version 1.7