source: branches/port5/PROBE_SET/ps_pg_tree_functions.cxx

Last change on this file was 5309, checked in by westram, 17 years ago
  • replaced calls to GB_find with new find-functions
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#ifndef PS_PG_TREE_FUNCTIONS_CXX
2#define PS_PG_TREE_FUNCTIONS_CXX
3
4#ifndef PS_DEFS_HXX
5#include "ps_defs.hxx"
6#endif
7
8#ifndef ARBDB_H
9#include <arbdb.h>
10#endif
11
12using namespace std;
13
14// API for Probe-Group-Database format
15
16// --------------------------------------------------------------------------------
17// mapping shortname <-> SpeciesID
18
19static Name2IDMap __NAME2ID_MAP;
20static ID2NameMap __ID2NAME_MAP;
21static bool       __MAPS_INITIALIZED = false;
22
23GB_ERROR PG_initSpeciesMaps(GBDATA *pb_main) {
24
25  GB_transaction pb_dummy(pb_main);
26
27  ps_assert(!__MAPS_INITIALIZED);
28
29  // look for existing mapping in pb-db:
30  GBDATA *pb_mapping = GB_entry(pb_main, "species_mapping");
31  if (!pb_mapping) {  // error
32    GB_export_error("No species mapping");
33  }  else {
34    // retrieve mapping from string
35    const char *mapping = GB_read_char_pntr(pb_mapping);
36    if (!mapping) return GB_export_error("Can't read mapping");
37   
38    while (mapping[0]) {
39      const char *komma     = strchr(mapping, ',');   if (!komma) break;
40      const char *semicolon = strchr(komma, ';');     if (!semicolon) break;
41      string      name(mapping, komma-mapping);
42      komma+=1;
43      string idnum(komma,semicolon-komma);
44      SpeciesID   id        = atoi(idnum.c_str());
45
46      __NAME2ID_MAP[name] = id;
47      __ID2NAME_MAP[id]   = name;
48
49      mapping = semicolon+1;
50    }
51  }
52
53  __MAPS_INITIALIZED = true;
54  return 0;
55}
56
57SpeciesID PG_SpeciesName2SpeciesID(const string& shortname) {
58  ps_assert(__MAPS_INITIALIZED); // you didn't call PG_initSpeciesMaps
59  return __NAME2ID_MAP[shortname];
60}
61
62const string& PG_SpeciesID2SpeciesName(SpeciesID num) {
63  ps_assert(__MAPS_INITIALIZED); // you didn't call PG_initSpeciesMaps
64  return __ID2NAME_MAP[num];
65}
66
67int PG_NumberSpecies(){
68    return __ID2NAME_MAP.size();
69}
70
71// db-structure of group_tree:
72//
73//                  <root>
74//                  |
75//                  |
76//                  "group_tree"
77//                  |
78//                  |
79//                  "node" <more nodes...>
80//                  | | |
81//                  | | |
82//                  | | "group" (contains all probes for this group; may be missing)
83//                  | |
84//                  | "num" (contains species-number (created by PG_SpeciesName2SpeciesID))
85//                  |
86//                  "node" <more nodes...>
87// 
88//  Notes:  - the "node"s contained in the path from "group_tree" to any "group"
89//            describes the members of the group
90
91
92
93// search or create "group_tree"-entry
94// static GBDATA *group_tree(GBDATA *pb_main) {
95//     return GB_search(pb_main, "group_tree", GB_CREATE_CONTAINER);
96// }
97
98
99GBDATA *PG_get_first_probe(GBDATA *pb_group) {
100    return GB_entry(pb_group, "probe");
101}
102
103GBDATA *PG_get_next_probe(GBDATA *pb_probe) {
104    ps_assert(GB_has_key(pb_probe, "probe"));
105    return GB_nextEntry(pb_probe);
106}
107
108const char *PG_read_probe(GBDATA *pb_probe) {
109    return GB_read_char_pntr(pb_probe);
110}
111
112GBDATA *PS_get_first_node(GBDATA *pb_nodecontainer) {
113    return GB_entry(pb_nodecontainer, "node");
114}
115
116GBDATA *PS_get_next_node(GBDATA *pb_node) {
117    ps_assert(GB_has_key(pb_node, "node"));
118    return GB_nextEntry(pb_node);
119}
120
121#else
122#error ps_pg_tree_functions.cxx included twice
123#endif
Note: See TracBrowser for help on using the repository browser.