1 #ifndef OSMIUM_IO_FILE_HPP
2 #define OSMIUM_IO_FILE_HPP
55 inline std::vector<std::string> split(
const std::string& in,
const char delim) {
56 std::vector<std::string> result;
57 std::stringstream ss(in);
59 while (std::getline(ss, item, delim)) {
60 result.push_back(item);
114 if (protocol ==
"http" || protocol ==
"https") {
152 std::vector<std::string> options = detail::split(
format,
',');
156 if (!options.empty() && options[0].find_first_of(
'=') == std::string::npos) {
158 options.erase(options.begin());
161 for (
auto& option : options) {
162 const size_t pos = option.find_first_of(
'=');
163 if (pos == std::string::npos) {
166 std::string value{option.substr(pos + 1)};
172 if (get(
"history") ==
"true") {
174 }
else if (get(
"history") ==
"false") {
180 std::vector<std::string> suffixes = detail::split(name,
'.');
182 if (suffixes.empty()) {
188 if (suffixes.back() ==
"gz") {
191 }
else if (suffixes.back() ==
"bz2") {
196 if (suffixes.empty()) {
202 if (suffixes.back() ==
"pbf") {
205 }
else if (suffixes.back() ==
"xml") {
208 }
else if (suffixes.back() ==
"opl") {
211 }
else if (suffixes.back() ==
"json") {
214 }
else if (suffixes.back() ==
"o5m") {
217 }
else if (suffixes.back() ==
"o5c") {
220 set(
"o5c_change_format",
true);
222 }
else if (suffixes.back() ==
"debug") {
225 }
else if (suffixes.back() ==
"blackhole") {
230 if (suffixes.empty()) {
234 if (suffixes.back() ==
"osm") {
239 }
else if (suffixes.back() ==
"osh") {
245 }
else if (suffixes.back() ==
"osc") {
250 set(
"xml_change_format",
true);
263 std::string msg{
"Could not detect file format"};
265 msg +=
" from format string '";
270 msg +=
" for stdin/stdout";
272 msg +=
" for filename '";
File & set_compression(file_compression compression) noexcept
Definition: file.hpp:295
File & filename(const std::string &filename)
Definition: file.hpp:309
bool m_has_multiple_object_versions
Definition: file.hpp:87
std::string m_filename
Definition: file.hpp:76
size_t buffer_size() const noexcept
Definition: file.hpp:147
File(std::string filename="", std::string format="")
Definition: file.hpp:103
bool has_multiple_object_versions() const noexcept
Definition: file.hpp:300
const File & check() const
Definition: file.hpp:261
size_t m_buffer_size
Definition: file.hpp:79
file_compression m_file_compression
Definition: file.hpp:85
file_format m_file_format
Definition: file.hpp:83
const char * buffer() const noexcept
Definition: file.hpp:143
std::string m_format_string
Definition: file.hpp:81
File & set_format(file_format format) noexcept
Definition: file.hpp:286
File(const char *buffer, size_t size, const std::string &format="")
Definition: file.hpp:134
void detect_format_from_suffix(const std::string &name)
Definition: file.hpp:179
File & set_has_multiple_object_versions(bool value) noexcept
Definition: file.hpp:304
const char * m_buffer
Definition: file.hpp:78
void parse_format(const std::string &format)
Definition: file.hpp:151
const std::string & filename() const noexcept
Definition: file.hpp:318
file_compression compression() const noexcept
Definition: file.hpp:291
file_format format() const noexcept
Definition: file.hpp:282
Definition: options.hpp:58
file_format
Definition: file_format.hpp:42
file_compression
Definition: file_compression.hpp:42
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
Definition: location.hpp:551