libdballe  5.18
db/repinfo.h
Go to the documentation of this file.
1 /*
2  * db/repinfo - repinfo table management
3  *
4  * Copyright (C) 2005--2010 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_REPINFO_H
23 #define DBALLE_DB_REPINFO_H
24 
32 #include <vector>
33 #include <string>
34 
35 namespace dballe {
36 namespace db {
37 struct Connection;
38 
39 namespace repinfo {
40 
42 struct Cache
43 {
45  DBALLE_SQL_C_UINT_TYPE id;
46 
48  std::string memo;
50  std::string desc;
52  DBALLE_SQL_C_SINT_TYPE prio;
54  std::string descriptor;
56  DBALLE_SQL_C_UINT_TYPE tablea;
57 
59  std::string new_memo;
61  std::string new_desc;
63  DBALLE_SQL_C_SINT_TYPE new_prio;
65  std::string new_descriptor;
67  DBALLE_SQL_C_UINT_TYPE new_tablea;
68 
69  Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
70  void make_new();
71 };
72 
74 struct Memoidx
75 {
77  std::string memo;
79  int id;
80 
81  bool operator<(const Memoidx& memo) const;
82 };
83 
84 }
85 
89 struct Repinfo
90 {
92  std::vector<repinfo::Cache> cache;
93 
95  mutable std::vector<repinfo::Memoidx> memo_idx;
96 
97 
103 
105  ~Repinfo();
106 
111  void invalidate_cache();
112 
129  void update(const char* deffile, int* added, int* deleted, int* updated);
130 
140  int get_id(const char* memo) const;
141 
150  bool has_id(unsigned id) const;
151 
160  const repinfo::Cache* get_by_id(unsigned id) const;
161 
170  const repinfo::Cache* get_by_memo(const char* memo) const;
171 
172 protected:
173  void read_cache();
174  void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
175  void rebuild_memo_idx() const;
176  int cache_find_by_memo(const char* memo) const;
177  int cache_find_by_id(unsigned id) const;
178  std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
179 
180 private:
181  // disallow copy
182  Repinfo(const Repinfo&);
183  Repinfo& operator=(const Repinfo&);
184 };
185 
186 } // namespace db
187 } // namespace dballe
188 
189 /* vim:set ts=4 sw=4: */
190 #endif