libdballe  9.11
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 <dballe/core/fwd.h>
12 #include <memory>
13 #include <map>
14 #include <string>
15 #include <vector>
16 
17 namespace dballe {
18 namespace db {
19 namespace v7 {
20 
21 namespace repinfo {
22 
24 struct Cache
25 {
27  unsigned id;
28 
30  std::string memo;
32  std::string desc;
34  int prio;
36  std::string descriptor;
38  unsigned tablea;
39 
41  std::string new_memo;
43  std::string new_desc;
45  int new_prio;
47  std::string new_descriptor;
49  unsigned new_tablea;
50 
51  Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
52  void make_new();
53 
54  void dump(FILE* out) const;
55 };
56 
58 struct Memoidx
59 {
61  std::string memo;
63  int id;
64 
65  bool operator<(const Memoidx& memo) const;
66 };
67 
68 }
69 
71 struct Repinfo
72 {
74 
76  virtual ~Repinfo() {}
77 
78  //static std::unique_ptr<Repinfo> create(Connection& conn);
79 
81  // FIXME: use std::string?
82  const char* get_rep_memo(int id);
83 
85  int get_id(const char* rep_memo);
86 
88  int get_priority(const std::string& report);
89 
104  void update(const char* deffile, int* added, int* deleted, int* updated);
105 
109  std::map<std::string, int> get_priorities();
110 
114  std::vector<int> ids_by_prio(const core::Query& rec);
115 
126  int obtain_id(const char* memo);
127 
129  virtual void dump(FILE* out) = 0;
130 
135  virtual void read_cache() = 0;
136 
137 protected:
139  std::vector<repinfo::Cache> cache;
140 
142  mutable std::vector<repinfo::Memoidx> memo_idx;
143 
145  const repinfo::Cache* get_by_id(unsigned id) const;
146 
148  const repinfo::Cache* get_by_memo(const char* memo) const;
149 
151  int cache_find_by_id(unsigned id) const;
152 
154  int cache_find_by_memo(const char* memo) const;
155 
157  void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
158 
160  void rebuild_memo_idx() const;
161 
163  std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
164 
166  virtual int id_use_count(unsigned id, const char* name) = 0;
167 
169  virtual void delete_entry(unsigned id) = 0;
170 
172  virtual void update_entry(const repinfo::Cache& entry) = 0;
173 
175  virtual void insert_entry(const repinfo::Cache& entry) = 0;
176 
178  virtual void insert_auto_entry(const char* memo) = 0;
179 };
180 
181 }
182 }
183 }
184 #endif
int get_priority(const std::string &report)
Get the priority for a given ID; returns INT_MAX if id is not valid.
int cache_find_by_memo(const char *memo) const
Lookup a cache index by report name. Returns -1 if not found.
Forward declarations for public dballe/sql names.
const repinfo::Cache * get_by_memo(const char *memo) const
Get a Cache entry by report name.
virtual void dump(FILE *out)=0
Dump the entire contents of the database to an output stream.
int new_prio
New report priority used when updating the repinfo table.
Definition: repinfo.h:45
virtual int id_use_count(unsigned id, const char *name)=0
Return how many time this ID is used in the database.
std::string memo
Report name.
Definition: repinfo.h:30
unsigned id
Report code.
Definition: repinfo.h:27
std::vector< repinfo::Cache > read_repinfo_file(const char *deffile)
Read cache entries from a repinfo file on disk.
void rebuild_memo_idx() const
Rebuild the memo_idx cache.
virtual void update_entry(const repinfo::Cache &entry)=0
Update an entry using the new_* fields of entry.
Fast cached access to the repinfo table.
Definition: repinfo.h:71
Standard dballe::Query implementation.
Definition: core/query.h:34
Definition: cmdline.h:18
int cache_find_by_id(unsigned id) const
Lookup a cache index by database ID. Returns -1 if not found.
std::vector< repinfo::Cache > cache
Cache of table entries.
Definition: repinfo.h:139
int obtain_id(const char *memo)
Get the id of a repinfo entry given its name.
int prio
Report priority.
Definition: repinfo.h:34
Definition: sql.h:52
const repinfo::Cache * get_by_id(unsigned id) const
Get a Cache entry by database ID.
void update(const char *deffile, int *added, int *deleted, int *updated)
Update the report type information in the database using the data from the given file.
int id
Report code.
Definition: repinfo.h:63
unsigned new_tablea
New report A table value used when updating the repinfo table.
Definition: repinfo.h:49
std::string memo
Report name.
Definition: repinfo.h:61
void cache_append(unsigned id, const char *memo, const char *desc, int prio, const char *descriptor, int tablea)
Append an entry to the cache.
std::map< std::string, int > get_priorities()
Get a mapping between rep_memo and their priorities.
std::string new_desc
New report description used when updating the repinfo table.
Definition: repinfo.h:43
std::vector< repinfo::Memoidx > memo_idx
rep_memo -> rep_cod reverse index
Definition: repinfo.h:142
std::string new_descriptor
New report descriptor used when updating the repinfo table.
Definition: repinfo.h:47
std::string descriptor
Report descriptor (currently unused)
Definition: repinfo.h:36
unsigned tablea
Report A table value (currently unused)
Definition: repinfo.h:38
virtual void insert_entry(const repinfo::Cache &entry)=0
Insert an entry using the new_* fields of entry.
const char * get_rep_memo(int id)
Get the rep_memo for a given ID; throws if id is not valud.
int get_id(const char *rep_memo)
Get the ID for a given rep_memo; returns -1 if rep_memo is not valid.
std::string new_memo
New report name used when updating the repinfo table.
Definition: repinfo.h:41
repinfo cache entry
Definition: repinfo.h:24
virtual void read_cache()=0
Reread the repinfo cache from the database FIXME: needed when rolling back a transaction, won&#39;t be needed anymore when repinfo is moved to Transaction instead of db.
virtual void insert_auto_entry(const char *memo)=0
Create an automatic entry for a missing memo, and insert it in the database.
std::string desc
Report description.
Definition: repinfo.h:32
virtual void delete_entry(unsigned id)=0
Delete a repinfo entry.
reverse rep_memo -> rep_cod cache entry
Definition: repinfo.h:58
std::vector< int > ids_by_prio(const core::Query &rec)
Return a vector of IDs matching the priority constraints in the given record.