SAF_Unit *
saf_declare_unit(SAF_ParMode pmode,
SAF_Db *db, /* The database in which to create the new unit. */
const char *name, /* Optional singular unit name. */
const char *abbr, /* Optional singular abbreviation */
const char *url, /* Optional documentation URL. */
SAF_Unit *unit /* [OUT] Optional unit handle to initialize and return. */
)
{
SAF_ENTER(saf_declare_unit, NULL);
ss_scope_t scope;
SAF_REQUIRE(_saf_valid_pmode(pmode), SAF_LOW_CHK_COST, NULL,
_saf_errmsg("PMODE must be valid"));
if (!_saf_is_participating_proc(pmode)) SAF_RETURN(NULL);
ss_file_topscope(db, &scope);
unit = (ss_unit_t*)ss_pers_new(&scope, SS_MAGIC(ss_unit_t), NULL, SAF_ALL==pmode?SS_ALLSAME:0U, (ss_pers_t*)unit, NULL);
if (SAF_EACH==pmode) SS_PERS_UNIQUE(unit);
ss_string_set(SS_UNIT_P(unit,name), name);
ss_string_set(SS_UNIT_P(unit,abbr), abbr);
ss_string_set(SS_UNIT_P(unit,url), url);
SS_UNIT(unit)->scale = 1.0;
#ifdef HASH_UNITS /*RPM DEBUGGING 2004-09-26*/
/* Store the new unit in the hash table by both description and abbreviation */
if (!UHash) UHash = _saf_htab_new();
_saf_htab_insert(UHash, _saf_hkey_str(name), (ss_pers_t*)unit);
_saf_htab_insert(UHash, _saf_hkey_str(abbr), (ss_pers_t*)unit);
#endif
SAF_LEAVE(unit);
}