/usr/include/dballe/db/v5/repinfo.h is in libdballe-dev 6.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | /*
* db/v5/repinfo - repinfo table management
*
* Copyright (C) 2005--2013 ARPA-SIM <urpsim@smr.arpa.emr.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Enrico Zini <enrico@enricozini.com>
*/
#ifndef DBALLE_DB_V5_REPINFO_H
#define DBALLE_DB_V5_REPINFO_H
/** @file
* @ingroup db
*
* Repinfo table management used by the db module.
*/
#include <dballe/db/odbcworkarounds.h>
#include <vector>
#include <string>
#include <map>
namespace dballe {
struct Record;
namespace db {
struct Connection;
namespace v5 {
namespace repinfo {
/** repinfo cache entry */
struct Cache
{
/** Report code */
DBALLE_SQL_C_UINT_TYPE id;
/** Report name */
std::string memo;
/** Report description */
std::string desc;
/** Report priority */
DBALLE_SQL_C_SINT_TYPE prio;
/** Report descriptor (currently unused) */
std::string descriptor;
/** Report A table value (currently unused) */
DBALLE_SQL_C_UINT_TYPE tablea;
/** New report name used when updating the repinfo table */
std::string new_memo;
/** New report description used when updating the repinfo table */
std::string new_desc;
/** New report priority used when updating the repinfo table */
DBALLE_SQL_C_SINT_TYPE new_prio;
/** New report descriptor used when updating the repinfo table */
std::string new_descriptor;
/** New report A table value used when updating the repinfo table */
DBALLE_SQL_C_UINT_TYPE new_tablea;
Cache(int id, const std::string& memo, const std::string& desc, int prio, const std::string& descriptor, int tablea);
void make_new();
};
/** reverse rep_memo -> rep_cod cache entry */
struct Memoidx
{
/** Report name */
std::string memo;
/** Report code */
int id;
bool operator<(const Memoidx& memo) const;
};
}
/**
* Fast cached access to the repinfo table
*/
struct Repinfo
{
/** Cache of table entries */
std::vector<repinfo::Cache> cache;
/** rep_memo -> rep_cod reverse index */
mutable std::vector<repinfo::Memoidx> memo_idx;
/**
* DB connection. The pointer is assumed always valid during the
* lifetime of the object
*/
Connection* conn;
Repinfo(Connection* conn);
virtual ~Repinfo();
/**
* Invalidate the repinfo cache. To be called if the repinfo table is modified
* externally; for example, when the table is recreated on database reset.
*/
void invalidate_cache();
/**
* Update the report type information in the database using the data from the
* given file.
*
* @param ri
* dba_db_repinfo used to update the database
* @param deffile
* Pathname of the file to use for the update. The NULL value is accepted
* and means to use the default configure repinfo.csv file.
* @retval added
* Number of entries that have been added during the update.
* @retval deleted
* Number of entries that have been deleted during the update.
* @retval updated
* Number of entries that have been updated during the update.
*/
void update(const char* deffile, int* added, int* deleted, int* updated);
/**
* Get the id of a repinfo entry given its name
*
* @param memo
* The name to query
* @return
* The resulting id. It will always be a valid one, because the functions
* fails if memo is not found.
*/
int get_id(const char* memo) const;
/**
* Get the id of a repinfo entry given its name.
*
* It creates a new entry if the memo is missing from the database.
*
* @param memo
* The name to query
* @return
* The resulting id.
*/
int obtain_id(const char* memo);
/**
* Check if the database contains the given rep_cod id
*
* @param id
* id to check
* @return
* true if id exists, else false.
*/
bool has_id(unsigned id) const;
/**
* Get a repinfo cache entry by id.
*
* @param id
* id to query
* @return
* The Cache structure found, or NULL if none was found.
*/
const repinfo::Cache* get_by_id(unsigned id) const;
/**
* Get a repinfo cache entry by name.
*
* @param memo
* name to query
* @return
* The Cache structure found, or NULL if none was found.
*/
const repinfo::Cache* get_by_memo(const char* memo) const;
/**
* Return a vector of IDs matching the priority constraints in the given record.
*/
std::vector<int> ids_by_prio(const Record& rec) const;
/**
* Get a mapping between rep_memo and their priorities
*/
std::map<std::string, int> get_priorities() const;
/**
* Dump the entire contents of the table to an output stream
*/
void dump(FILE* out);
protected:
/// Return how many time this ID is used in the database
virtual int id_use_count(unsigned id, const char* name);
void read_cache();
void cache_append(unsigned id, const char* memo, const char* desc, int prio, const char* descriptor, int tablea);
void rebuild_memo_idx() const;
int cache_find_by_memo(const char* memo) const;
int cache_find_by_id(unsigned id) const;
std::vector<repinfo::Cache> read_repinfo_file(const char* deffile);
/// Create an automatic entry for a missing memo, and insert it in the database
void insert_auto_entry(const char* memo);
private:
// disallow copy
Repinfo(const Repinfo&);
Repinfo& operator=(const Repinfo&);
};
} // namespace v5
} // namespace db
} // namespace dballe
/* vim:set ts=4 sw=4: */
#endif
|