This file is indexed.

/usr/include/dballe/core/values.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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#ifndef DBALLE_CORE_VALUES_H
#define DBALLE_CORE_VALUES_H

/** @file
 * Structures used as input to database insert functions.
 */

#include <dballe/core/defs.h>
#include <dballe/core/var.h>
#include <dballe/record.h>
#include <wreport/varinfo.h>
#include <vector>
#include <map>

namespace dballe {

/**
 * Information about a station
 */
struct Station
{
    /// rep_memo for this station
    std::string report;

    /**
     * Database ID of the station.
     *
     * It will be filled when the Station is inserted on the database.
     */
    int ana_id = MISSING_INT;

    /// Station coordinates
    Coords coords;

    /// Mobile station identifier
    Ident ident;

    Station() = default;
    Station(const dballe::Record& rec) { set_from_record(rec); }

    /// Reset the database ID
    void clear_ids() { ana_id = MISSING_INT; }

    /// Fill this Station with values from a dballe::Record
    void set_from_record(const Record& rec);

    bool operator==(const Station& o) const
    {
        return report == o.report && ana_id == o.ana_id && coords == o.coords && ident == o.ident;
    }

    /**
     * Print the Station to a FILE*.
     *
     * @param out  The output stream
     * @param end  String to print after the Station
     */
    void print(FILE* out, const char* end="\n") const;
};

/**
 * Information about a physical variable
 */
struct Sampling : public Station
{
    /// Date and time at which the value was measured or forecast
    Datetime datetime;

    /// Vertical level or layer
    Level level;

    /// Time range
    Trange trange;

    Sampling() = default;
    Sampling(const dballe::Record& rec) { set_from_record(rec); }
    void set_from_record(const Record& rec);
    Sampling& operator=(const Sampling&) = default;
    Sampling& operator=(const Station& st) {
        Station::operator=(st);
        return *this;
    }

    bool operator==(const Sampling& o) const
    {
        return Station::operator==(o) && datetime == o.datetime && level == o.level && trange == o.trange;
    }

    /**
     * Print the Sampling contents to a FILE*.
     *
     * @param out  The output stream
     * @param end  String to print after the Station
     */
    void print(FILE* out, const char* end="\n") const;
};

namespace values {

/**
 * A station or measured value
 */
struct Value
{
    /// Database ID of the value
    int data_id = MISSING_INT;

    /// wreport::Var representing the value
    wreport::Var* var = nullptr;

    Value(const Value& o) : data_id(o.data_id), var(o.var ? new wreport::Var(*o.var) : nullptr) {}
    Value(Value&& o) : data_id(o.data_id), var(o.var) { o.var = nullptr; }

    /// Construct from a wreport::Var
    Value(const wreport::Var& var) : var(new wreport::Var(var)) {}

    /// Construct from a wreport::Var, taking ownership of it
    Value(std::unique_ptr<wreport::Var>&& var) : var(var.release()) {}

    ~Value() { delete var; }

    Value& operator=(const Value& o)
    {
        if (this == &o) return *this;
        data_id = o.data_id;
        delete var;
        var = o.var ? new wreport::Var(*o.var) : nullptr;
        return *this;
    }
    Value& operator=(Value&& o)
    {
        if (this == &o) return *this;
        data_id = o.data_id;
        delete var;
        var = o.var;
        o.var = nullptr;
        return *this;
    }
    bool operator==(const Value& o) const
    {
        if (data_id != o.data_id) return false;
        if (var == o.var) return true;
        if (!var || !o.var) return false;
        return *var == *o.var;
    }

    /// Reset the database ID
    void clear_ids() { data_id = MISSING_INT; }

    /// Fill from a wreport::Var
    void set(const wreport::Var& v)
    {
        delete var;
        var = new wreport::Var(v);
    }

    /// Fill from a wreport::Var, taking ownership of it
    void set(std::unique_ptr<wreport::Var>&& v)
    {
        delete var;
        var = v.release();
    }

    /// Print the contents of this Value
    void print(FILE* out) const;
};

struct Encoder
{
    std::vector<uint8_t> buf;

    Encoder();
    void append_uint16(uint16_t val);
    void append_uint32(uint32_t val);
    void append_cstring(const char* val);
    void append(const wreport::Var& var);
    void append_attributes(const wreport::Var& var);
};

struct Decoder
{
    const uint8_t* buf;
    unsigned size;

