libdballe  7.7
sql/repinfo.h
Go to the documentation of this file.
1 #ifndef DBALLE_DB_SQL_REPINFO_H
2 #define DBALLE_DB_SQL_REPINFO_H
3 
10 #include <memory>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 namespace dballe {
16 struct Record;
17 
18 namespace core {
19 struct Query;
20 }
21 
22 namespace db {
23 struct Connection;
24 
25 namespace sql {
26 
27 namespace repinfo {
28 
30 struct Cache
31 {
33  unsigned id;
34 
36  std::string memo;
38  std::string desc;
40  int prio;
42  std::string descriptor;
44  unsigned tablea;
45 
47  std::string new_memo;
49  std::string new_desc;
51  int new_prio;
53  std::string new_descriptor;
55  unsigned new_tablea;
56 
57  Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
58  void make_new();
59 
60  void dump(FILE* out) const;
61 };
62 
64 struct Memoidx
65 {
67  std::string memo;
69  int id;
70 
71  bool operator<(const Memoidx& memo) const;
72 };
73 
74 }
75 
77 struct Repinfo
78 {
79  Connection& conn;
80 
81  Repinfo(Connection& conn);
82  virtual ~Repinfo() {}
83 
84  //static std::unique_ptr<Repinfo> create(Connection& conn);
85 
90  void to_record(int id, Record& rec);
91 
93  const char* get_rep_memo(int id);
94 
96  int get_id(const char* rep_memo);
97 
99  int get_priority(int id);
100 
117  void update(const char* deffile, int* added, int* deleted, int* updated);
118 
122  std::map<std::string, int> get_priorities();
123 
127  std::vector<int> ids_by_prio(const core::Query& rec);
128 
139  int obtain_id(const char* memo);
140 
142  virtual void dump(FILE* out) = 0;
143 
144 protected:
146  std::vector<repinfo::Cache> cache;
147 
149  mutable std::vector<repinfo::Memoidx> memo_idx;
150 
152  const repinfo::Cache* get_by_id(unsigned id) const;
153 
155  const repinfo::Cache* get_by_memo(const char* memo) const;
156 
158  int cache_find_by_id(unsigned id) const;
159 
161  int cache_find_by_memo(const char* memo) const;
162 
164  void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
165 
167  void rebuild_memo_idx() const;
168 
170  std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
171 
173  virtual int id_use_count(unsigned id, const char* name) = 0;
174 
176  virtual void delete_entry(unsigned id) = 0;
177 
179  virtual void update_entry(const repinfo::Cache& entry) = 0;
180 
182  virtual void insert_entry(const repinfo::Cache& entry) = 0;
183 
185  virtual void read_cache() = 0;
186 
188  virtual void insert_auto_entry(const char* memo) = 0;
189 };
190 
191 }
192 }
193 }
194 #endif
unsigned id
Report code.
Definition: sql/repinfo.h:33
std::string new_desc
New report description used when updating the repinfo table.
Definition: sql/repinfo.h:49
std::string new_descriptor
New report descriptor used when updating the repinfo table.
Definition: sql/repinfo.h:53
std::vector< repinfo::Cache > cache
Cache of table entries.
Definition: sql/repinfo.h:146
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
int prio
Report priority.
Definition: sql/repinfo.h:40
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
std::string desc
Report description.
Definition: sql/repinfo.h:38
repinfo cache entry
Definition: sql/repinfo.h:30
std::string memo
Report name.
Definition: sql/repinfo.h:36
std::vector< repinfo::Memoidx > memo_idx
rep_memo -> rep_cod reverse index
Definition: sql/repinfo.h:149
Fast cached access to the repinfo table.
Definition: sql/repinfo.h:77
int new_prio
New report priority used when updating the repinfo table.
Definition: sql/repinfo.h:51
unsigned new_tablea
New report A table value used when updating the repinfo table.
Definition: sql/repinfo.h:55
int id
Report code.
Definition: sql/repinfo.h:69
unsigned tablea
Report A table value (currently unused)
Definition: sql/repinfo.h:44
reverse rep_memo -> rep_cod cache entry
Definition: sql/repinfo.h:64
Definition: sql.h:69
std::string descriptor
Report descriptor (currently unused)
Definition: sql/repinfo.h:42
std::string new_memo
New report name used when updating the repinfo table.
Definition: sql/repinfo.h:47
std::string memo
Report name.
Definition: sql/repinfo.h:67