<> <> <> <> <> 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: BOOL _ FALSE] RETURNS[e: Entity] = { segName, domainName, entityName: ROPE; domain: Domain; segment: Segment; [segName, domainName, entityName] _ DecomposeName[name]; segment _ Atom.MakeAtom[segName]; <> 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]; <> name _ Rope.Replace[name, 0, substrLength+1]; <> 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. . .