Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPropertyExtensions.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 "mitkPropertyExtensions.h"
18 #include <algorithm>
19 #include <utility>
20 
22 {
23 }
24 
26 {
27 }
28 
29 bool mitk::PropertyExtensions::AddExtension(const std::string &propertyName,
31  const std::string &className,
32  bool overwrite)
33 {
34  if (propertyName.empty())
35  return false;
36 
37  ExtensionMap &extensions = m_Extensions[className];
38  std::pair<ExtensionMapIterator, bool> ret = extensions.insert(std::make_pair(propertyName, extension));
39 
40  if (!ret.second && overwrite)
41  {
42  ret.first->second = extension;
43  ret.second = true;
44  }
45 
46  return ret.second;
47 }
48 
50  const std::string &className)
51 {
52  if (!propertyName.empty())
53  {
54  ExtensionMap &extensions = m_Extensions[className];
55  ExtensionMapConstIterator iter = extensions.find(propertyName);
56 
57  if (iter != extensions.end())
58  return iter->second;
59  }
60 
61  return NULL;
62 }
63 
64 bool mitk::PropertyExtensions::HasExtension(const std::string &propertyName, const std::string &className)
65 {
66  const ExtensionMap &extensions = m_Extensions[className];
67 
68  return !propertyName.empty() ? extensions.find(propertyName) != extensions.end() : false;
69 }
70 
71 void mitk::PropertyExtensions::RemoveAllExtensions(const std::string &className)
72 {
73  m_Extensions[className].clear();
74 }
75 
76 void mitk::PropertyExtensions::RemoveExtension(const std::string &propertyName, const std::string &className)
77 {
78  if (!propertyName.empty())
79  m_Extensions[className].erase(propertyName);
80 }
PropertyExtension::Pointer GetExtension(const std::string &propertyName, const std::string &className) override
Get the extension of a specific property.
void RemoveExtension(const std::string &propertyName, const std::string &className) override
Remove extension of a specific property.
bool HasExtension(const std::string &propertyName, const std::string &className) override
Check if a specific property has an extension.
void RemoveAllExtensions(const std::string &className) override
Remove all property extensions.
bool AddExtension(const std::string &propertyName, PropertyExtension::Pointer extension, const std::string &className, bool overwrite) override
Add an extension to a specific property.