Logo Search packages:      
Sourcecode: djvulibre version File versions

int DjVmDir::insert_file ( const GP< File > &  file,
int  pos = -1 
)

Inserts the specified file record at the specified position. Specifying pos# equal to #-1# means to append. The actual position inserted is returned.

Definition at line 626 of file DjVmDir.cpp.

Referenced by DjVuDocEditor::create_shared_anno_file(), and DjVmDoc::insert_file().

{
   DEBUG_MSG("DjVmDir::insert_file(): name='" << file->name << "', pos=" << pos_num << "\n");
   DEBUG_MAKE_INDENT(3);
   
   GCriticalSectionLock lock((GCriticalSection *) &class_lock);
   
   if (pos_num<0)
     pos_num=files_list.size();

      // Modify maps
//   if (! File::is_legal_id(file->id))
//     G_THROW( ERR_MSG("DjVmDir.bad_file") "\t" + file->id);
   if (id2file.contains(file->id))
     G_THROW( ERR_MSG("DjVmDir.dupl_id2") "\t" + file->id);
   if (name2file.contains(file->name))
     G_THROW( ERR_MSG("DjVmDir.dupl_name2") "\t" + file->name);
   name2file[file->name]=file;
   id2file[file->id]=file;
   if (file->title.length())
     {
       if (title2file.contains(file->title))  // duplicate titles may become ok some day
         G_THROW( ERR_MSG("DjVmDir.dupl_title2") "\t" + file->title);
       title2file[file->title]=file;
     }

      // Make sure that there is no more than one file with shared annotations
   if (file->is_shared_anno())
   {
      for(GPosition pos=files_list;pos;++pos)
         if (files_list[pos]->is_shared_anno())
            G_THROW( ERR_MSG("DjVmDir.multi_save2") );
   }
   
      // Add the file to the list
   int cnt;
   GPosition pos;
   for(pos=files_list, cnt=0;pos&&(cnt!=pos_num);++pos, cnt++)
                   continue;
   if (pos)
     files_list.insert_before(pos, file);
   else
     files_list.append(file);

   if (file->is_page())
   {
         // This file is also a page
         // Count its number
      int page_num=0;
      for(pos=files_list;pos;++pos)
      {
         GP<File> &f=files_list[pos];
         if (f==file)
           break;
         if (f->is_page())
           page_num++;
      }

      int i;
      page2file.resize(page2file.size());
      for(i=page2file.size()-1;i>page_num;i--)
         page2file[i]=page2file[i-1];
      page2file[page_num]=file;
      for(i=page_num;i<page2file.size();i++)
         page2file[i]->page_num=i;
   }
   return pos_num;
}


Generated by  Doxygen 1.6.0   Back to index