libdballe 9.6
internals.h
1#ifndef DBALLE_DB_V7_INTERNALS_H
2#define DBALLE_DB_V7_INTERNALS_H
3
4#include <wreport/var.h>
5#include <vector>
6
7namespace dballe {
8namespace db {
9namespace v7 {
10
12struct AttributeList : public std::vector<std::pair<wreport::Varcode, const char*>>
13{
14 void add(wreport::Varcode code, const char* value)
15 {
16 push_back(std::make_pair(code, value));
17 }
18
20 const char* get(wreport::Varcode code) const
21 {
22 for (const_iterator i = begin(); i != end(); ++i)
23 if (i->first == code) return i->second;
24 return nullptr;
25 }
26
31 const char* pop(wreport::Varcode code)
32 {
33 const char* res = nullptr;
34 for (iterator i = begin(); i != end(); ++i)
35 {
36 if (i->first == code)
37 {
38 res = i->second;
39 i->second = nullptr;
40 break;
41 }
42 }
43 while (!empty() && back().second == nullptr)
44 pop_back();
45 return res;
46 }
47};
48
49}
50}
51}
52
53#endif
uint16_t Varcode
Store a list of attributes to be inserted/updated in the database.
Definition: internals.h:13
const char * pop(wreport::Varcode code)
Get a value by code, returns nullptr if not found, removes it from the AttributeList.
Definition: internals.h:31
const char * get(wreport::Varcode code) const
Get a value by code, returns nullptr if not found.
Definition: internals.h:20