41 auto infoRange = m_InfoMap.equal_range(info->
GetName());
43 auto predicate = [mime](
const std::pair<const std::string, mitk::PropertyPersistenceInfo::ConstPointer> &x) {
44 return x.second.IsNotNull() && x.second->GetMimeTypeName() == mime;
47 auto finding = std::find_if(infoRange.first, infoRange.second, predicate);
49 bool exists = finding != infoRange.second;
52 if (!exists || overwrite)
54 if (exists && overwrite)
56 m_InfoMap.erase(finding);
59 m_InfoMap.insert(std::make_pair(info->
GetName(),
info));
65 mitk::PropertyPersistence::InfoMap mitk::PropertyPersistence::SelectInfo(
const InfoMap &infoMap,
66 const SelectFunctionType &selectFunction)
70 for (
auto pos : infoMap)
72 if (selectFunction(pos))
82 bool allowNameRegEx)
const 84 SelectFunctionType select = [propertyName](
const InfoMap::value_type &x) {
85 return x.second.IsNotNull() && !x.second->IsRegEx() && x.second->GetName() == propertyName;
88 InfoMap selection = SelectInfo(m_InfoMap, select);
91 for (
const auto &pos : selection)
93 result.push_back(pos.second->UnRegExByName(propertyName).GetPointer());
98 select = [propertyName](
const InfoMap::value_type &x) {
99 if (x.second.IsNotNull() && x.second->IsRegEx())
101 std::regex ex(x.second->GetName());
102 return std::regex_match(propertyName, ex);
107 selection = SelectInfo(m_InfoMap, select);
109 for (
const auto &pos : selection)
111 result.push_back(pos.second->UnRegExByName(propertyName).GetPointer());
118 bool infoPredicate(
const std::multimap<const std::string, mitk::PropertyPersistenceInfo::ConstPointer>::value_type &x,
119 const std::string &propertyName,
120 const std::string &mime)
122 return x.second.IsNotNull() && !x.second->IsRegEx() && x.second->GetName() == propertyName &&
123 x.second->GetMimeTypeName() == mime;
127 const std::multimap<const std::string, mitk::PropertyPersistenceInfo::ConstPointer>::value_type &x,
128 const std::string &propertyName,
129 const std::string &mime)
131 if (x.second.IsNotNull() && x.second->IsRegEx())
133 std::regex ex(x.second->GetName());
134 return std::regex_match(propertyName, ex) && x.second->GetMimeTypeName() == mime;
141 bool allowMimeWildCard,
142 bool allowNameRegEx)
const 144 SelectFunctionType select = [propertyName, mime](
const InfoMap::value_type &x) {
148 InfoMap selection = SelectInfo(m_InfoMap, select);
152 select = [propertyName, mime](
const InfoMap::value_type &x) {
return infoPredicateRegEx(x, propertyName, mime); };
154 InfoMap regExSelection = SelectInfo(m_InfoMap, select);
156 selection.insert(regExSelection.begin(), regExSelection.end());
159 if (selection.empty() && allowMimeWildCard)
161 select = [propertyName](
const InfoMap::value_type &x) {
165 selection = SelectInfo(m_InfoMap, select);
169 select = [propertyName](
const InfoMap::value_type &x) {
173 InfoMap regExSelection = SelectInfo(m_InfoMap, select);
175 selection.insert(regExSelection.begin(), regExSelection.end());
180 for (
const auto &pos : selection)
182 result.push_back(pos.second->UnRegExByName(propertyName).GetPointer());
189 bool allowKeyRegEx)
const 193 for (
const auto &pos : m_InfoMap)
195 if (pos.second.IsNotNull())
197 bool valid = pos.second->GetKey() == persistenceKey;
198 if (!valid && pos.second->IsRegEx() && allowKeyRegEx)
200 std::regex ex(pos.second->GetKey());
201 valid = std::regex_match(persistenceKey, ex);
206 result.push_back(pos.second->UnRegExByKey(persistenceKey).GetPointer());
216 return !this->
GetInfo(propertyName, allowNameRegEx).empty();
226 if (!propertyName.empty())
228 m_InfoMap.erase(propertyName);
234 auto itr = m_InfoMap.begin();
235 while (itr != m_InfoMap.end())
237 if (itr->first == propertyName && itr->second.IsNotNull() && itr->second->GetMimeTypeName() == mime)
239 itr = m_InfoMap.erase(itr);
static MimeTypeNameType ANY_MIMETYPE_NAME()
void RemoveAllInfo() override
Remove all persistence info.
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.
~PropertyPersistence() override
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...
const MimeTypeNameType & GetMimeTypeName() const
bool infoPredicate(const std::multimap< const std::string, mitk::PropertyPersistenceInfo::ConstPointer >::value_type &x, const std::string &propertyName, const std::string &mime)
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.
std::string GetName() const
PropertyPersistenceInfo::MimeTypeNameType MimeTypeNameType