Exemplo n.º 1
0
SdfLoader::SdfLoader (Scanner &scanner) :
TL_CP_GET(data),
TL_CP_GET(properties),
TL_CP_GET(_offsets),
TL_CP_GET(_preread)
{
   data.clear();
   properties.clear();

   // detect if input is gzipped
   byte id[2];
   int pos = scanner.tell();

   scanner.readCharsFix(2, (char *)id);
   scanner.seek(pos, SEEK_SET);

   if (id[0] == 0x1f && id[1] == 0x8b)
   {
      _scanner = new GZipScanner(scanner);
      _own_scanner = true;
   }
   else
   {
      _scanner = &scanner;
      _own_scanner = false;
   }
   _current_number = 0;
   _max_offset = 0;
   _offsets.clear();
   _preread.clear();
}
Exemplo n.º 2
0
SdfLoader::SdfLoader (Scanner &scanner) :
CP_INIT,
TL_CP_GET(data),
TL_CP_GET(properties),
TL_CP_GET(_offsets),
TL_CP_GET(_preread)
{
   data.clear();
   properties.clear();

   // detect if input is gzipped
   byte id[2];
   int pos = scanner.tell();

   scanner.readCharsFix(2, (char *)id);
   scanner.seek(pos, SEEK_SET);

   if (id[0] == 0x1f && id[1] == 0x8b)
   {
      _scanner = new GZipScanner(scanner);
      _own_scanner = true;
   }
   else
   {
      _scanner = &scanner;
      _own_scanner = false;
   }
   _current_number = 0;
   _max_offset = 0;
   _offsets.clear();
   _preread.clear();
}

SdfLoader::~SdfLoader()
{
   if (_own_scanner)
      delete _scanner;
}

int SdfLoader::tell ()
{
   return _scanner->tell();
}

int SdfLoader::currentNumber ()
{
   return _current_number;
}

int SdfLoader::count ()
{
   int offset = _scanner->tell();
   int cn = _current_number;

   if (offset != _max_offset)
   {
      _scanner->seek(_max_offset, SEEK_SET);
      _preread.clear();
      _current_number = _offsets.size();
   }

   while (!isEOF())
      readNext();

   int res = _current_number;

   if (res != cn)
   {
      _scanner->seek(offset, SEEK_SET);
      _preread.clear();
      _current_number = cn;
   }

   return res;
}