File: DBNamesImpl.mesa
last edited by:
Cattell, July 5, 1983 5:00 pm
Donahue, March 20, 1986 9:33:00 am PST
Willie-sue, March 27, 1986 5:52:18 pm PST
DIRECTORY
Atom,
DB,
DBDefs,
DBNames,
Rope;
DBNamesImpl: CEDAR PROGRAM IMPORTS Atom, Rope, DB EXPORTS DBNames =
BEGIN OPEN Rope, DBDefs;
Separator: PUBLIC CHAR ← '#;
Sep: ROPE = Rope.FromChar[Separator];
EntityToName: PUBLIC PROC[e: Entity, seg: Segment] RETURNS[ name: ROPE ] = {
name ← Rope.Cat[DB.GetSegmentInfo[seg].filePath, Sep, Atom.GetPName[seg], Sep];
name ← Rope.Cat[ name, DB.DomainInfo[DB.EntityInfo[e].domain].name, Sep, DB.EntityInfo[e].name ] };
MakeName: PUBLIC PROC[seg: Segment, domain, eName: ROPE] RETURNS[name: ROPE] =
{ name ← Rope.Cat[DB.GetSegmentInfo[seg].filePath, Sep, Atom.GetPName[seg], Sep];
name ← Rope.Cat[ name, domain, Sep, eName ] };
NameToEntity: PUBLIC PROC[name: ROPE, create: BOOLFALSE] RETURNS[e: Entity] = {
segName, domainName, entityName: ROPE;
domain: Domain;
segment: Segment;
[segName, domainName, entityName] ← DecomposeName[name];
segment ← Atom.MakeAtom[segName];
check to make sure that this is the right segment for the entity
IF NOT Rope.Equal[DB.GetSegmentInfo[segment].filePath, SegmentOf[name].filePath, FALSE]
THEN RETURN[NIL];
domain ← DB.LookupDomain[ domainName, segment !
DB.Error => CHECKED { domain ← NIL; CONTINUE } ];
e ← IF domain = NIL THEN NIL ELSE DB.LookupEntity[ domain, entityName ];
IF e = NIL AND domain # NIL AND create THEN
e ← DB.DeclareEntity[ domain, entityName ! DB.Error => CONTINUE ] };
SegmentOf: PUBLIC PROC[name: ROPE] RETURNS[segment: Segment, filePath: ROPE] = {
segmentName: ROPE;
substrLength: INT ← Rope.Find[name, Sep]; -- always has the length to the next separator
filePath ← Rope.Substr[name, 0, substrLength];
name ← Rope.Replace[name, 0, substrLength+1]; -- make sure to throw away the separator
substrLength ← Rope.Find[name, Sep];
segmentName ← Rope.Substr[name, 0, substrLength];
RETURN[ Atom.MakeAtom[segmentName], filePath ] };
DecomposeName: PUBLIC PROC[name: ROPE] RETURNS[segment, domain, entity: ROPE] =
BEGIN
substrLength: INT ← Rope.Find[name, Sep];
throw away the leading file path information
name ← Rope.Replace[name, 0, substrLength+1];
now get the remaining fields
substrLength ← Rope.Find[name, Sep];
segment ← Rope.Substr[name, 0, substrLength];
name ← Rope.Replace[name, 0, substrLength+1];
substrLength ← Rope.Find[name, Sep];
domain ← Rope.Substr[name, 0, substrLength];
entity ← Rope.Replace[name, 0, substrLength+1]
END;
END. . .