38 #ifndef OME_BIOFORMATS_FORMATHANDLER_H
39 #define OME_BIOFORMATS_FORMATHANDLER_H
47 #include <boost/format.hpp>
48 #include <boost/optional.hpp>
49 #include <boost/version.hpp>
101 isThisType(
const boost::filesystem::path& name,
102 bool open =
true)
const = 0;
128 const std::vector<boost::filesystem::path>&
137 const std::vector<boost::filesystem::path>&
149 setId(
const boost::filesystem::path&
id) = 0;
172 close(
bool fileOnly =
false) = 0;
186 const boost::filesystem::path& suffix)
190 boost::filesystem::path filename(name);
191 #if !defined(BOOST_VERSION) || BOOST_VERSION >= 105000 // Boost >= 1.50
192 boost::filesystem::path ext;
193 ext.replace_extension(suffix);
194 #else // Boost < 1.50
196 boost::filesystem::path ext(suffix);
197 std::string suffixString(ext.string());
198 if (!suffixString.empty() && suffixString[0] !=
'.')
199 ext = boost::filesystem::path(std::string(
".") + suffixString);
200 #endif // Boost version
204 boost::filesystem::path filename_ext = filename.extension();
205 boost::filesystem::path current_ext = ext.extension();
206 filename.replace_extension();
207 ext.replace_extension();
209 if (filename_ext.empty() && current_ext.empty())
211 else if (!filename_ext.empty() && !current_ext.empty() &&
212 filename_ext == current_ext)
233 const std::vector<boost::filesystem::path>& suffixes)
235 for (std::vector<boost::filesystem::path>::const_iterator si = suffixes.begin();
236 si != suffixes.end();
257 const std::vector<boost::filesystem::path>& suffixes,
258 const std::vector<boost::filesystem::path>& compression_suffixes)
263 for (std::vector<boost::filesystem::path>::const_iterator csi = compression_suffixes.begin();
264 csi != compression_suffixes.end();
267 for (std::vector<boost::filesystem::path>::const_iterator si = suffixes.begin();
268 si != suffixes.end();
271 #if !defined(BOOST_VERSION) || BOOST_VERSION >= 105000 // Boost >= 1.50
272 boost::filesystem::path suffix(*si);
273 suffix += boost::filesystem::path(
".");
275 #else // Boost < 1.50
276 boost::filesystem::path suffix(si->parent_path());
277 suffix /= boost::filesystem::path(si->filename().string() +
"." + csi->string());
278 #endif // Boost version
299 assertId(
const boost::optional<boost::filesystem::path>&
id,
304 throw std::logic_error(
"Current file should not be null; call setId() first");
306 else if (
id && !notNull)
308 boost::format fmt(
"Current file should be null, but is '%1%'; call close() first");
310 throw std::logic_error(fmt.str());
319 #endif // OME_BIOFORMATS_FORMATHANDLER_H
Boost.Filesystem compatibility.
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40