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: 2010-01-09 Functions: 9 3 33.3 %

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

Generated by: LCOV version 1.7