///////////////////////////////////////// // i_begin(i_name) (+) // insert i_name as local to current DB // push empty DB(i_name) // BtFImpl(i_begin, a, p) { Term t; if (!(t = p->eval_term(a.getarg(0))).type(f_ATOM)) { p->BtErr(BTERR_INVALID_ARG_TYPE); return 0; } DbIntlog *db = p->get_db(); kstring idi = t.kstr(); if ((db = db->BeginInterface(idi)) == 0) { p->BtErr(BTERR_CANT_BEGINTERF, CCP(idi)); return 0; } p->set_db(db); return 1; }
/////////////////////////////////////////////////// // i_end(i_name) (+) // pop current DB (interface became instantiable) // BtFImpl(i_end, a, p) { Term t; if (!(t = p->eval_term(a.getarg(0))).type(f_ATOM)) { p->BtErr(BTERR_INVALID_ARG_TYPE); return 0; } DbIntlog *db = p->get_db(); kstring dbid = db->GetId(), idi = t.kstr(); if (dbid != idi || (db = db->EndInterface()) == 0) { CCP sdb = MemStoreRef(dbid) != MSR_NULL ? dbid : ""; p->BtErr(BTERR_CANT_ENDINTERF, CCP(idi), sdb); return 0; } p->set_db(db); return 1; }
///////////////////////////////////////////// // i_proplist(NameInt,Property,List) (+,+,?) // retrieve property name/arity list // for required interface e property // BtFImpl(i_proplist, t, p) { Term NameInt = p->eval_term(t.getarg(0)), Prop = p->eval_term(t.getarg(1)), ListProp(ListNULL); DbIntlog *db; if ( !NameInt.type(f_ATOM) || !Prop.type(f_ATOM) || (db = findint(p->get_db(), NameInt.kstr())) == 0) { err: p->BtErr(BTERR_INVALID_ARG_TYPE); return 0; } // search for property DbEntry::scopemode prop; BuiltIn* bt = p->get_db()->is_builtin(Prop, 1); if (!bt) goto err; if (bt->eval == i_export) prop = DbEntry::exported; else if (bt->eval == i_import) prop = DbEntry::import; else if (bt->eval == i_dynamic) prop = DbEntry::dynamic; else if (bt->eval == i_begin) prop = DbEntry::local; else goto err; slist lprop; db->EntriesWithProperty(prop, lprop); // transform the slist in Prolog List if (lprop.numel() > 0) { Term tail(f_NOTERM); slist_iter it(lprop); DbIntlog::EntryWithProp *pEntry; while ((pEntry = (DbIntlog::EntryWithProp *)it.next()) != 0) { // build the name/arity structure Term sProp = Term(kstring(Operator::DIV), 2); sProp.setarg(0, Term(kstring(pEntry->id))); sProp.setarg(1, Term(Int(pEntry->arity))); Term elem = Term(sProp, Term(ListNULL)); if (tail.type(f_NOTERM)) tail = ListProp = elem; else { tail.setarg(1, elem); tail = elem; } } ListProp = p->save(ListProp); } return p->unify(t.getarg(2), ListProp); }