1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 SAF_Quantity *
 saf_declare_quantity(SAF_ParMode pmode,
                      SAF_Db *db,
                      const char *description,   /* A short description of the new quantity (e.g., "volume per time"). */
                      const char *abbreviation,  /* An optional abbreviation or symbol name for the quantity. */
                      const char *url,           /* An optional URL to the quantity documentation. */
                      SAF_Quantity *quant        /* [OUT] Optional quantity handle to initialize (and return). */
                      )
 {
     SAF_ENTER(saf_declare_quantity, 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);
     quant = (ss_quantity_t*)ss_pers_new(&scope, SS_MAGIC(ss_quantity_t), NULL, SAF_ALL==pmode?SS_ALLSAME:0U,
                                         (ss_pers_t*)quant, NULL);

     if (SAF_EACH==pmode) SS_PERS_UNIQUE(quant);
     ss_string_set(SS_QUANTITY_P(quant,name), description);
     ss_string_set(SS_QUANTITY_P(quant,abbr), abbreviation);
     ss_string_set(SS_QUANTITY_P(quant,url), url);

 #ifdef HASH_QUANTITIES /*RPM DEBUGGING 2004-09-26*/
     /* Store the new quantity in the hash table by both description and abbreviation */
     if (!QHash) QHash = _saf_htab_new();
     _saf_htab_insert(QHash, _saf_hkey_str(description), (ss_pers_t*)quant);
     _saf_htab_insert(QHash, _saf_hkey_str(abbreviation), (ss_pers_t*)quant);
 #endif

     SAF_LEAVE(quant);
 }