-- File: DBNamesImpl.mesa
-- last edited by Donahue, May 20, 1983 9:58 am
-- Last Edited by: Willie-sue, February 22, 1983 4:08 pm
DIRECTORY
DB,
DBEnvironment,
DBNames,
Atom,
NutOps,
Rope;
DBNamesImpl: CEDAR PROGRAM
IMPORTS Rope, DB, Atom, DBEnvironment, NutOps
EXPORTS DBNames =
BEGIN OPEN Rope, DB, Atom;
Separator: PUBLIC CHAR ← '!;
Sep: ROPE = Rope.FromChar[Separator];
EntityToName: PUBLIC PROC[ e: Entity, seg: DB.Segment ← NIL ] RETURNS[ name: ROPE ] = {
IF NOT NutOps.IsSystemDomain[d: DomainOf[e]] THEN seg ← DB.SegmentOf[e];
name ← Rope.Cat[ GetPName[seg], Sep, NameOf[DomainOf[e]], Sep, NameOf[e] ]};
NameToEntity: PUBLIC PROC[ name: ROPE ] RETURNS[ e: Entity ] = {
segNameLength: INT = Rope.Find[ name, Sep ];
domainNameLength: INT = Rope.Find[ name, Sep, segNameLength+1 ] - segNameLength - 1;
segName: ROPE = Rope.Substr[ name, 0, segNameLength ];
domainName: ROPE = Rope.Substr[ name, segNameLength+1, domainNameLength ];
entityName: ROPE = Rope.Substr[ name, segNameLength+domainNameLength+2 ];
segment: DB.Segment = Atom.MakeAtom[ segName ];
domain: Domain;
domain ← DeclareDomain[ domainName, segment, Version[OldOnly] !
DBEnvironment.Error => CHECKED { domain ← NIL; CONTINUE } ];
e ← IF domain = NIL THEN NIL
ELSE FetchEntity[ domain, entityName, segment ] };
SegmentOf: PUBLIC PROC[ name: ROPE ] RETURNS[ segment: DB.Segment ] = {
segNameLength: INT = Rope.Find[ name, Sep ];
segName: ROPE = Rope.Substr[ name, 0, segNameLength ];
RETURN[ Atom.MakeAtom[ segName ] ] };
END. . .