38 #ifndef OME_FILES_FORMATHANDLER_H 39 #define OME_FILES_FORMATHANDLER_H 47 #include <boost/filesystem/path.hpp> 48 #include <boost/format.hpp> 49 #include <boost/optional.hpp> 50 #include <boost/version.hpp> 100 isThisType(
const boost::filesystem::path& name,
101 bool open =
true)
const = 0;
127 const std::vector<boost::filesystem::path>&
136 const std::vector<boost::filesystem::path>&
148 setId(
const boost::filesystem::path&
id) = 0;
171 close(
bool fileOnly =
false) = 0;
185 const boost::filesystem::path& suffix)
189 boost::filesystem::path filename(name);
190 #if !defined(BOOST_VERSION) || BOOST_VERSION >= 105000 // Boost >= 1.50 191 boost::filesystem::path ext;
192 ext.replace_extension(suffix);
193 #else // Boost < 1.50 195 boost::filesystem::path ext(suffix);
196 std::string suffixString(ext.string());
197 if (!suffixString.empty() && suffixString[0] !=
'.')
198 ext = boost::filesystem::path(std::string(
".") + suffixString);
199 #endif // Boost version 203 boost::filesystem::path filename_ext = filename.extension();
204 boost::filesystem::path current_ext = ext.extension();
205 filename.replace_extension();
206 ext.replace_extension();
208 if (filename_ext.empty() && current_ext.empty())
210 else if (!filename_ext.empty() && !current_ext.empty() &&
211 filename_ext == current_ext)
232 const std::vector<boost::filesystem::path>& suffixes)
234 for (std::vector<boost::filesystem::path>::const_iterator si = suffixes.begin();
235 si != suffixes.end();
256 const std::vector<boost::filesystem::path>& suffixes,
257 const std::vector<boost::filesystem::path>& compression_suffixes)
262 for (std::vector<boost::filesystem::path>::const_iterator csi = compression_suffixes.begin();
263 csi != compression_suffixes.end();
266 for (std::vector<boost::filesystem::path>::const_iterator si = suffixes.begin();
267 si != suffixes.end();
270 #if !defined(BOOST_VERSION) || BOOST_VERSION >= 105000 // Boost >= 1.50 271 boost::filesystem::path suffix(*si);
272 suffix += boost::filesystem::path(
".");
274 #else // Boost < 1.50 275 boost::filesystem::path suffix(si->parent_path());
276 suffix /= boost::filesystem::path(si->filename().string() +
"." + csi->string());
277 #endif // Boost version 298 assertId(
const boost::optional<boost::filesystem::path>&
id,
303 throw std::logic_error(
"Current file should not be null; call setId() first");
305 else if (
id && !notNull)
307 boost::format fmt(
"Current file should be null, but is '%1%'; call close() first");
309 throw std::logic_error(fmt.str());
318 #endif // OME_FILES_FORMATHANDLER_H
Open Microscopy Environment C++.