ARB
LabelTranslator.h
Go to the documentation of this file.
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 
27 typedef arb_unordered_map<std::string, std::string> StringMap;
29 
30 class TranslationReport;
31 
33  virtual ErrorOrLabel translate(const char *label) const = 0; // @@@ require two translate() methods: 1. for label->identifier, 2. for species->identifier
34 
35 public:
36  virtual ~LabelTranslator() {}
37 
40 };
41 
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 
49 public:
51  return NULp;
52  }
53 };
54 
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 
61 public:
62  ACI_LabelTranslator(const char *species_aci_) :
63  species_aci(species_aci_)
64  {}
66 };
67 
69 
70 #else
71 #error LabelTranslator.h included twice
72 #endif // LABELTRANSLATOR_H
73 
74 
const char * GB_ERROR
Definition: arb_core.h:25
return string(buffer, length)
GB_ERROR TREE_translate_labels(GBDATA *gb_main, TreeNode *tree, const LabelTranslator &translator)
ErrorOr< std::string > ErrorOrLabel
GB_ERROR generate_species_identifiers(GBDATA *) const OVERRIDE
virtual GB_ERROR generate_species_identifiers(GBDATA *gb_main) const =0
arb_unordered_map< std::string, std::string > StringMap
GB_ERROR generate_species_identifiers(GBDATA *gb_main) const OVERRIDE
virtual ~LabelTranslator()
#define OVERRIDE
Definition: cxxforward.h:112
ACI_LabelTranslator(const char *species_aci_)
#define NULp
Definition: cxxforward.h:116
GBDATA * gb_main
Definition: adname.cxx:32
GB_ERROR translate_unlinked_labels_in_tree(TreeNode *tree, TranslationReport &report) const
const char * label