Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
config.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_UTIL_CONFIG_HPP
2#define OSMIUM_UTIL_CONFIG_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/util/misc.hpp>
37
38#include <cassert>
39#include <cstddef>
40#include <cstdlib>
41#include <cstring>
42#include <string>
43
44#ifdef _MSC_VER
45# define strcasecmp _stricmp
46#endif
47
48namespace osmium {
49
50 namespace detail {
51
52#ifndef OSMIUM_TEST_RUNNER
53 inline const char* getenv_wrapper(const char* var) noexcept {
54 return getenv(var);
55 }
56#endif
57
58 } // namespace detail
59
60 namespace config {
61
62 inline int get_pool_threads() noexcept {
63 const char* env = osmium::detail::getenv_wrapper("OSMIUM_POOL_THREADS");
64 if (env) {
65 return osmium::detail::str_to_int<int>(env);
66 }
67 return 0;
68 }
69
70 inline bool use_pool_threads_for_pbf_parsing() noexcept {
71 const char* env = osmium::detail::getenv_wrapper("OSMIUM_USE_POOL_THREADS_FOR_PBF_PARSING");
72 if (env) {
73 if (!strcasecmp(env, "off") ||
74 !strcasecmp(env, "false") ||
75 !strcasecmp(env, "no") ||
76 !strcasecmp(env, "0")) {
77 return false;
78 }
79 }
80 return true;
81 }
82
83 inline std::size_t get_max_queue_size(const char* queue_name, const std::size_t default_value) noexcept {
84 assert(queue_name);
85 std::string name{"OSMIUM_MAX_"};
86 name += queue_name;
87 name += "_QUEUE_SIZE";
88 const char* env = osmium::detail::getenv_wrapper(name.c_str());
89
90 std::size_t value = default_value;
91
92 if (env) {
93 const auto new_value = osmium::detail::str_to_int<std::size_t>(env);
94 if (new_value != 0) {
95 value = new_value;
96 }
97 }
98
99 if (value < 2) {
100 value = 2;
101 }
102
103 return value;
104 }
105
106 inline int8_t clean_page_cache_after_read() noexcept {
107 const char* env = osmium::detail::getenv_wrapper("OSMIUM_CLEAN_PAGE_CACHE_AFTER_READ");
108 if (env) {
109 if (!strcasecmp(env, "yes")) {
110 return 1;
111 }
112 if (!strcasecmp(env, "no")) {
113 return -1;
114 }
115 }
116 return 0;
117 }
118
119 } // namespace config
120
121} // namespace osmium
122
123#endif // OSMIUM_UTIL_CONFIG_HPP
Definition: attr.hpp:342
bool use_pool_threads_for_pbf_parsing() noexcept
Definition: config.hpp:70
int get_pool_threads() noexcept
Definition: config.hpp:62
std::size_t get_max_queue_size(const char *queue_name, const std::size_t default_value) noexcept
Definition: config.hpp:83
int8_t clean_page_cache_after_read() noexcept
Definition: config.hpp:106
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53