libdballe
5.18
|
00001 /* 00002 * db/repinfo - repinfo table management 00003 * 00004 * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * Author: Enrico Zini <enrico@enricozini.com> 00020 */ 00021 00022 #ifndef DBALLE_DB_REPINFO_H 00023 #define DBALLE_DB_REPINFO_H 00024 00031 #include <dballe/db/odbcworkarounds.h> 00032 #include <vector> 00033 #include <string> 00034 00035 namespace dballe { 00036 namespace db { 00037 struct Connection; 00038 00039 namespace repinfo { 00040 00042 struct Cache 00043 { 00045 DBALLE_SQL_C_UINT_TYPE id; 00046 00048 std::string memo; 00050 std::string desc; 00052 DBALLE_SQL_C_SINT_TYPE prio; 00054 std::string descriptor; 00056 DBALLE_SQL_C_UINT_TYPE tablea; 00057 00059 std::string new_memo; 00061 std::string new_desc; 00063 DBALLE_SQL_C_SINT_TYPE new_prio; 00065 std::string new_descriptor; 00067 DBALLE_SQL_C_UINT_TYPE new_tablea; 00068 00069 Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea); 00070 void make_new(); 00071 }; 00072 00074 struct Memoidx 00075 { 00077 std::string memo; 00079 int id; 00080 00081 bool operator<(const Memoidx& memo) const; 00082 }; 00083 00084 } 00085 00089 struct Repinfo 00090 { 00092 std::vector<repinfo::Cache> cache; 00093 00095 mutable std::vector<repinfo::Memoidx> memo_idx; 00096 00097 00102 Connection* conn; 00103 00104 Repinfo(Connection* conn); 00105 ~Repinfo(); 00106 00111 void invalidate_cache(); 00112 00129 void update(const char* deffile, int* added, int* deleted, int* updated); 00130 00140 int get_id(const char* memo) const; 00141 00150 bool has_id(unsigned id) const; 00151 00160 const repinfo::Cache* get_by_id(unsigned id) const; 00161 00170 const repinfo::Cache* get_by_memo(const char* memo) const; 00171 00172 protected: 00173 void read_cache(); 00174 void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea); 00175 void rebuild_memo_idx() const; 00176 int cache_find_by_memo(const char* memo) const; 00177 int cache_find_by_id(unsigned id) const; 00178 std::vector<repinfo::Cache> read_repinfo_file(const char* deffile); 00179 00180 private: 00181 // disallow copy 00182 Repinfo(const Repinfo&); 00183 Repinfo& operator=(const Repinfo&); 00184 }; 00185 00186 } // namespace db 00187 } // namespace dballe 00188 00189 /* vim:set ts=4 sw=4: */ 00190 #endif