ARB
refentries.h
Go to the documentation of this file.
1 // ============================================================ //
2 // //
3 // File : refentries.h //
4 // Purpose : functions for fields containing references to //
5 // other item (as names) //
6 // //
7 // Coded by Ralf Westram (coder@reallysoft.de) in June 2011 //
8 // Institute of Microbiology (Technical University Munich) //
9 // http://www.arb-home.de/ //
10 // //
11 // ============================================================ //
12 
13 #ifndef REFENTRIES_H
14 #define REFENTRIES_H
15 
16 #ifndef ARB_ERROR_H
17 #include <arb_error.h>
18 #endif
19 #ifndef ARB_STRING_H
20 #include <arb_string.h>
21 #endif
22 #ifndef ARBDB_BASE_H
23 #include <arbdb_base.h>
24 #endif
25 #ifndef AW_BASE_HXX
26 #include <aw_base.hxx>
27 #endif
28 #ifndef _GLIBCXX_SET
29 #include <set>
30 #endif
31 #ifndef DBITEM_SET_H
32 #include <dbitem_set.h>
33 #endif
34 #ifndef ITEMS_H
35 #include <items.h>
36 #endif
37 
38 #define re_assert(cond) arb_assert(cond)
39 
40 
41 namespace RefEntries {
42 
43  typedef ARB_ERROR (*referred_item_handler)(GBDATA *gb_main, const DBItemSet& referred); // called with all referred items
44 
45  class RefSelector : virtual Noncopyable {
46  char *field; // name of field containing references
47  char *aci; // postprocess expression for field-content
48 
49  bool error_if_field_missing;
50  bool error_if_ref_unknown;
51  public:
52  RefSelector(const char *field_, const char *aci_, bool error_if_field_missing_, bool error_if_ref_unknown_)
53  : field(ARB_strdup(field_)),
54  aci(ARB_strdup(aci_)),
55  error_if_field_missing(error_if_field_missing_),
56  error_if_ref_unknown(error_if_ref_unknown_)
57  {}
59  free(aci);
60  free(field);
61  }
62 
63  const char *get_refs(ItemSelector& itemtype, GBDATA *gb_item) const;
64  char *filter_refs(const char *refs, GBDATA *gb_item) const;
65 
66  bool ignore_unknown_refs() const { return !error_if_ref_unknown; }
67  const char *get_field() const { return field; }
68  };
69 
71  GBDATA *gb_main;
72  ItemSelector& itemtype;
73 
74  public:
76  : gb_main(gb_main_),
77  itemtype(itemtype_)
78  {
79  re_assert(&itemtype);
80  }
81 
82  GBDATA *get_gbmain() const { return gb_main; }
83  ItemSelector& get_referring_item() const { return itemtype; }
84 
85 
88  };
89 
90  // --------------------------
91  // GUI related below
92 
93  typedef void (*client_area_builder)(AW_window *aw_reh); // callback to build client area in RefEntriesHandler window
94 
95  AW_window *create_refentries_window(AW_root *awr, ReferringEntriesHandler *reh, const char *window_id, const char *title, const char *help, client_area_builder build_client_area, const char *action, referred_item_handler action_cb);
96  void create_refentries_awars(AW_root *aw_root, AW_default aw_def);
97 };
98 
99 #else
100 #error refentries.h included twice
101 #endif // REFENTRIES_H
ARB_ERROR with_all_referred_items(GBDATA *gb_item, const RefSelector &refsel, referred_item_handler cb)
Definition: refentries.cxx:122
ItemSelector & get_referring_item() const
Definition: refentries.h:83
bool ignore_unknown_refs() const
Definition: refentries.h:66
static void help()
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
const char * title
Definition: readseq.c:22
#define cb(action)
ARB_ERROR(* referred_item_handler)(GBDATA *gb_main, const DBItemSet &referred)
Definition: refentries.h:43
RefSelector(const char *field_, const char *aci_, bool error_if_field_missing_, bool error_if_ref_unknown_)
Definition: refentries.h:52
std::set< GBDATA * > DBItemSet
Definition: dbitem_set.h:22
AW_window * create_refentries_window(AW_root *aw_root, ReferringEntriesHandler *reh, const char *window_id, const char *title, const char *help, client_area_builder build_client_area, const char *action, referred_item_handler action_cb)
Definition: refentries.cxx:253
ReferringEntriesHandler(GBDATA *gb_main_, ItemSelector &itemtype_)
Definition: refentries.h:75
void(* client_area_builder)(AW_window *aw_reh)
Definition: refentries.h:93
QUERY_RANGE
Definition: items.h:40
const char * get_field() const
Definition: refentries.h:67
#define re_assert(cond)
Definition: refentries.h:38
void create_refentries_awars(AW_root *aw_root, AW_default aw_def)
Definition: refentries.cxx:223
const char * get_refs(ItemSelector &itemtype, GBDATA *gb_item) const
Definition: refentries.cxx:42
GBDATA * gb_main
Definition: adname.cxx:33
char * filter_refs(const char *refs, GBDATA *gb_item) const
Definition: refentries.cxx:56