Esempio n. 1
0
void  ScannerFile::SaveIndexFile (vector<kkint64>&  frameOffsets)
{
  indexFileName = osRemoveExtension (fileName) + ".idx";
  ofstream f (indexFileName.Str ());
  f << "IndexFile"                                     << endl
    << "ScannerFile" << "\t" << fileName               << endl
    << "DateTime"    << "\t" << osGetLocalDateTime ()  << endl;

  f << "IndexEntryFields" << "\t" << "FrameNum"
                          << "\t" << "ScanLineNum"
                          << "\t" << "ByteOffset"
                          << endl;

  for  (kkuint32 frameNum = 0;  frameNum < frameOffsets.size ();  ++frameNum)
  {
    f << "IndexEntry" << "\t" << frameNum << "\t" << (frameNum * frameHeight) << "\t" << frameOffsets[frameNum] << endl;
  }

  StartStopPointList::const_iterator  idx;
  for  (idx = startStopPoints.begin ();  idx != startStopPoints.end ();  ++idx)
  {
    StartStopPointPtr ssp = *idx;
    f << "StartStopPoint" << "\t" << ssp->ToTabDelStr () << endl;
  }

  f.close ();
}  /* SaveIndexFile */
kkMemSize  StartStopPointList::MemoryConsumedEstimated ()  const
{
  const_iterator  idx2;

  kkMemSize mem = sizeof (*this);

  for  (idx2 = begin ();  idx2 != end ();  ++idx2)
  {
    StartStopPointPtr  sp = *idx2;
    mem += sp->MemoryConsumedEstimated ();
  }

  return  mem;
}
StartStopPointPtr  StartStopPointList::AddEntry (StartStopPointPtr&  _entry)
{
  if  (size () < 1)
  {
    push_back (_entry);
    return  _entry;
  }

  StartStopPointPtr  entryAdded = _entry;

  kkint32 m = FindGreaterOrEqual (_entry->ScanLineNum ());
  if  (m < 0)
    push_back (_entry);

  else 
  {
    StartStopPointPtr  existingEntry = (*this)[m];
    if  (existingEntry->ScanLineNum () == _entry->ScanLineNum ())
    {
      entryAdded = existingEntry;
      existingEntry->Type (_entry->Type ());
      delete  _entry;
      _entry = NULL;
    }
    else
    {
      entryAdded = _entry;
      idx = begin () + m;
      insert (idx, _entry);
    }
  }

  return  entryAdded;
}  /* AddEntry */
Esempio n. 4
0
void  ScannerFile::LoadIndexFile (bool&  successful)
{
  if  (indexFile)
  {
    delete  indexFile;
    indexFile = NULL;
  }

  indexFileName = osRemoveExtension (fileName) + ".idx";
  FILE* f = osFOPEN (indexFileName.Str (), "r");

  if  (!f)
  {
    log.Level (-1) << "LoadIndexFile  IndexFile[" << indexFileName << "] does not exist." << endl;
    successful = false;
    return;
  }

  KKStrPtr  ln = NULL;

  while  (true)
  {
    bool  eol = false;
    delete ln;
    ln = KKB::osReadRestOfLine (f, eof);
    if  (eof)  break;
    if  (!ln)  continue;

    KKStr lineName = ln->ExtractToken2 ("\t\n\r");

    if  (lineName.EqualIgnoreCase ("IndexEntry"))
    {
      kkuint32 frameNum    = ln->ExtractTokenUint   ("\t\n\r");
      kkint32  scanLineNum = ln->ExtractTokenInt    ("\t\n\r");
      kkuint64 byteOffset  = ln->ExtractTokenUint64 ("\t\n\r");
      UpdateFrameOffset (frameNum, scanLineNum, byteOffset);
      if  (scanLineNum > largestKnownScanLine)
        largestKnownScanLine = scanLineNum;
    }

    else if  (lineName.EqualIgnoreCase ("ClearStartStopPoints"))
    {
      startStopPoints.Clear ();
    }

    else if  (lineName.EqualIgnoreCase ("StartStopPoint"))
    {
      StartStopPointPtr  entry = new StartStopPoint (*ln);
      if  (entry->Type () == StartStopPoint::StartStopType::Invalid)
      {
        delete  entry;
        entry = NULL;
      }
      else
      {
        startStopPoints.AddEntry (entry);
      }
    }

    else if  (lineName.EqualIgnoreCase ("DeleteStartStopPoint"))
    {
      kkint32  scanLineNum = ln->ExtractTokenInt ("\n\t\r");
      startStopPoints.DeleteEntry (scanLineNum);
    }
  }
  delete  ln;
  ln = NULL;

  fclose (f);
  successful = true;
}  /* LoadIndexFile */