source: tags/ms_r16q2/PROBE_SET/ps_pg_specmap.hxx

Last change on this file was 11464, checked in by westram, 10 years ago
  • un-dummy-fied transaction (renames only)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1#ifndef PS_PG_SPECMAP_HXX
2#define PS_PG_SPECMAP_HXX
3
4// -----------------------------------------
5//      mapping shortname <-> SpeciesID
6
7static Name2IDMap __NAME2ID_MAP;
8static ID2NameMap __ID2NAME_MAP;
9static bool       __MAPS_INITIALIZED = false;
10
11static GB_ERROR PG_initSpeciesMaps(GBDATA *pb_main) {
12
13  GB_transaction ta(pb_main);
14
15  ps_assert(!__MAPS_INITIALIZED);
16
17  // look for existing mapping in pb-db:
18  GBDATA *pb_mapping = GB_entry(pb_main, "species_mapping");
19  if (!pb_mapping) {  // error
20    GB_export_error("No species mapping");
21  }
22  else {
23    // retrieve mapping from string
24    const char *mapping = GB_read_char_pntr(pb_mapping);
25    if (!mapping) return GB_export_error("Can't read mapping");
26
27    while (mapping[0]) {
28      const char *comma     = strchr(mapping, ',');   if (!comma) break;
29      const char *semicolon = strchr(comma, ';');     if (!semicolon) break;
30      string      name(mapping, comma-mapping);
31      comma+=1;
32      string idnum(comma, semicolon-comma);
33      SpeciesID   id        = atoi(idnum.c_str());
34
35      __NAME2ID_MAP[name] = id;
36      __ID2NAME_MAP[id]   = name;
37
38      mapping = semicolon+1;
39    }
40  }
41
42  __MAPS_INITIALIZED = true;
43  return 0;
44}
45
46SpeciesID PG_SpeciesName2SpeciesID(const string& shortname) {
47  ps_assert(__MAPS_INITIALIZED); // you didn't call PG_initSpeciesMaps
48  return __NAME2ID_MAP[shortname];
49}
50
51inline const string& PG_SpeciesID2SpeciesName(SpeciesID num) {
52  ps_assert(__MAPS_INITIALIZED); // you didn't call PG_initSpeciesMaps
53  return __ID2NAME_MAP[num];
54}
55
56static int PG_NumberSpecies() {
57    return __ID2NAME_MAP.size();
58}
59
60#else
61#error ps_pg_specmap.hxx included twice
62#endif // PS_PG_SPECMAP_HXX
Note: See TracBrowser for help on using the repository browser.