Overpass API regression suite coverage (Nova Scotia) / template_db/types.h
template_db/types.h
40 of 104 instrumented lines run by the suite (38.5%) 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 modify6 * it under the terms of the GNU Affero General Public License as7 * published by the Free Software Foundation, either version 3 of the8 * 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 of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.17 */19#ifndef DE__OSM3S___TEMPLATE_DB__TYPES_H20#define DE__OSM3S___TEMPLATE_DB__TYPES_H22#include <fcntl.h>23#include <sys/stat.h>24#include <sys/types.h>25#include <unistd.h>27#include <cerrno>28#include <cstdlib>29#include <string>30#include <vector>32#ifdef NATIVE_LARGE_FILES33#define ftruncate64 ftruncate34#define lseek64 lseek35#define open64 open36#endif39typedef unsigned int uint;41typedef char int8;42typedef short int int16;43typedef int int32;44typedef long long int64;46typedef unsigned char uint8;47typedef unsigned short int uint16;48typedef unsigned int uint32;49typedef unsigned long long uint64;52const int S_666 = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;55struct File_Error56{57 File_Error(uint32 errno_, const std::string& filename_, const std::string& origin_)60 uint32 error_number;61 std::string filename;62 std::string origin;63};66struct File_Properties_Exception67{70 int32 id;71};74struct File_Blocks_Index_Base75{76 virtual bool empty() const = 0;79 virtual std::string get_data_file_name() const = 0;80 virtual uint64 get_block_size() const = 0;81 virtual uint32 get_compression_factor() const = 0;82 virtual uint32 get_compression_method() const = 0;83 virtual uint32 get_block_count() const = 0;84 virtual int32 get_file_format_version() const = 0;86 static const int USE_DEFAULT = -1;87 static const int NO_COMPRESSION = 0;88 static const int ZLIB_COMPRESSION = 1;89 static const int LZ4_COMPRESSION = 2;90 static const unsigned int IDX_HEADER_LENGTH = 8;91};94enum class Access_Mode95{ readonly, writeable, truncate };98struct File_Properties99{100 virtual const std::string& get_file_name_trunk() const = 0;101 virtual const std::string& get_index_suffix() const = 0;102 virtual const std::string& get_data_suffix() const = 0;103 virtual const std::string& get_id_suffix() const = 0;104 virtual const std::string& get_shadow_suffix() const = 0;105 virtual uint32 get_block_size() const = 0;106 virtual uint32 get_compression_factor() const = 0;107 virtual uint32 get_compression_method() const = 0;108 virtual uint32 get_map_block_size() const = 0;109 virtual uint32 get_map_compression_factor() const = 0;110 virtual uint32 get_map_compression_method() const = 0;111 virtual std::vector< bool > get_data_footprint(const std::string& db_dir) const = 0;112 virtual std::vector< bool > get_map_footprint(const std::string& db_dir) const = 0;113 virtual uint32 id_max_size_of() const = 0;115 // The returned object is of type File_Blocks_Index< .. >*116 // and goes into the ownership of the caller.117 virtual File_Blocks_Index_Base* new_data_index(118 Access_Mode access_mode, bool use_shadow, const std::string& db_dir, const std::string& file_name_extension)119 const = 0;120};123/** Simple RAII class to keep a file descriptor. */124class Raw_File125{126 Raw_File(const Raw_File&);127 Raw_File operator=(const Raw_File&);129 public:130 Raw_File(const std::string& name, int oflag, mode_t mode, const std::string& caller_id);133 uint64 size(const std::string& caller_id) const;134 void resize(uint64 size, const std::string& caller_id) const;135 void read(void* buf, uint64 size, const std::string& caller_id) const;136 void write(void* buf, uint64 size, const std::string& caller_id) const;137 void seek(uint64 pos, const std::string& caller_id) const;139 private:140 int fd_;141 std::string name;142};145/** Simple RAII class to keep a pointer to some memory on the heap. */146template < class T >147class Void_Pointer148{149 Void_Pointer(const Void_Pointer&);150 Void_Pointer& operator=(const Void_Pointer&);152public:1535708168 q explicit Void_Pointer(int block_size) { ptr = block_size > 0 ? (T*)malloc(block_size) : 0; }156 Void_Pointer(Void_Pointer&& rhs) : ptr(rhs.ptr)157 {158 rhs.ptr = nullptr;159 }160 Void_Pointer& operator=(Void_Pointer&& rhs)161 {162 if (ptr != rhs.ptr)163 {164 clear();165 ptr = rhs.ptr;166 rhs.ptr = nullptr;167 }168 return *this;169 }171 void clear()177 void resize(int block_size)185 T* ptr;186};190/** Simple RAII class to keep a pointer to some memory on the heap. Enforces 64 bit alignment. */191template < class T >192class Void64_Pointer193{194 Void64_Pointer(const Void64_Pointer&);195 Void64_Pointer& operator=(const Void64_Pointer&);197public:198 explicit Void64_Pointer(int block_size)204 Void64_Pointer(Void64_Pointer&& rhs) : ptr(rhs.ptr)205 {206 rhs.ptr = nullptr;207 }208 Void64_Pointer& operator=(Void64_Pointer&& rhs)209 {210 if (ptr != rhs.ptr)211 {212 clear();213 ptr = rhs.ptr;214 rhs.ptr = nullptr;215 }216 return *this;217 }219 void clear()225 void resize(int block_size)226 {227 clear();228 ptr = 0;229 if (block_size > 0)230 ptr = (T*)aligned_alloc(8, block_size);231 }232 void swap(Void64_Pointer& rhs)239 T* ptr;240};243inline bool file_exists(const std::string& filename)249/** Simple RAII class to keep a unix socket. */250class Unix_Socket251{252public:253 Unix_Socket(const std::string& socket_name = "", uint max_num_reading_processes = 0);254 void open(const std::string& socket_name);255 ~Unix_Socket();259private:260 int socket_descriptor;261 uint max_num_reading_processes;262};265//-----------------------------------------------------------------------------267inline Raw_File::Raw_File(const std::string& name_, int oflag, mode_t mode, const std::string& caller_id)281inline uint64 Raw_File::size(const std::string& caller_id) const292inline void Raw_File::resize(uint64 size, const std::string& caller_id) const299inline void Raw_File::read(void* buf, uint64 size, const std::string& caller_id) const306inline void Raw_File::write(void* buf, uint64 size, const std::string& caller_id) const313inline void Raw_File::seek(uint64 pos, const std::string& caller_id) const320//-----------------------------------------------------------------------------323template< typename Int >324int shift_log(Int val)336template< typename Iterator, typename Object >337void rearrange_block(const Iterator& begin, Iterator& it, Object to_move)354inline void zero_padding(uint8* from, uint32 bytes)361//-----------------------------------------------------------------------------364int& global_read_counter();366enum Signal_Status { absent = 0, received, processed };367Signal_Status& sigterm_status();368void sigterm(int);371void millisleep(uint32 milliseconds);374void copy_file(const std::string& source, const std::string& dest);375void force_link_file(const std::string& source, const std::string& dest);378#endif