libdballe  6.8
db/v5/repinfo.h
Go to the documentation of this file.
1 /*
2  * db/v5/repinfo - repinfo table management
3  *
4  * Copyright (C) 2005--2013 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBALLE_DB_V5_REPINFO_H
23 #define DBALLE_DB_V5_REPINFO_H
24 
32 #include <vector>
33 #include <string>
34 #include <map>
35 
36 namespace dballe {
37 struct Record;
38 
39 namespace db {
40 struct Connection;
41 
42 namespace v5 {
43 
44 namespace repinfo {
45 
47 struct Cache
48 {
50  DBALLE_SQL_C_UINT_TYPE id;
51 
53  std::string memo;
55  std::string desc;
57  DBALLE_SQL_C_SINT_TYPE prio;
59  std::string descriptor;
61  DBALLE_SQL_C_UINT_TYPE tablea;
62 
64  std::string new_memo;
66  std::string new_desc;
68  DBALLE_SQL_C_SINT_TYPE new_prio;
70  std::string new_descriptor;
72  DBALLE_SQL_C_UINT_TYPE new_tablea;
73 
74  Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
75  void make_new();
76 };
77 
79 struct Memoidx
80 {
82  std::string memo;
84  int id;
85 
86  bool operator<(const Memoidx& memo) const;
87 };
88 
89 }
90 
94 struct Repinfo
95 {
97  std::vector<repinfo::Cache> cache;
98 
100  mutable std::vector<repinfo::Memoidx> memo_idx;
101 
102 
108 
109  Repinfo(Connection* conn);
110  virtual ~Repinfo();
111 
116  void invalidate_cache();
117 
134  void update(const char* deffile, int* added, int* deleted, int* updated);
135 
145  int get_id(const char* memo) const;
146 
157  int obtain_id(const char* memo);
158 
167  bool has_id(unsigned id) const;
168 
177  const repinfo::Cache* get_by_id(unsigned id) const;
178 
187  const repinfo::Cache* get_by_memo(const char* memo) const;
188 
192  std::vector<int> ids_by_prio(const Record& rec) const;
193 
197  std::map<std::string, int> get_priorities() const;
198 
202  void dump(FILE* out);
203 
204 protected:
206  virtual int id_use_count(unsigned id, const char* name);
207 
208  void read_cache();
209  void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
210  void rebuild_memo_idx() const;
211  int cache_find_by_memo(const char* memo) const;
212  int cache_find_by_id(unsigned id) const;
213  std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
215  void insert_auto_entry(const char* memo);
216 
217 private:
218  // disallow copy
219  Repinfo(const Repinfo&);
220  Repinfo& operator=(const Repinfo&);
221 };
222 
223 } // namespace v5
224 } // namespace db
225 } // namespace dballe
226 
227 /* vim:set ts=4 sw=4: */
228 #endif
int obtain_id(const char *memo)
Get the id of a repinfo entry given its name.
std::string desc
Report description.
Definition: db/v5/repinfo.h:55
std::vector< int > ids_by_prio(const Record &rec) const
Return a vector of IDs matching the priority constraints in the given record.
Connection * conn
DB connection.
Definition: db/v5/repinfo.h:107
Fast cached access to the repinfo table.
Definition: db/v5/repinfo.h:94
int id
Report code.
Definition: db/v5/repinfo.h:84
virtual int id_use_count(unsigned id, const char *name)
Return how many time this ID is used in the database.
Database connection.
Definition: internals.h:124
std::map< std::string, int > get_priorities() const
Get a mapping between rep_memo and their priorities.
The ODBC specification is imperfect with regards to integer sizes on 64bit platforms, and different ODBC drivers are currently interpreting it differently.
DBALLE_SQL_C_UINT_TYPE tablea
Report A table value (currently unused)
Definition: db/v5/repinfo.h:61
void dump(FILE *out)
Dump the entire contents of the table to an output stream.
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.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
DBALLE_SQL_C_UINT_TYPE new_tablea
New report A table value used when updating the repinfo table.
Definition: db/v5/repinfo.h:72
void invalidate_cache()
Invalidate the repinfo cache.
reverse rep_memo -> rep_cod cache entry
Definition: db/v5/repinfo.h:79
std::string new_descriptor
New report descriptor used when updating the repinfo table.
Definition: db/v5/repinfo.h:70
const repinfo::Cache * get_by_memo(const char *memo) const
Get a repinfo cache entry by name.
std::string new_desc
New report description used when updating the repinfo table.
Definition: db/v5/repinfo.h:66
const repinfo::Cache * get_by_id(unsigned id) const
Get a repinfo cache entry by id.
std::string memo
Report name.
Definition: db/v5/repinfo.h:53
std::vector< repinfo::Cache > cache
Cache of table entries.
Definition: db/v5/repinfo.h:97
std::vector< repinfo::Memoidx > memo_idx
rep_memo -> rep_cod reverse index
Definition: db/v5/repinfo.h:100
DBALLE_SQL_C_UINT_TYPE id
Report code.
Definition: db/v5/repinfo.h:50
DBALLE_SQL_C_SINT_TYPE prio
Report priority.
Definition: db/v5/repinfo.h:57
bool has_id(unsigned id) const
Check if the database contains the given rep_cod id.
void insert_auto_entry(const char *memo)
Create an automatic entry for a missing memo, and insert it in the database.
repinfo cache entry
Definition: db/v5/repinfo.h:47
std::string descriptor
Report descriptor (currently unused)
Definition: db/v5/repinfo.h:59
std::string new_memo
New report name used when updating the repinfo table.
Definition: db/v5/repinfo.h:64
std::string memo
Report name.
Definition: db/v5/repinfo.h:82
int get_id(const char *memo) const
Get the id of a repinfo entry given its name.
DBALLE_SQL_C_SINT_TYPE new_prio
New report priority used when updating the repinfo table.
Definition: db/v5/repinfo.h:68