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;
159 close(
bool fileOnly =
false) = 0;
173 const boost::filesystem::path& suffix)
177 boost::filesystem::path filename(name);
178 #if !defined(BOOST_VERSION) || BOOST_VERSION >= 105000 // Boost >= 1.50
179 boost::filesystem::path ext;
180 ext.replace_extension(suffix);
181 #else // Boost < 1.50
183 boost::filesystem::path ext(suffix);
184 std::string suffixString(ext.string());
185 if (!suffixString.empty() && suffixString[0] !=
'.')
186 ext = boost::filesystem::path(std::string(
".") + suffixString);
187 #endif // Boost version
191 boost::filesystem::path filename_ext = filename.extension();
192 boost::filesystem::path current_ext = ext.extension();
193 filename.replace_extension();
194 ext.replace_extension();
196 if (filename_ext.empty() && current_ext.empty())
198 else if (!filename_ext.empty() && !current_ext.empty() &&
199 filename_ext == current_ext)
220 const std::vector<boost::filesystem::path>& suffixes)
222 for (std::vector<boost::filesystem::path>::const_iterator si = suffixes.begin();
223 si != suffixes.end();
244 const std::vector<boost::filesystem::path>& suffixes,
245 const std::vector<boost::filesystem::path>& compression_suffixes)
250 for (std::vector<boost::filesystem::path>::const_iterator csi = compression_suffixes.begin();
251 csi != compression_suffixes.end();
254 for (std::vector<boost::filesystem::path>::const_iterator si = suffixes.begin();
255 si != suffixes.end();
258 #if !defined(BOOST_VERSION) || BOOST_VERSION >= 105000 // Boost >= 1.50
259 boost::filesystem::path suffix(*si);
260 suffix += boost::filesystem::path(
".");
262 #else // Boost < 1.50
263 boost::filesystem::path suffix(si->parent_path());
264 suffix /= boost::filesystem::path(si->filename().string() +
"." + csi->string());
265 #endif // Boost version
286 assertId(
const boost::optional<boost::filesystem::path>&
id,
291 throw std::logic_error(
"Current file should not be null; call setId() first");
293 else if (
id && !notNull)
295 boost::format fmt(
"Current file should be null, but is '%1%'; call close() first");
297 throw std::logic_error(fmt.str());
306 #endif // OME_BIOFORMATS_FORMATHANDLER_H
Boost.Filesystem compatibility.
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40