    Decoder(const std::vector<uint8_t>& buf);
    uint16_t decode_uint16();
    uint32_t decode_uint32();
    const char* decode_cstring();
    std::unique_ptr<wreport::Var> decode_var();

    /**
     * Decode the attributes of var from a buffer
     */
    static void decode_attrs(const std::vector<uint8_t>& buf, wreport::Var& var);
};

}

/**
 * Collection of Value objects, indexed by wreport::Varcode
 */
struct Values : protected std::map<wreport::Varcode, values::Value>
{
    Values() = default;
    Values(const dballe::Record& rec) { set_from_record(rec); }

    typedef std::map<wreport::Varcode, values::Value>::const_iterator const_iterator;
    typedef std::map<wreport::Varcode, values::Value>::iterator iterator;
    const_iterator begin() const { return std::map<wreport::Varcode, values::Value>::begin(); }
    const_iterator end() const { return std::map<wreport::Varcode, values::Value>::end(); }
    iterator begin() { return std::map<wreport::Varcode, values::Value>::begin(); }
    iterator end() { return std::map<wreport::Varcode, values::Value>::end(); }
    size_t size() const { return std::map<wreport::Varcode, values::Value>::size(); }
    bool empty() const { return std::map<wreport::Varcode, values::Value>::empty(); }
    void clear() { return std::map<wreport::Varcode, values::Value>::clear(); }
    void erase(wreport::Varcode code) { std::map<wreport::Varcode, values::Value>::erase(code); }
    bool operator==(const Values& o) const;

    const values::Value& operator[](wreport::Varcode code) const;
    const values::Value& operator[](const char* code) const { return operator[](resolve_varcode(code)); }
    const values::Value& operator[](const std::string& code) const { return operator[](resolve_varcode(code)); }
    const values::Value* get(wreport::Varcode code) const;
    const values::Value* get(const char* code) const { return get(resolve_varcode(code)); }
    const values::Value* get(const std::string& code) const { return get(resolve_varcode(code)); }

    /// Set from a wreport::Var
    void set(const wreport::Var&);

    /// Set from a wreport::Var, taking ownership of it
    void set(std::unique_ptr<wreport::Var>&&);

    /// Set with all the variables from vals
    void set(const Values& vals);

    /// Set from a variable created by dballe::newvar()
    template<typename C, typename T> void set(C code, const T& val) { this->set(newvar(code, val)); }

    /// Set the database ID for the Value with this wreport::Varcode
    void add_data_id(wreport::Varcode code, int data_id);

    /// Set from the contents of a dballe::Record
    void set_from_record(const Record& rec);

    /// Reset all the database IDs
    void clear_ids()
    {
        for (auto& i : *this)
            i.second.clear_ids();
    }

    /**
     * Encode these values in a DB-All.e specific binary representation
     */
    std::vector<uint8_t> encode() const;

    /**
     * Encode the attributes of var in a DB-All.e specific binary representation
     */
    static std::vector<uint8_t> encode_attrs(const wreport::Var& var);

    /**
     * Decode variables from a DB-All.e specific binary representation
     */
    static void decode(const std::vector<uint8_t>& buf, std::function<void(std::unique_ptr<wreport::Var>)> dest);

    /// Print the contents of this Values
    void print(FILE* out) const;
};

/**
 * A set of station values.
 */
struct StationValues
{
    Station info;
    Values values;

    StationValues() = default;
    StationValues(const dballe::Record& rec) : info(rec), values(rec) {}

    /// Set from the contents of a dballe::Record
    void set_from_record(const Record& rec);

    bool operator==(const StationValues& o) const
    {
        return info == o.info && values == o.values;
    }

    /// Reset all the database IDs
    void clear_ids()
    {
        info.clear_ids();
        values.clear_ids();
    }

    /// Print the contents of this StationValues
    void print(FILE* out) const;
};

/**
 * A set of measured values
 */
struct DataValues
{
    Sampling info;
    Values values;

    DataValues() = default;
    DataValues(const dballe::Record& rec) : info(rec), values(rec) {}

    /// Set from the contents of a dballe::Record
    void set_from_record(const Record& rec);

    bool operator==(const DataValues& o) const
    {
        return info == o.info && values == o.values;
    }

    /// Reset all the database IDs
    void clear_ids()
    {
        info.clear_ids();
        values.clear_ids();
    }

    /// Print the contents of this StationValues
    void print(FILE* out) const;
};

}

#endif