Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

void GIFFManager::add_chunk ( GUTF8String  parent_name,
const GP< GIFFChunk > &  chunk,
int  pos = -1 
)

Adds the chunk {chunk} to chunk with name {parent_name} at position {pos}. {parent_name} may contain dots, brackets and colons. All missing chunks in the chain will be created.

{ Examples:} {verbatim} ;; To set the top-level chunk to 'ch' m.addChunk(".", ch); ;; To add 'ch' to the top-level chunk "DJVU" creating it if necessary m.addChunk(".DJVU", ch); ;; Same as above regardless of top-level chunk name m.addChunk("", ch); ;; To add 'ch' to 2nd FORM DJVU in top-level form DJVM m.addChunk(".FORM:DJVM.FORM:DJVU[1]", ch); ;; Same thing regardless of the top-level chunk name m.addChunk("FORM:DJVU[1]", ch); {verbatim}

Definition at line 330 of file GIFFManager.cpp.

References GIFFChunk::create(), GBaseString::length(), GBaseString::search(), GUTF8String::substr(), and GBaseString::toInt().

Referenced by add_chunk().

{
  DEBUG_MSG("GIFFManager::add_chunk(): Adding chunk to name='" << parent_name << "'\n");
  DEBUG_MAKE_INDENT(3);
   
  if (!top_level->get_name().length())
  {
    if ((!parent_name.length())||(parent_name[0]!='.'))
      G_THROW( ERR_MSG("GIFFManager.no_top_name") );
    if (parent_name.length() < 2)
    {
      // 'chunk' is actually the new top-level chunk
      DEBUG_MSG("since parent_name=='.', making the chunk top-level\n");
      if (!chunk->is_container())
        G_THROW( ERR_MSG("GIFFManager.no_top_cont") );
      top_level=chunk;
      return;
    }

    DEBUG_MSG("Setting the name of the top-level chunk\n");
    const int next_dot=parent_name.search('.',1);
    if(next_dot>=0)
    {
      top_level->set_name(parent_name.substr(1,next_dot-1));
    }else
    {
      top_level->set_name(parent_name.substr(1,(unsigned int)-1));
    }
  }

  DEBUG_MSG("top level chunk name='" << top_level->get_name() << "'\n");
   
  if (parent_name.length() && parent_name[0] == '.')
  {
    int next_dot=parent_name.search('.',1);
    if(next_dot<0)
    {
      next_dot=parent_name.length();
    }
    GUTF8String top_name=parent_name.substr(1,next_dot-1);
    if (!top_level->check_name(top_name))
      G_THROW( ERR_MSG("GIFFManager.wrong_name") "\t"+top_name);
    parent_name=parent_name.substr(next_dot,(unsigned int)-1);
  }

  GP<GIFFChunk> cur_sec=top_level;
  const char * start, * end=(const char *)parent_name-1;
  do
  {
    for(start=++end;*end&&(*end!='.');end++)
      EMPTY_LOOP;
    if (end>start)
    {
      GUTF8String name(start,end-start);
      GUTF8String short_name;
      int number=0;
      const int obracket=name.search('[');
      if (obracket >= 0)
      {
        const int cbracket=name.search(']',obracket+1);
        if (cbracket < 0)
          G_THROW( ERR_MSG("GIFFManager.unmatched") );
//        number=atoi((const char *)name.substr(obracket+1,cbracket-obracket-1));
        number = name.substr(obracket+1,cbracket-obracket-1).toInt();
        short_name=name.substr(0,obracket);
      }else
      {
        short_name=name;
      }

      for(int i=cur_sec->get_chunks_number(short_name);i<number+1;i++)
        cur_sec->add_chunk(GIFFChunk::create(short_name));
      cur_sec=cur_sec->get_chunk(name);
      if (!cur_sec)
        G_THROW( ERR_MSG("GIFFManager.unknown") "\t"+name);
    }
  } while(*end);
  cur_sec->add_chunk(chunk, pos);
}


Generated by  Doxygen 1.6.0   Back to index