libdballe  7.6
sql/internals.h
1 /*
2  * db/sql/internals - Support structures not part of any public API
3  *
4  * Copyright (C) 2015 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 #include <wreport/var.h>
22 #include <vector>
23 
24 namespace dballe {
25 namespace db {
26 namespace sql {
27 
29 struct AttributeList : public std::vector<std::pair<wreport::Varcode, const char*>>
30 {
31  void add(wreport::Varcode code, const char* value)
32  {
33  push_back(std::make_pair(code, value));
34  }
35 
37  const char* get(wreport::Varcode code) const
38  {
39  for (const_iterator i = begin(); i != end(); ++i)
40  if (i->first == code) return i->second;
41  return nullptr;
42  }
43 
48  const char* pop(wreport::Varcode code)
49  {
50  const char* res = nullptr;
51  for (iterator i = begin(); i != end(); ++i)
52  {
53  if (i->first == code)
54  {
55  res = i->second;
56  i->second = nullptr;
57  break;
58  }
59  }
60  while (!empty() && back().second == nullptr)
61  pop_back();
62  return res;
63  }
64 };
65 
66 }
67 }
68 }
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
Store a list of attributes to be inserted/updated in the database.
Definition: sql/internals.h:29
const char * pop(wreport::Varcode code)
Get a value by code, returns nullptr if not found, removes it from the AttributeList.
Definition: sql/internals.h:48