source: branches/gcc/SL/TREE_READ/LabelTranslator.h

Last change on this file was 19913, checked in by westram, 7 days ago
File size: 2.4 KB
Line 
1// ========================================================= //
2//                                                           //
3//   File      : LabelTranslator.h                           //
4//   Purpose   : Translate tree labels                       //
5//                                                           //
6//   Coded by Ralf Westram (coder@reallysoft.de) in Sep 21   //
7//   http://www.arb-home.de/                                 //
8//                                                           //
9// ========================================================= //
10
11#ifndef LABELTRANSLATOR_H
12#define LABELTRANSLATOR_H
13
14#ifndef ARBDB_BASE_H
15#include <arbdb_base.h>
16#endif
17#ifndef ARB_UNORDERED_MAP_H
18#include <arb_unordered_map.h>
19#endif
20#ifndef _GLIBCXX_STRING
21#include <string>
22#endif
23#ifndef ERRORORTYPE_H
24#include <ErrorOrType.h>
25#endif
26
27typedef arb_unordered_map<std::string, std::string> StringMap;
28typedef ErrorOr<std::string> ErrorOrLabel;
29
30class TranslationReport;
31
32class LabelTranslator {
33    virtual ErrorOrLabel translate(const char *label) const = 0; // @@@ require two translate() methods: 1. for label->identifier, 2. for species->identifier
34
35public:
36    virtual ~LabelTranslator() {}
37
38    virtual GB_ERROR generate_species_identifiers(GBDATA *gb_main) const = 0;
39    GB_ERROR translate_unlinked_labels_in_tree(TreeNode *tree, TranslationReport& report) const;
40};
41
42class LabelForwarder : public LabelTranslator {
43    // does not translate anything, just forwards Labels as found.
44
45    ErrorOrLabel translate(const char *label) const OVERRIDE {
46        return ErrorOrLabel(NULp, label); // performs no translation
47    }
48
49public:
50    GB_ERROR generate_species_identifiers(GBDATA *) const OVERRIDE {
51        return NULp;
52    }
53};
54
55class ACI_LabelTranslator : public LabelTranslator {
56    std::string       species_aci;          // ACI that translates each species in DB into unique identifier
57    mutable StringMap identifier2shortname; // identifier is result of 'species_aci' (key=identifier, value=comma-separated list of shortname generated from)
58
59    ErrorOrLabel translate(const char *label) const OVERRIDE;
60
61public:
62    ACI_LabelTranslator(const char *species_aci_) :
63        species_aci(species_aci_)
64    {}
65    GB_ERROR generate_species_identifiers(GBDATA *gb_main) const OVERRIDE;
66};
67
68GB_ERROR TREE_translate_labels(GBDATA *gb_main, TreeNode *tree, const LabelTranslator& translator);
69
70#else
71#error LabelTranslator.h included twice
72#endif // LABELTRANSLATOR_H
73
74
Note: See TracBrowser for help on using the repository browser.