Overpass API regression suite coverage (Saxony) / overpass_api/osm-backend/area_updater.h

overpass_api/osm-backend/area_updater.h

0 of 41 instrumented lines run by the suite (0.0%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API 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 Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___OVERPASS_API__OSM_BACKEND__AREA_UPDATER_H
20#define DE__OSM3S___OVERPASS_API__OSM_BACKEND__AREA_UPDATER_H
22#include <algorithm>
23#include <iostream>
24#include <map>
25#include <set>
26#include <vector>
28#include "../../template_db/block_backend.h"
29#include "../../template_db/random_file.h"
30#include "../../template_db/transaction.h"
31#include "../core/datatypes.h"
32#include "../core/settings.h"
35struct Area_Pair_Comparator_By_Id {
36 bool operator() (const std::pair< Area_Location, Uint31_Index >& a,
37 const std::pair< Area_Location, Uint31_Index >& b)
380 {
390 return (a.first.id < b.first.id);
400 }
41};
43struct Area_Pair_Equal_Id {
44 bool operator() (const std::pair< Area_Location, Uint31_Index >& a,
45 const std::pair< Area_Location, Uint31_Index >& b)
460 {
470 return (a.first.id == b.first.id);
480 }
49};
51struct Area_Updater : public Area_Usage_Listener
53 Area_Updater(Transaction& transaction_);
54 Area_Updater(std::string db_dir_);
560 ~Area_Updater() { flush(); }
580 void set_id_deleted(uint32 id) { ids_to_modify.insert(id); }
59 void set_area
60 (uint32 id, const Uint31_Index& index,
61 const std::vector< std::pair< std::string, std::string > >& tags,
62 const std::set< uint32 >& used_indices);
63 void set_area(const Uint31_Index& index, const Area_Location& area);
64 void add_blocks(const std::map< Uint31_Index, std::vector< Area_Block > >& area_blocks_);
65 void commit();
66 virtual void flush();
68private:
69 Transaction* transaction;
70 bool external_transaction;
71 std::string db_dir;
72 std::map< Uint31_Index, std::vector< Area_Block > > area_blocks;
73 unsigned int total_area_blocks_count;
74 std::set< Area::Id_Type > ids_to_modify;
75 std::vector< std::pair< Area_Location, Uint31_Index > > areas_to_insert;
76 static Area_Pair_Comparator_By_Id area_comparator_by_id;
77 static Area_Pair_Equal_Id area_equal_id;
79 void update();
80 void update_area_ids
81 (std::map< Uint31_Index, std::set< Area_Skeleton > >& locations_to_delete,
82 std::map< Uint31_Index, std::set< Area_Block > >& blocks_to_delete);
83 void update_members
84 (const std::map< Uint31_Index, std::set< Area_Skeleton > >& locations_to_delete,
85 const std::map< Uint31_Index, std::set< Area_Block > >& blocks_to_delete);
86 void prepare_delete_tags
87 (std::vector< Tag_Entry< uint32 > >& tags_to_delete,
88 const std::map< Uint31_Index, std::set< Area_Skeleton > >& to_delete);
89 void update_area_tags_local
90 (const std::vector< Tag_Entry< uint32 > >& tags_to_delete);
91 void update_area_tags_global
92 (const std::vector< Tag_Entry< uint32 > >& tags_to_delete);
93};
95/** Implementation (inline functions): --------------------------------------*/
97inline void Area_Updater::commit()
980{
990 if (total_area_blocks_count > 512*1024)
1000 update();
1010}
103inline void Area_Updater::flush()
1040{
1050 try
1060 {
1070 if ((!ids_to_modify.empty()) ||
1080 (!areas_to_insert.empty()) ||
1090 (!area_blocks.empty()))
1100 update();
1110 }
1120 catch(File_Error e)
1130 {
1140 std::cerr<<"File_Error: "<<strerror(e.error_number)<<' '<<e.error_number<<' '<<e.filename<<' '<<e.origin<<'\n';
1150 }
1160}
118inline void Area_Updater::set_area
119 (uint32 id, const Uint31_Index& index,
120 const std::vector< std::pair< std::string, std::string > >& tags,
121 const std::set< uint32 >& used_indices)
1220{
1230 ids_to_modify.insert(id);
1250 std::vector< uint32 > indices;
1260 for (std::set< uint32 >::const_iterator it(used_indices.begin());
1270 it != used_indices.end(); ++it)
1280 indices.push_back(*it);
1300 Area_Location area(id, indices);
1310 area.tags = tags;
1320 areas_to_insert.push_back(std::make_pair(area, index));
1330}
135inline void Area_Updater::set_area(const Uint31_Index& index, const Area_Location& area)
1360{
1370 ids_to_modify.insert(area.id);
1380 areas_to_insert.push_back(std::make_pair(area, index));
1390}
141#endif