Exemplo n.º 1
0
iterator* info_base::first(char* col_nm, c_code_t code)
{
   handler* x = get_set(col_nm);

   if ( x == 0 ) {
      handler* x = get_list(col_nm);
   }

   if ( x == 0 ) {
      throw(stringException("unknown collection name"));
   }

   page_storage *s = (page_storage*)(x -> its_store());

   if ( s == 0 ) {
      throw(stringException("collection has no store"));
   }

   if ( s -> my_oid().ccode() != PAGE_STORAGE_CODE ) {
      throw(stringException("non page store no supported"));
   }

   iterator* it = new iterator(x, code);

   it -> ind = s -> first_loc();

   if ( managers::template_mgr -> peek_slot(s, it->ind) != code ) {
      this -> next(*it);
   }

   return it;
}
Exemplo n.º 2
0
Arquivo: tuple.C Projeto: juddy/edcde
io_status tuple::asciiIn(istream& in)
{

/*
MESSAGE(cerr, "in tuple asciiIn()");
my_oid().asciiOut(cerr);
MESSAGE(cerr, "\n");
*/
   int comps; in >> comps; 

   if ( comps > MAX_COMPS ) {
      debug(cerr, comps);
      throw(stringException("exceed MAX_COMPS"));
   }

//debug(cerr, comps);

   int ret = in.get();

   if ( ret != '\n' ) {
      debug(cerr, ret);
      throw(stringException("'\\n' expected"));
   }

   if ( comps > (int) v_sz ) {
MESSAGE(cerr, "tuple asciiIn(): to expand space");
debug(cerr, comps);
debug(cerr, v_sz);
     oid_list::expand_space(comps - v_sz);
     v_sz = comps;
   }


   handler *hd_ptr = 0;

   for ( int i=1; i<=comps; i++ ) {
 
      c_code_t ccode;
      in >> ccode;  

      if ( in.get() != '\n' ) {
         throw(stringException("'\\n' expected"));
      }

      hd_ptr = new handler(ccode, storage_ptr);

      (*hd_ptr) -> asciiIn(in);

      pinned_insert(i, hd_ptr -> its_oid());

      delete hd_ptr;
   }

   set_mode(UPDATE, true);

   return done;
}
Exemplo n.º 3
0
/////////////////////////////////////////////////
// load mixed stream of infobase data from stdin.
/////////////////////////////////////////////////
void insert_to_collection(c_code_t ccode, istream& in)
{
    enum coll_type { VOID, SET, LIST };

    coll_type obj_type = VOID;

    abs_storage* store = 0;
//  handler* hd = 0;

    int i;
    for ( i = 0; i<SET_MAP_SZ ; i++ ) {
      if ( set_map[i].instance_class_code == ccode ) {
         obj_type = SET;
         store = set_map[i].collection_hd -> its_store();
//       hd = set_map[i].collection_hd;
         break;
      }
    }

    if ( obj_type == VOID ) 
    for ( i = 0; i<LIST_MAP_SZ ; i++ ) {
       if ( list_map[i].instance_class_code == ccode ) {
         obj_type = LIST;
          store = list_map[i].collection_hd -> its_store();
//        hd = set_map[i].collection_hd;
          break;
       }
    }

    if ( store == 0 ) {
       throw(stringException(form("unknown class code %d", ccode)));
    }

    handler* root_hd_ptr = new handler(ccode, store);

    (*root_hd_ptr) ->asciiIn(in);
    root_hd_ptr -> commit();

    switch ( obj_type ) {
       case SET:
         (*(cset_handlerPtr)(set_map[i].collection_hd)) ->
             insert_object(*root_hd_ptr);
         break;
       case LIST:
         (*(dl_list_handlerPtr)(list_map[i].collection_hd)) -> 
              insert_as_tail(*(dl_list_cell_handler*)root_hd_ptr);
         break;
       default:
         cerr << "bad ccode = " << ccode << "\n";
         throw(stringException("bad ccode"));
   }

   delete root_hd_ptr;

}
Exemplo n.º 4
0
int _load_mixed_objects(info_base* base_ptr, istream& in)
{
   int i;
   for ( i = 0; i<SET_MAP_SZ ; i++ ) {
      cset_handlerPtr x = base_ptr -> get_set(set_map[i].col_name);

      if (x==0)
         throw(stringException("null cset_handler pointer"));

      (*x) -> batch_index_begin();
      set_map[i].collection_hd = x;
   }

   for ( i = 0; i<LIST_MAP_SZ ; i++ ) {
      dl_list_handlerPtr x = base_ptr -> get_list(list_map[i].col_name);

      if (x==0)
         throw(stringException("null cset_handler pointer"));

      (*x) -> batch_index_begin();
      list_map[i].collection_hd = x;
   }

   
   char ccode_buf[LBUFSIZ];
   int ccode;

   while ( in.getline(ccode_buf, LBUFSIZ) ) {
      sscanf(ccode_buf, "%u", &ccode);
//debug(cerr, ccode);

      if ( ccode == SGML_CONTENT_CODE )
         sgml_content_load(base_ptr, in);
      else
         insert_to_collection(ccode, in);
   }

   for ( i = 0; i<SET_MAP_SZ ; i++ ) {
      cset_handlerPtr x = (cset_handlerPtr)(set_map[i].collection_hd);
      (*x) -> batch_index_end();
   }

   for ( i = 0; i<LIST_MAP_SZ ; i++ ) {
      dl_list_handlerPtr x = (dl_list_handlerPtr)(list_map[i].collection_hd);
      (*x) -> batch_index_end();
   }

   return 0;
}
Exemplo n.º 5
0
smart_ptr::smart_ptr(info_lib* lib_ptr,
                     const char* ibase_name, 
                     int composite_pos,
                     const handler& query_hd,
                     int index_selector,
                     composite_tag tag
                    ) 
{
   info_base* ibase = lib_ptr -> get_info_base(ibase_name);

   if ( ibase == 0 ) {
       throw(stringException(
          form("unknown base %s in %s\n", ibase_name, 
               lib_ptr -> get_info_lib_path()
            )));
   }
//debug(cerr, ibase -> num_of_docs());

   switch (tag) {
     case SET:
      {
      cset_handlerPtr set_ptr = ibase -> get_set(composite_pos);

      if ( set_ptr == 0 )
         throw(stringException("NULL set ptr"));

      _init((*set_ptr)->get_first_oid(query_hd, index_selector),
            set_ptr -> its_store()
           );
      }
      break;
     case LIST:
      {
      dl_list_handlerPtr list_ptr = ibase -> get_list(composite_pos);

      if ( list_ptr == 0 )
         throw(stringException("NULL set ptr"));

      _init((*list_ptr)->get_first_oid(query_hd, index_selector),
            list_ptr -> its_store()
           );
      }
      break;
     default:
      throw(stringException("unknown tag"));
   }

}
Exemplo n.º 6
0
const char* smart_ptr::get_string(int i)
{
  handler* x = _get_component(i);

  x -> operator->(); // this will bring the its_oid field up-to-date

  char* str;

  switch ( x -> its_oid().ccode() ) {
     case STRING_CODE:
       {
       str = (*(pstring_handler*)x) -> get();
       break;
       }
     case COMPRESSED_STRING_CODE:
       {
       str = (*(compressed_pstring_handler*)x) -> get();
       break;
       }

     default:
       throw(stringException("invalid node data class code"));
  }

  delete x;

  return str;
}
Exemplo n.º 7
0
oid_t get_nth_mark_id(mark_base* ub, char* key, int n)
{
   oid_list_handler* handle = ub -> get_mark_list(key);
   
   if ( handle == 0 ) {
     throw(stringException("empty mark list"));
   }

   int ind = (*handle) -> first();

   int i = 0;

   while (ind) {

      if ( n == i ) {
        oid_t id = (*handle) -> operator()(ind);
        delete handle;
        return id;
      }

      (*handle) -> next(ind);
      i++;
   }
   
   int count = (*handle)->count();
   delete handle;
   throw(boundaryException(0, count, i));
}
Exemplo n.º 8
0
Arquivo: lru.C Projeto: juddy/edcde
Boolean lru::derank(rep_cell& x, position_t opt)
{
   switch (x.get_position()) {
     case ACTIVE:
        //MESSAGE(cerr, "active status to derank");
        active_list.delete_cell(&x);
        break;

     case INACTIVE:
        //MESSAGE(cerr, "derand: an inactive cell");
        inactive_list.delete_cell(&x);
        opt = INACTIVE;
        break;

     case NOWHERE:
        throw(stringException("lru::derand(): nowhere status"));
   }

   switch ( opt ) {
     case ACTIVE:
        active_list.insert_as_tail(&x);
        x.set_position(ACTIVE);
        break;
     case INACTIVE:
        inactive_list.insert_as_tail(&x);
        x.set_position(INACTIVE);
        break;
     default:
        break;
   }

   return true;
}
Exemplo n.º 9
0
void info_base::build_dict(char* agent_name)
{
   compress_agent_handler* x = (compress_agent_handler*)
                  (f_obj_dict -> get_handler(agent_name));

   if ( x == 0 )
      throw(stringException("info_base::build_dict(): unknown compress agent"));

   if ( strstr(agent_name, ".sgml.") != NULL ) {
      (*x) -> build_dict(sgmllex, stdin_sgml_data_getchar);
   } else
   if ( strstr(agent_name, ".ps.") != NULL ) {
      (*x) -> build_dict(pslex, stdin_ps_data_getchar);
   } else
      throw(stringException("info_base::build_dict(): unknown compress target"));
}
Exemplo n.º 10
0
int _update_by_id_subtest(istream& in, oid_t id, mark_base* ub)
{
   char* data;
   mark_smart_ptr* x = 0;
   _get_data(in, data);

    x = new mark_smart_ptr(ub, id);
                      
    cout << x -> its_oid() << "\n";

    x -> update_usermark(data, strlen(data));
    delete x;

    x = new mark_smart_ptr(ub, id);
                      
    pstring* y = x->mark_value();
                      
    if ( y -> size() != strlen(data) || strcmp(y -> get(), data) != 0 ) 
    {
      debug(cerr, y->size());
      debug(cerr, (long)strlen(data));
      debug(cerr, y -> get());
      debug(cerr, data);
      throw(stringException("improperly updated mark"));
                      
    }
                      
    delete x;

    return 0;
}
Exemplo n.º 11
0
int stdin_sgml_data_getchar(unsigned char* buf, int max_sz)
{
   static int remain_chars = 0;
   static int chars_to_read;
   static char loc_buf[LBUFSIZ];

   if ( remain_chars == 0 ) {
      if ( fgets(loc_buf, LBUFSIZ, stdin) == NULL )
         return 0;

      if ( fgets(loc_buf, LBUFSIZ, stdin) == NULL )
         throw(stringException("no locator line"));

      if ( fscanf(stdin, "%d", &remain_chars) != 1 )
         throw(stringException("sgml_data_getchar(): fscanf() failed"));

      if ( getc(stdin) != '\t' ) {
         debug(cerr, remain_chars);
         throw(stringException("'\\t' expected"));
      }

   }

   chars_to_read = MIN(max_sz, remain_chars);

   if ( fread((char*)buf, 1, chars_to_read, stdin) != chars_to_read ) {
      throw(stringException("sgml_data_getchar(): fread() failed"));
   }

   remain_chars -= chars_to_read;

   if ( remain_chars == 0 ) {
      if ( getc(stdin) != '\n' )
         throw(stringException("'\\n' expected"));
   }

/*
for ( int i=0; i<chars_to_read; i++ ) {
   cerr << buf[i];
}
MESSAGE(cerr, "\n");
debug(cerr, max_sz);
debug(cerr, chars_to_read);
*/

   return chars_to_read;
}
Exemplo n.º 12
0
handler* smart_ptr::get_handler(int i, c_code_t code)
{
   handler* x =  _get_component(i); 
   x -> operator->();                      

   if ( x -> its_oid().ccode() != code )   
       throw(stringException("invalid node data class code"));

   return x;
}
Exemplo n.º 13
0
oid_list_handler* dl_list::get_locs(handler& query, int index)
{
   if ( !INRANGE(index, 0, (int) v_num_indices-1) )
      throw(boundaryException(0, v_num_indices-1, index));

   if ( v_indices[index] == 0 ) 
      throw(stringException("NULL index handler ptr"));

   return (*v_indices[index]) -> get_loc_list(query);
}
Exemplo n.º 14
0
int btree_index::handler_to_inv_idx(const handler& query)
{
   get_key_string(query);

   data_t k(v_static_key.get(), v_static_key.size());

   if ( v_idx_agent_ptr -> member(k) == false )
     throw(stringException("first_of_invlist(): key is not in btree"));

   return int(k.dt);
}
Exemplo n.º 15
0
oid_t info_base::get_oid(const iterator& it)
{
   page_storage *s = (page_storage*)( it.collection_hd -> its_store() );

   root *r = 0;
   managers::template_mgr -> init_obj(s, it.ind, r);
   if (r == 0)
       throw(stringException("null root pointer"));

   return r -> my_oid();
}
Exemplo n.º 16
0
void connectNodeToDoc(info_lib* x_lib)
{
   if ( x_lib == 0 )
      throw(stringException("connectNodeToDoc: can't find infolib"));

   info_base* x_base = 0;

   long ind = x_lib -> first();

   while ( ind ) {
      x_base = (*x_lib)(ind);

      if ( x_base == 0 )
         throw(stringException("connectNodeToDoc: null base pointer"));

      _connectNodeToDoc(x_base);

      x_lib -> next(ind);
   };
}
Exemplo n.º 17
0
Arquivo: lru.C Projeto: juddy/edcde
long lru::last(position_t option)
{
   switch (option) {
      case ACTIVE:
         return active_list.last();
      case INACTIVE:
         return inactive_list.last();
      default:
         throw(stringException("lru::last(): bad option"));
   }
}
Exemplo n.º 18
0
Arquivo: lru.C Projeto: juddy/edcde
rep_cell* lru::operator()(long index, position_t option)
{
   switch (option) {
      case ACTIVE:
         return (rep_cell*)(index);
      case INACTIVE:
         return (rep_cell*)(index);
      default:
         throw(stringException("lru::operator(): bad option"));
   }
}
Exemplo n.º 19
0
info_base* olias_server::get_infobase(const char *locator_string, enum TestSelector sel)
{

   if ( locator_string == 0 )
      return 0;


   info_base* ib = 0;

   int ind = infolibptr -> first();

   while ( ind ) {

      ib =  (*infolibptr)(ind);

      if (ib==0)
         throw(stringException("null info_base ptr"));

      try { // since an infobase may not have any graphics, we catch
            // any exceptions there and try next infobase.

         switch (sel) {
          case LOC:
   	   {
            locator_smart_ptr loc(ib, locator_string);
   
//fprintf(stderr, "inside-loc-string=%s\n", loc.inside_node_locator_str());
//fprintf(stderr, "loc-string=%s\n", locator_string);
            if ( strcmp( loc.inside_node_locator_str(), locator_string) == 0 ) {
               return ib;
            }
   
           }
          case GRA:
   	   {
            graphic_smart_ptr graphic(ib, locator_string);
   
            if ( strcmp( graphic.locator(), locator_string) == 0 ) {
               return ib;
            }
           }
         }
      }

      catch (mmdbException &,e)
      {
      } end_try;


      infolibptr -> next(ind);
   }

   return 0;
}
Exemplo n.º 20
0
void _get_key(istream& in, char*& key)
{
   static char buf[LBUFSIZ];
   in.getline(buf, LBUFSIZ);

   if ( buf[0] != 'k' || buf[1] != '\t' ) {
       debug(cerr, buf);
     throw(stringException("_get_key(): missing k\t"));
   }

   key = buf + 2;
}
Exemplo n.º 21
0
void _get_key_pos(istream& in, char*& key, int& n)
{
   static char buf[LBUFSIZ];
   in.getline(buf, LBUFSIZ);

   if ( buf[0] != 'k' || buf[1] != '\t' ) {
       debug(cerr, buf);
     throw(stringException("_get_key_pos(): missing k\t"));
   }

   key = buf + 2;

   char* nextToken = strchr(key, '\t');

   if ( nextToken == 0 )
     throw(stringException("can't find position (integer)."));

   *nextToken = 0;

   n = atoi(nextToken+1);
}
Exemplo n.º 22
0
void _get_data(istream& in, char*& data)
{
   static char buf[LBUFSIZ];
   in.getline(buf, LBUFSIZ);

   if ( buf[0] != 'd' || buf[1] != '\t' ) {
       debug(cerr, buf);
     throw(stringException("_get_data(): missing d\t"));
   }

   data = buf + 2;
}
Exemplo n.º 23
0
Arquivo: lru.C Projeto: juddy/edcde
void lru::next(long& index, position_t option)
{
   switch (option) {
      case ACTIVE:
         active_list.next(index);
         return;
      case INACTIVE:
         inactive_list.next(index);
         return;
      default:
         throw(stringException("lru::next(): bad option"));
   }
}
Exemplo n.º 24
0
io_status dl_list::asciiOut(ostream& out) 
{
/*   
MESSAGE(cerr, "HEAD");
v_dl_list_head.asciiOut(out); cerr << "\n";

MESSAGE(cerr, "TAIL");
v_dl_list_tail.asciiOut(out); cerr << "\n";
*/
   out << "OID_T:\n";
   my_oid().asciiOut(out); 
   out << "\n";

   if ( v_sz == 0 ) return done;

   oid_t* cell_ptr = &v_dl_list_head;

   for ( unsigned int i=1; i<=v_sz; i++ ) {

       if ( cell_ptr == 0 ) {
          throw(stringException("broken chain"));
       }

       if ( cell_ptr -> icode() == 0 ) {
          debug(cerr, i);
          debug(cerr, v_sz);
          throw(stringException("dl_list::get_component(): broken chain"));
       }

       dl_list_cell_handler cell(*cell_ptr, storage_ptr);


       cell -> asciiOut(cerr); cerr << "\n";
       cell_ptr = &cell -> get_forward_ptr();

   }

   return done;
}
Exemplo n.º 25
0
oid_t dl_list::get_first_oid(const handler& query, int index)
{
   if ( !INRANGE(index, 0, (int) v_num_indices-1) ) {
       MESSAGE(cerr, "cset::get_first_oid(): invalid index");
       throw(boundaryException(0, v_num_indices-1, index));
   }

   if ( v_indices[index] == 0 ) {
       throw(stringException("cset::get_first_oid(): NULL index ptr"));
   }

   return (*v_indices[index]) -> first_of_invlist(query);
}
Exemplo n.º 26
0
int data_t::operator==(data_t& d)
{
   if ( flag != d.flag ) {

      debug(cerr, flag);
      debug(cerr, d.flag);

      debug(cerr, *this);
      debug(cerr, d);

      throw(stringException("data_t type mismatches in operator==()"));
   }

   switch (flag) {
      case INT:
        return key.int_key == d.key.int_key ;
      case STRING:
        return strcmp(key.str_key, d.key.str_key) == 0 ;
      case VOID:
        throw(stringException("VOID type in operator==()"));
   }
}
Exemplo n.º 27
0
smart_ptr::smart_ptr(info_base* ibase, 
                     int composite_pos,
                     const handler& query_hd,
                     int index_selector,
                     composite_tag tag
                    ) 
{
   switch (tag) {
     case SET:
      {
      cset_handlerPtr set_ptr = ibase -> get_set(composite_pos);

      if ( set_ptr == 0 )
         throw(stringException("NULL set ptr"));

      _init((*set_ptr)->get_first_oid(query_hd, index_selector),
            set_ptr -> its_store()
           );
      }
      break;
     case LIST:
      {
      dl_list_handlerPtr list_ptr = ibase -> get_list(composite_pos);

      if ( list_ptr == 0 )
         throw(stringException("NULL set ptr"));

      _init((*list_ptr)->get_first_oid(query_hd, index_selector),
            list_ptr -> its_store()
           );
      }
      break;
     default:
      throw(stringException("unknown tag"));
   }

}
Exemplo n.º 28
0
void pstring::_asciiIn(istream& in) 
{
   if ( ! cc_is_digit(in) )
      throw (stringException("a digit expected"));

   int len;
   in >> len;

   int tab = in.get(); // expect a '\t'

   if ( tab != '\t' ) {
      debug(cerr, len);
      debug(cerr, tab);
      throw(stringException("'\\t' expected"));
   }

   v_io_buf.reset();
   v_io_buf.expand_chunk(len);

   if (  len > 0 && 
         ( !in.read(v_io_buf.get_base(), len) || in.gcount() != len ) 
      ) {
      debug(cerr, len);
      debug(cerr, v_io_buf.get_base());
      throw(stringException("pstring::asciiIn(): read failed"));
   }

   int ret = in.get(); // expect a '\n'

   if ( ret != '\n' ) {
      debug(cerr, ret);
      throw(stringException(form("'\\n' expected. %c seen. (count=%d)", ret, len)));
   }

   v_io_buf.set_content_sz(len);
}
Exemplo n.º 29
0
void _get_id(istream& in, oid_t& x)
{
   static char buf[LBUFSIZ];
   in.getline(buf, LBUFSIZ);

   if ( buf[0] != 'k' || buf[1] != '\t' ) {
       debug(cerr, buf);
       throw(stringException("_get_id(): missing k\t"));
   }

    char* key = buf+2;

    oid_t id(key, true, false);

    x = id;
}
Exemplo n.º 30
0
Arquivo: lru.C Projeto: juddy/edcde
Boolean lru::remove(rep_cell& x)
{
  switch (x.get_position()) {
     case ACTIVE:
       active_list.delete_cell(&x);
       return true;

     case INACTIVE:
       inactive_list.delete_cell(&x);
       return true;

     case NOWHERE:
       throw(stringException("lru::last(): bad option"));
   }

   return false;
}