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);
87 bool m_has_multiple_object_versions {
false};
103 explicit File(
const std::string& filename =
"",
const std::string& format =
"") :
105 m_filename(filename),
108 m_format_string(format) {
111 if (m_filename ==
"-") {
116 const std::string protocol = m_filename.substr(0, m_filename.find_first_of(
':'));
117 if (protocol ==
"http" || protocol ==
"https") {
121 if (format.empty()) {
122 detect_format_from_suffix(m_filename);
124 parse_format(format);
137 explicit File(
const char* buffer,
size_t size,
const std::string& format =
"") :
142 m_format_string(format) {
144 parse_format(format);
149 File& operator=(
const File&) =
default;
161 return m_buffer_size;
165 std::vector<std::string> options = detail::split(format,
',');
169 if (!options.empty() && options[0].find_first_of(
'=') == std::string::npos) {
170 detect_format_from_suffix(options[0]);
171 options.erase(options.begin());
174 for (
auto& option : options) {
175 const size_t pos = option.find_first_of(
'=');
176 if (pos == std::string::npos) {
179 std::string value = option.substr(pos+1);
185 if (
get(
"history") ==
"true") {
186 m_has_multiple_object_versions =
true;
187 }
else if (
get(
"history") ==
"false") {
188 m_has_multiple_object_versions =
false;
193 std::vector<std::string> suffixes = detail::split(name,
'.');
195 if (suffixes.empty())
return;
199 if (suffixes.back() ==
"gz") {
202 }
else if (suffixes.back() ==
"bz2") {
207 if (suffixes.empty())
return;
211 if (suffixes.back() ==
"pbf") {
214 }
else if (suffixes.back() ==
"xml") {
217 }
else if (suffixes.back() ==
"opl") {
220 }
else if (suffixes.back() ==
"json") {
223 }
else if (suffixes.back() ==
"o5m") {
226 }
else if (suffixes.back() ==
"o5c") {
228 m_has_multiple_object_versions =
true;
229 set(
"o5c_change_format",
true);
231 }
else if (suffixes.back() ==
"debug") {
236 if (suffixes.empty())
return;
238 if (suffixes.back() ==
"osm") {
241 }
else if (suffixes.back() ==
"osh") {
243 m_has_multiple_object_versions =
true;
245 }
else if (suffixes.back() ==
"osc") {
247 m_has_multiple_object_versions =
true;
248 set(
"xml_change_format",
true);
261 std::string msg =
"Could not detect file format";
262 if (!m_format_string.empty()) {
263 msg +=
" from format string '";
264 msg += m_format_string;
267 if (m_filename.empty()) {
268 msg +=
" for stdin/stdout";
270 msg +=
" for filename '";
281 return m_file_format;
285 m_file_format = format;
290 return m_file_compression;
294 m_file_compression = compression;
299 return m_has_multiple_object_versions;
303 m_has_multiple_object_versions = value;
308 if (filename ==
"-") {
311 m_filename = filename;
326 #endif // OSMIUM_IO_FILE_HPP File & set_has_multiple_object_versions(bool value) noexcept
Definition: file.hpp:302
void parse_format(const std::string &format)
Definition: file.hpp:164
File(const char *buffer, size_t size, const std::string &format="")
Definition: file.hpp:137
bool has_multiple_object_versions() const noexcept
Definition: file.hpp:298
File(const std::string &filename="", const std::string &format="")
Definition: file.hpp:103
void detect_format_from_suffix(const std::string &name)
Definition: file.hpp:192
size_t buffer_size() const noexcept
Definition: file.hpp:160
Definition: options.hpp:58
Namespace for everything in the Osmium library.
Definition: assembler.hpp:63
File & set_compression(file_compression compression) noexcept
Definition: file.hpp:293
std::string m_format_string
Definition: file.hpp:81
file_format format() const noexcept
Definition: file.hpp:280
file_compression
Definition: file_compression.hpp:42
File & set_format(file_format format) noexcept
Definition: file.hpp:284
file_format
Definition: file_format.hpp:42
const char * buffer() const noexcept
Definition: file.hpp:156
std::string m_filename
Definition: file.hpp:76
const File & check() const
Definition: file.hpp:259
file_compression compression() const noexcept
Definition: file.hpp:289
size_t m_buffer_size
Definition: file.hpp:79
File & filename(const std::string &filename)
Definition: file.hpp:307
const std::string & filename() const noexcept
Definition: file.hpp:316
const char * m_buffer
Definition: file.hpp:78