/usr/include/dballe/db/v7/state.h is in libdballe-dev 7.21-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 | #ifndef DBALLE_DB_V7_STATE_H
#define DBALLE_DB_V7_STATE_H
#include <wreport/var.h>
#include <dballe/core/defs.h>
#include <map>
#include <unordered_set>
namespace dballe {
struct Record;
namespace db {
namespace v7 {
struct ItemState
{
// Database ID
int id;
// True if the item has just been inserted
bool is_new;
ItemState() {}
ItemState(int id, bool is_new) : id(id), is_new(is_new) {}
ItemState(const ItemState&) = default;
ItemState(ItemState&&) = default;
ItemState& operator=(const ItemState&) = default;
ItemState& operator=(ItemState&&) = default;
};
struct StationDesc
{
int rep;
Coords coords;
Ident ident;
int compare(const StationDesc&) const;
bool operator<(const StationDesc& o) const { return compare(o) < 0; }
/**
* Set coords and ident to rec.
*
* rep is not set, because StationDesc does not contain rep_memo
* information.
*/
void to_record(Record& rec) const;
};
struct StationState : public ItemState
{
using ItemState::ItemState;
};
typedef std::map<StationDesc, StationState> stations_t;
struct LevTrDesc
{
/// Vertical level or layer
Level level;
/// Time range
Trange trange;
LevTrDesc() = default;
LevTrDesc(const Level& level, const Trange& trange) : level(level), trange(trange) {}
LevTrDesc(const LevTrDesc&) = default;
LevTrDesc(LevTrDesc&&) = default;
LevTrDesc& operator=(const LevTrDesc&) = default;
LevTrDesc& operator=(LevTrDesc&&) = default;
int compare(const LevTrDesc&) const;
bool operator<(const LevTrDesc& o) const { return compare(o) < 0; }
};
struct LevTrState : public ItemState
{
using ItemState::ItemState;
};
typedef std::map<LevTrDesc, LevTrState> levtrs_t;
typedef std::map<int, levtrs_t::iterator> levtr_id_t;
struct StationValueDesc
{
stations_t::iterator station;
wreport::Varcode varcode;
StationValueDesc() {}
StationValueDesc(const StationValueDesc&) = default;
StationValueDesc(stations_t::iterator station, wreport::Varcode varcode)
: station(station), varcode(varcode) {}
StationValueDesc& operator=(const StationValueDesc&) = default;
int compare(const StationValueDesc&) const;
bool operator<(const StationValueDesc& o) const { return compare(o) < 0; }
};
struct StationValueState : public ItemState
{
using ItemState::ItemState;
};
typedef std::map<StationValueDesc, StationValueState> stationvalues_t;
struct ValueDesc
{
stations_t::iterator station;
int levtr;
/// Date and time at which the value was measured or forecast
Datetime datetime;
wreport::Varcode varcode;
ValueDesc() {}
ValueDesc(const ValueDesc&) = default;
ValueDesc(stations_t::iterator station, int levtr, const Datetime& datetime, wreport::Varcode varcode)
: station(station), levtr(levtr), datetime(datetime), varcode(varcode) {}
ValueDesc& operator=(const ValueDesc&) = default;
int compare(const ValueDesc&) const;
bool operator<(const ValueDesc& o) const { return compare(o) < 0; }
};
struct ValueState : public ItemState
{
using ItemState::ItemState;
};
typedef std::map<ValueDesc, ValueState> values_t;
/**
* Cache intermediate results during a database transaction, to avoid hitting
* the database multiple times when we already know values from previous
* operations.
*/
struct State
{
stations_t stations;
levtrs_t levtrs;
levtr_id_t levtr_ids;
stationvalues_t stationvalues;
values_t values;
std::unordered_set<int> stationvalues_new;
std::unordered_set<int> values_new;
stations_t::iterator add_station(const StationDesc& desc, const StationState& state);
levtrs_t::iterator add_levtr(const LevTrDesc& desc, const LevTrState& state);
stationvalues_t::iterator add_stationvalue(const StationValueDesc& desc, const StationValueState& state);
values_t::iterator add_value(const ValueDesc& desc, const ValueState& state);
/// Clear the state, removing all cached data
void clear();
};
}
}
}
#endif
|