45 auto infoRange = m_InfoMap.equal_range(info->
GetName());
47 auto predicate = [mime](
const std::pair<const std::string, mitk::PropertyPersistenceInfo::ConstPointer> &x) {
48 return x.second.IsNotNull() && x.second->GetMimeTypeName() == mime;
51 auto finding = std::find_if(infoRange.first, infoRange.second, predicate);
53 bool exists = finding != infoRange.second;
56 if (!exists || overwrite)
58 if (exists && overwrite)
60 m_InfoMap.erase(finding);
63 m_InfoMap.insert(std::make_pair(info->
GetName(),
info));
69 mitk::PropertyPersistence::InfoMap mitk::PropertyPersistence::SelectInfo(
const InfoMap &infoMap,
70 const SelectFunctionType &selectFunction)
74 for (
auto pos : infoMap)
76 if (selectFunction(pos))
86 bool allowNameRegEx)
const
88 SelectFunctionType select = [propertyName](
const InfoMap::value_type &x) {
89 return x.second.IsNotNull() && !x.second->IsRegEx() && x.second->GetName() == propertyName;
92 InfoMap selection = SelectInfo(m_InfoMap, select);
95 for (
const auto &pos : selection)
97 result.push_back(pos.second->UnRegExByName(propertyName).GetPointer());
102 select = [propertyName](
const InfoMap::value_type &x) {
103 if (x.second.IsNotNull() && x.second->IsRegEx())
105 std::regex ex(x.second->GetName());
106 return std::regex_match(propertyName, ex);
111 selection = SelectInfo(m_InfoMap, select);
113 for (
const auto &pos : selection)
115 result.push_back(pos.second->UnRegExByName(propertyName).GetPointer());
122 bool infoPredicate(
const std::multimap<const std::string, mitk::PropertyPersistenceInfo::ConstPointer>::value_type &x,
123 const std::string &propertyName,
124 const std::string &mime)
126 return x.second.IsNotNull() && !x.second->IsRegEx() && x.second->GetName() == propertyName &&
127 x.second->GetMimeTypeName() == mime;
131 const std::multimap<const std::string, mitk::PropertyPersistenceInfo::ConstPointer>::value_type &x,
132 const std::string &propertyName,
133 const std::string &mime)
135 if (x.second.IsNotNull() && x.second->IsRegEx())
137 std::regex ex(x.second->GetName());
138 return std::regex_match(propertyName, ex) && x.second->GetMimeTypeName() == mime;
145 bool allowMimeWildCard,
146 bool allowNameRegEx)
const
148 SelectFunctionType select = [propertyName, mime](
const InfoMap::value_type &x) {
152 InfoMap selection = SelectInfo(m_InfoMap, select);
156 select = [propertyName, mime](
const InfoMap::value_type &x) {
return infoPredicateRegEx(x, propertyName, mime); };
158 InfoMap regExSelection = SelectInfo(m_InfoMap, select);
160 selection.insert(regExSelection.begin(), regExSelection.end());
163 if (selection.empty() && allowMimeWildCard)
165 select = [propertyName](
const InfoMap::value_type &x) {
169 selection = SelectInfo(m_InfoMap, select);
173 select = [propertyName](
const InfoMap::value_type &x) {
177 InfoMap regExSelection = SelectInfo(m_InfoMap, select);
179 selection.insert(regExSelection.begin(), regExSelection.end());
184 for (
const auto &pos : selection)
186 result.push_back(pos.second->UnRegExByName(propertyName).GetPointer());
193 bool allowKeyRegEx)
const
197 for (
const auto &pos : m_InfoMap)
199 if (pos.second.IsNotNull())
201 bool valid = pos.second->GetKey() == persistenceKey;
202 if (!valid && pos.second->IsRegEx() && allowKeyRegEx)
204 std::regex ex(pos.second->GetKey());
205 valid = std::regex_match(persistenceKey, ex);
210 result.push_back(pos.second->UnRegExByKey(persistenceKey).GetPointer());
220 return !this->GetInfo(propertyName, allowNameRegEx).empty();
231 if (!propertyName.empty())
233 m_InfoMap.erase(propertyName);
239 auto itr = m_InfoMap.begin();
240 while (itr != m_InfoMap.end())
242 if (itr->first == propertyName && itr->second.IsNotNull() && itr->second->GetMimeTypeName() == mime)
244 itr = m_InfoMap.erase(itr);
static MimeTypeNameType ANY_MIMETYPE_NAME()
void RemoveAllInfo() override
Remove all persistence info.
std::string GetName() const
std::string MimeTypeNameType
InfoResultType GetInfo(const std::string &propertyName, bool allowNameRegEx) const override
Get the persistence info for a specific base data property.
void RemoveInfo(const std::string &propertyName) override
Remove persistence info instances of a specific property name/regex.
MITKCORE_EXPORT IPropertyPersistence * CreateTestInstancePropertyPersistence()
IPropertyPersistence::InfoResultType InfoResultType
static void info(const char *fmt,...)
Property persistence info. This class is used to specify the way the persistance of a property of Bas...
bool infoPredicate(const std::multimap< const std::string, mitk::PropertyPersistenceInfo::ConstPointer >::value_type &x, const std::string &propertyName, const std::string &mime)
const MimeTypeNameType & GetMimeTypeName() const
bool AddInfo(const PropertyPersistenceInfo *info, bool overwrite) override
Add persistence info for a specific base data property. If there is already a property info instance ...
bool HasInfo(const std::string &propertyName, bool allowNameRegEx) const override
Check if a specific base data property has persistence info.
bool infoPredicateRegEx(const std::multimap< const std::string, mitk::PropertyPersistenceInfo::ConstPointer >::value_type &x, const std::string &propertyName, const std::string &mime)
Interface of property persistence service.
std::list< PropertyPersistenceInfo::ConstPointer > InfoResultType
InfoResultType GetInfoByKey(const std::string &persistenceKey, bool allowKeyRegEx) const override
Get the persistence info that will use the specified key.
PropertyPersistenceInfo::MimeTypeNameType MimeTypeNameType