new object $has_name: $foundation; var $has_name name = ['normal, "named object", "a named object"]; var $has_name templates = 0; var $root created_on = 796268969; var $root fertile = 1; var $root flags = ['methods, 'code, 'fertile, 'core, 'variables]; var $root inited = 1; var $root managed = [$has_name]; var $root manager = $has_name; public method .add_name_template() { arg template; var p; (> .perms(sender()) <); for p in (explode(template, "|")) { if (match_begin(name[2], p.strip())) throw(~redundant, ("Redundant name template part \"" + p) + "\" already matches name."); } templates = setadd(templates || [], template); }; public method .del_name_template() { arg template; (> .perms(sender()) <); templates = setremove(templates || [], template); if (!templates) (| clear_var('templates) |); }; public method .hname() { arg @args; return ((("<a href=\"/bin/describe?target=" + (.objname())) + "\">") + (.name())) + "</a>"; }; public method .init_has_name() { var objname; objname = tostr(.objname()); name = ['prop, tostr(objname), tostr(objname)]; }; public method .match_name() { arg str; var m, t; if ((m = match_begin(name[2], str))) return m; for t in (templates || []) { if ((m = match_template(str, t))) return m; } return 0; }; public method .match_name_exact() { arg str; return str == (name[2]); }; public method .name() { arg @args; if (!name) return tostr(this()); if (!args) return name[3]; switch (args[1]) { case 'type: return name[1]; case 'noarticle: return name[2]; default: return name; } }; public method .name_templates() { return templates || []; }; public method .namef() { arg type; switch (type) { case 'ref: return (((.name()) + " (") + this()) + ")"; case 'xref: return ((this() + " (") + (.name())) + ")"; case 'name: return .name(); default: return (> pass(type) <); } }; public method .set_name() { arg new_name, @args; var type; (> .perms(sender()) <); if (new_name && ((new_name[1]) in ["$", "#"])) throw(~invname, "Names cannot begin with \"$\" or \"#\"."); if (type(new_name) != 'string) throw(~type, "New name must be given as a string."); [(type ?= 'normal)] = args; if ((type != 'prop) && (new_name.match_regexp("^(a|an|the) +"))) throw(~bad_name, "Config error: articles included in unique or normal name."); if (!(type in ['prop, 'normal, 'uniq])) throw(~invarg, "Type must be one of: 'prop, 'normal or 'uniq"); switch (type) { case 'prop: new_name = [new_name, new_name]; case 'uniq: new_name = [new_name, "the " + new_name]; case 'normal: new_name = [new_name, new_name.add_indefinite()]; } name = [type, @new_name]; };