19 #include <itksys/SystemTools.hxx> 23 class FindCaseInsensitive
26 FindCaseInsensitive(std::string value)
28 lcValue.resize(value.size());
29 std::transform(value.begin(), value.end(), lcValue.begin(), ::tolower);
32 bool operator()(std::string elem)
34 std::transform(elem.begin(), elem.end(), elem.begin(), ::tolower);
35 return elem == lcValue;
42 struct CustomMimeType::Impl
45 std::string m_Category;
46 std::vector<std::string> m_Extensions;
47 std::string m_Comment;
81 if (!d->m_Comment.empty())
83 if (!d->m_Extensions.empty())
85 return d->m_Extensions.front() +
" File";
93 std::string extension, filename;
94 return ParsePathForExtension(path, extension, filename);
99 std::string extension, filename;
100 ParsePathForExtension(path, extension, filename);
106 std::string extension, filename;
107 ParsePathForExtension(path, extension, filename);
111 bool CustomMimeType::ParsePathForExtension(
const std::string &path,
112 std::string &extension,
113 std::string &filename)
const 115 for (std::vector<std::string>::const_iterator iter = d->m_Extensions.begin(), iterEnd = d->m_Extensions.end();
119 if (!iter->empty() && path.size() >= iter->size())
121 FindCaseInsensitive cmp(*iter);
122 if (cmp(path.substr(path.size() - iter->size())))
124 extension =
"." + *iter;
125 std::string filenameWithExtension = itksys::SystemTools::GetFilenameName(path);
126 filename = filenameWithExtension.substr(0, filenameWithExtension.size() - extension.size());
138 d->m_Extensions.clear();
139 d->m_Extensions.push_back(extension);
144 if (std::find_if(d->m_Extensions.begin(), d->m_Extensions.end(), FindCaseInsensitive(extension)) ==
145 d->m_Extensions.end())
147 d->m_Extensions.push_back(extension);
std::string GetComment() const
Returns the Human readable comment of the MimeType, a string that describes its unique role...
std::string GetExtension(const std::string &path) const
Provides the first matching extension.
bool MatchesExtension(const std::string &path) const
Checks if the MimeType can handle the etension of the given path.
CustomMimeType & operator=(const CustomMimeType &other)
std::string GetName() const
Returns the unique name for the MimeType.
void SetExtension(const std::string &extension)
std::string GetCategory() const
Returns the human-readable Category of the mime-type. Allows grouping of similar mime-types (like Sur...
DataCollection - Class to facilitate loading/accessing structured data.
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
std::string GetName() const
std::string GetFilenameWithoutExtension(const std::string &path) const
Provides the filename minus the extension.
void SetComment(const std::string &comment)
std::vector< std::string > GetExtensions() const
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
std::vector< std::string > GetExtensions() const
Returns all extensions that this MimeType can handle.
std::string GetCategory() const
virtual CustomMimeType * Clone() const
void swap(CustomMimeType &l, CustomMimeType &r)
virtual ~CustomMimeType()
void AddExtension(const std::string &extension)
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
void SetCategory(const std::string &category)
void Swap(CustomMimeType &r)
std::string GetComment() const
void SetName(const std::string &name)