libdballe  7.19
v7/repinfo.h
Go to the documentation of this file.
1 #ifndef DBALLE_DB_V7_REPINFO_H
2 #define DBALLE_DB_V7_REPINFO_H
3 
10 #include <dballe/sql/fwd.h>
11 #include <memory>
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 namespace dballe {
17 struct Record;
18 
19 namespace core {
20 struct Query;
21 }
22 
23 namespace db {
24 namespace v7 {
25 
26 namespace repinfo {
27 
29 struct Cache
30 {
32  unsigned id;
33 
35  std::string memo;
37  std::string desc;
39  int prio;
41  std::string descriptor;
43  unsigned tablea;
44 
46  std::string new_memo;
48  std::string new_desc;
50  int new_prio;
52  std::string new_descriptor;
54  unsigned new_tablea;
55 
56  Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
57  void make_new();
58 
59  void dump(FILE* out) const;
60 };
61 
63 struct Memoidx
64 {
66  std::string memo;
68  int id;
69 
70  bool operator<(const Memoidx& memo) const;
71 };
72 
73 }
74 
76 struct Repinfo
77 {
79 
81  virtual ~Repinfo() {}
82 
83  //static std::unique_ptr<Repinfo> create(Connection& conn);
84 
89  void to_record(int id, Record& rec);
90 
92  const char* get_rep_memo(int id);
93 
95  int get_id(const char* rep_memo);
96 
98  int get_priority(int id);
99 
114  void update(const char* deffile, int* added, int* deleted, int* updated);
115 
119  std::map<std::string, int> get_priorities();
120 
124  std::vector<int> ids_by_prio(const core::Query& rec);
125 
136  int obtain_id(const char* memo);
137 
139  virtual void dump(FILE* out) = 0;
140 
141 protected:
143  std::vector<repinfo::Cache> cache;
144 
146  mutable std::vector<repinfo::Memoidx> memo_idx;
147 
149  const repinfo::Cache* get_by_id(unsigned id) const;
150 
152  const repinfo::Cache* get_by_memo(const char* memo) const;
153 
155  int cache_find_by_id(unsigned id) const;
156 
158  int cache_find_by_memo(const char* memo) const;
159 
161  void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
162 
164  void rebuild_memo_idx() const;
165 
167  std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
168 
170  virtual int id_use_count(unsigned id, const char* name) = 0;
171 
173  virtual void delete_entry(unsigned id) = 0;
174 
176  virtual void update_entry(const repinfo::Cache& entry) = 0;
177 
179  virtual void insert_entry(const repinfo::Cache& entry) = 0;
180 
182  virtual void read_cache() = 0;
183 
185  virtual void insert_auto_entry(const char* memo) = 0;
186 };
187 
188 }
189 }
190 }
191 #endif
int new_prio
New report priority used when updating the repinfo table.
Definition: v7/repinfo.h:50
std::string memo
Report name.
Definition: v7/repinfo.h:35
unsigned id
Report code.
Definition: v7/repinfo.h:32
Fast cached access to the repinfo table.
Definition: v7/repinfo.h:76
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
Standard dballe::Query implementation.
Definition: core/query.h:29
Forward declarations for public dballe/sql names.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
std::vector< repinfo::Cache > cache
Cache of table entries.
Definition: v7/repinfo.h:143
int prio
Report priority.
Definition: v7/repinfo.h:39
Definition: sql.h:59
int id
Report code.
Definition: v7/repinfo.h:68
unsigned new_tablea
New report A table value used when updating the repinfo table.
Definition: v7/repinfo.h:54
std::string memo
Report name.
Definition: v7/repinfo.h:66
std::string new_desc
New report description used when updating the repinfo table.
Definition: v7/repinfo.h:48
std::vector< repinfo::Memoidx > memo_idx
rep_memo -> rep_cod reverse index
Definition: v7/repinfo.h:146
std::string new_descriptor
New report descriptor used when updating the repinfo table.
Definition: v7/repinfo.h:52
std::string descriptor
Report descriptor (currently unused)
Definition: v7/repinfo.h:41
unsigned tablea
Report A table value (currently unused)
Definition: v7/repinfo.h:43
std::string new_memo
New report name used when updating the repinfo table.
Definition: v7/repinfo.h:46
repinfo cache entry
Definition: v7/repinfo.h:29
std::string desc
Report description.
Definition: v7/repinfo.h:37
reverse rep_memo -> rep_cod cache entry
Definition: v7/repinfo.h:63