libdballe 9.13
repinfo.h
Go to the documentation of this file.
1#ifndef DBALLE_DB_V7_REPINFO_H
2#define DBALLE_DB_V7_REPINFO_H
3
9
10#include <dballe/core/fwd.h>
11#include <dballe/sql/fwd.h>
12#include <map>
13#include <memory>
14#include <string>
15#include <vector>
16
17namespace dballe {
18namespace db {
19namespace v7 {
20
21namespace repinfo {
22
24struct 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;
47 std::string new_descriptor;
49 unsigned new_tablea;
50
51 Cache(int id, const std::string& memo, const std::string& desc, int prio,
52 const std::string& descriptor, int tablea);
53 void make_new();
54
55 void dump(FILE* out) const;
56};
57
59struct Memoidx
60{
62 std::string memo;
64 int id;
65
66 bool operator<(const Memoidx& memo) const;
67};
68
69} // namespace repinfo
70
72struct Repinfo
73{
75
76 Repinfo(dballe::sql::Connection& conn);
77 virtual ~Repinfo() {}
78
79 // static std::unique_ptr<Repinfo> create(Connection& conn);
80
82 // FIXME: use std::string?
83 const char* get_rep_memo(int id);
84
86 int get_id(const char* rep_memo);
87
89 int get_priority(const std::string& report);
90
105 void update(const char* deffile, int* added, int* deleted, int* updated);
106
110 std::map<std::string, int> get_priorities();
111
116 std::vector<int> ids_by_prio(const core::Query& rec);
117
128 int obtain_id(const char* memo);
129
131 virtual void dump(FILE* out) = 0;
132
137 virtual void read_cache() = 0;
138
139protected:
141 std::vector<repinfo::Cache> cache;
142
144 mutable std::vector<repinfo::Memoidx> memo_idx;
145
147 const repinfo::Cache* get_by_id(unsigned id) const;
148
150 const repinfo::Cache* get_by_memo(const char* memo) const;
151
153 int cache_find_by_id(unsigned id) const;
154
156 int cache_find_by_memo(const char* memo) const;
157
159 void cache_append(unsigned id, const char* memo, const char* desc, int prio,
160 const char* descriptor, int tablea);
161
163 void rebuild_memo_idx() const;
164
166 std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
167
169 virtual int id_use_count(unsigned id, const char* name) = 0;
170
172 virtual void delete_entry(unsigned id) = 0;
173
175 virtual void update_entry(const repinfo::Cache& entry) = 0;
176
178 virtual void insert_entry(const repinfo::Cache& entry) = 0;
179
182 virtual void insert_auto_entry(const char* memo) = 0;
183};
184
185} // namespace v7
186} // namespace db
187} // namespace dballe
188#endif
Definition sql.h:54
Forward declarations for public dballe/sql names.
Standard dballe::Query implementation.
Definition core/query.h:36
virtual void insert_auto_entry(const char *memo)=0
Create an automatic entry for a missing memo, and insert it in the database.
int get_priority(const std::string &report)
Get the priority for a given ID; returns INT_MAX if id is not valid.
virtual void insert_entry(const repinfo::Cache &entry)=0
Insert an entry using the new_* fields of entry.
virtual void update_entry(const repinfo::Cache &entry)=0
Update an entry using the new_* fields of entry.
std::vector< repinfo::Cache > cache
Cache of table entries.
Definition repinfo.h:141
virtual void read_cache()=0
Reread the repinfo cache from the database FIXME: needed when rolling back a transaction,...
int obtain_id(const char *memo)
Get the id of a repinfo entry given its name.
int cache_find_by_memo(const char *memo) const
Lookup a cache index by report name. Returns -1 if not found.
int cache_find_by_id(unsigned id) const
Lookup a cache index by database ID. Returns -1 if not found.
void cache_append(unsigned id, const char *memo, const char *desc, int prio, const char *descriptor, int tablea)
Append an entry to the cache.
const repinfo::Cache * get_by_id(unsigned id) const
Get a Cache entry by database ID.
virtual int id_use_count(unsigned id, const char *name)=0
Return how many time this ID is used in the database.
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.
std::vector< repinfo::Cache > read_repinfo_file(const char *deffile)
Read cache entries from a repinfo file on disk.
virtual void dump(FILE *out)=0
Dump the entire contents of the database to an output stream.
int get_id(const char *rep_memo)
Get the ID for a given rep_memo; returns -1 if rep_memo is not valid.
virtual void delete_entry(unsigned id)=0
Delete a repinfo entry.
std::vector< int > ids_by_prio(const core::Query &rec)
Return a vector of IDs matching the priority constraints in the given record.
const repinfo::Cache * get_by_memo(const char *memo) const
Get a Cache entry by report name.
std::vector< repinfo::Memoidx > memo_idx
rep_memo -> rep_cod reverse index
Definition repinfo.h:144
std::map< std::string, int > get_priorities()
Get a mapping between rep_memo and their priorities.
const char * get_rep_memo(int id)
Get the rep_memo for a given ID; throws if id is not valud.
void rebuild_memo_idx() const
Rebuild the memo_idx cache.
repinfo cache entry
Definition repinfo.h:25
std::string descriptor
Report descriptor (currently unused)
Definition repinfo.h:36
unsigned tablea
Report A table value (currently unused)
Definition repinfo.h:38
unsigned new_tablea
New report A table value used when updating the repinfo table.
Definition repinfo.h:49
std::string new_desc
New report description used when updating the repinfo table.
Definition repinfo.h:43
int new_prio
New report priority used when updating the repinfo table.
Definition repinfo.h:45
std::string new_descriptor
New report descriptor used when updating the repinfo table.
Definition repinfo.h:47
int prio
Report priority.
Definition repinfo.h:34
std::string new_memo
New report name used when updating the repinfo table.
Definition repinfo.h:41
std::string desc
Report description.
Definition repinfo.h:32
unsigned id
Report code.
Definition repinfo.h:27
std::string memo
Report name.
Definition repinfo.h:30
reverse rep_memo -> rep_cod cache entry
Definition repinfo.h:60
int id
Report code.
Definition repinfo.h:64
std::string memo
Report name.
Definition repinfo.h:62