Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPropertyFilters.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkPropertyFilters.h"
18 #include <mitkPropertyFilter.h>
19 #include <utility>
20 
22 {
23 }
24 
26 {
27 }
28 
29 bool mitk::PropertyFilters::AddFilter(const PropertyFilter &filter, const std::string &className, bool overwrite)
30 {
31  if (!filter.IsEmpty())
32  {
33  std::pair<std::map<std::string, PropertyFilter>::iterator, bool> ret =
34  m_Filters.insert(std::make_pair(className, filter));
35 
36  if (!ret.second && overwrite)
37  {
38  ret.first->second = filter;
39  ret.second = true;
40  }
41 
42  return ret.second;
43  }
44 
45  return false;
46 }
47 
48 std::map<std::string, mitk::BaseProperty::Pointer> mitk::PropertyFilters::ApplyFilter(
49  const std::map<std::string, BaseProperty::Pointer> &propertyMap, const std::string &className) const
50 {
51  std::map<std::string, BaseProperty::Pointer> ret = propertyMap;
52  PropertyFilter filter = this->GetFilter("");
53 
54  if (!filter.IsEmpty())
55  ret = filter.Apply(ret);
56 
57  if (!className.empty())
58  {
59  filter = this->GetFilter(className);
60 
61  if (!filter.IsEmpty())
62  ret = filter.Apply(ret);
63  }
64 
65  return ret;
66 }
67 
68 mitk::PropertyFilter mitk::PropertyFilters::GetFilter(const std::string &className) const
69 {
70  std::map<std::string, PropertyFilter>::const_iterator iter = m_Filters.find(className);
71 
72  if (iter != m_Filters.end())
73  return iter->second;
74 
75  return PropertyFilter();
76 }
77 
78 bool mitk::PropertyFilters::HasFilter(const std::string &className) const
79 {
80  return m_Filters.find(className) != m_Filters.end();
81 }
82 
84 {
85  m_Filters.clear();
86 }
87 
88 void mitk::PropertyFilters::RemoveFilter(const std::string &className)
89 {
90  m_Filters.erase(className);
91 }
PropertyFilter GetFilter(const std::string &className) const override
Get the current property filter.
std::map< std::string, BaseProperty::Pointer > Apply(const std::map< std::string, BaseProperty::Pointer > &propertyMap) const
Apply the filter to a property list.
void RemoveAllFilters() override
Remove all property filters.
std::map< std::string, BaseProperty::Pointer > ApplyFilter(const std::map< std::string, BaseProperty::Pointer > &propertyMap, const std::string &className) const override
Apply property filter to property list.
bool HasFilter(const std::string &className) const override
Check if a specific data node class name has a property filter.
bool AddFilter(const PropertyFilter &filter, const std::string &className, bool overwrite) override
Add a property filter.
bool IsEmpty() const
Check if filter is empty.
void RemoveFilter(const std::string &className) override
Remove property filter for a specific data node class name.
Consists of blacklist and whitelist entries.