Logo Search packages:      
Sourcecode: djvulibre version File versions

GP< DjVuFile > DjVuDocument::get_djvu_file ( const GUTF8String id,
bool  dont_create = false 
)

Returns {DjVuFile} corresponding to the specified ID. This function behaves exactly as the get_djvu_file()# function above. The only thing worth mentioning here is how the ID# parameter is treated.

First off, {id_to_url}() is called. If not successfull, the function checks, if the ID contains a number. If so, it just calls the get_djvu_file()# function above. If ID is ZERO# or just empty, page number #-1# is assumed.

If dont_create# is FALSE# the function will return the file only if it already exists.

Definition at line 949 of file DjVuDocument.cpp.

References DjVuFile::create(), get_djvu_file(), id_to_url(), GURL::is_empty(), and is_init_complete().

{
  check();
  DEBUG_MSG("DjVuDocument::get_djvu_file(): ID='" << id << "'\n");
  DEBUG_MAKE_INDENT(3);
  if (!id.length())
    return get_djvu_file(-1);

// Integers are not supported, only ID's  
//  if (id.is_int())
//     return get_djvu_file(id.toInt(),dont_create);
  
  GURL url;
  // I'm locking the flags because depending on what id_to_url()
  // returns me, I'll be creating DjVuFile in different ways.
  // And I don't want the situation to change between the moment I call
  // id_to_url() and I actually create DjVuFile
  {
    GMonitorLock lock(&flags);
    url=id_to_url(id);
    if(url.is_empty() && !id.is_int())
    {
      // If init is complete, we know for sure, that there is no such
      // file with ID 'id' in the document. Otherwise we have to
      // create a temporary file and wait for the init to finish
      if (is_init_complete())
        return 0;
      // Invent some dummy temporary URL. I don't care what it will
      // be. I'll remember the ID and will generate the correct URL
      // after I learn what the document is
      url=invent_url(id);
      DEBUG_MSG("Invented url='" << url << "'\n");

      GCriticalSectionLock lock(&ufiles_lock);
      for(GPosition pos=ufiles_list;pos;++pos)
      {
        GP<UnnamedFile> f=ufiles_list[pos];
        if (f->url==url)
          return f->file;
      }
      GP<UnnamedFile> ufile=new UnnamedFile(UnnamedFile::ID, id, 0, url, 0);

      // We're adding the record to the list before creating the DjVuFile
      // because DjVuFile::init() will call request_data(), and the
      // latter should be able to find the record.
      //
      // We also want to keep ufiles_lock to make sure that when
      // request_data() is called, the record is still there
      ufiles_list.append(ufile);
      
      GP<DjVuFile> file=DjVuFile::create(url,this,recover_errors,verbose_eof);
      ufile->file=file;
      return file;
    }
  }
     
  return get_djvu_file(url,dont_create);
}


Generated by  Doxygen 1.6.0   Back to index