Libosmium  2.16.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 
6 This file is part of Osmium (https://osmcode.org/libosmium).
7 
8 Copyright 2013-2021 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS 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 
48 namespace 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  } // namespace config
107 
108 } // namespace osmium
109 
110 #endif // OSMIUM_UTIL_CONFIG_HPP
detail
Definition: attr.hpp:342
osmium::config::get_max_queue_size
std::size_t get_max_queue_size(const char *queue_name, const std::size_t default_value) noexcept
Definition: config.hpp:83
misc.hpp
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
osmium::config::use_pool_threads_for_pbf_parsing
bool use_pool_threads_for_pbf_parsing() noexcept
Definition: config.hpp:70
osmium::config::get_pool_threads
int get_pool_threads() noexcept
Definition: config.hpp:62