Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkPropertyExtensions.h"
14 #include <algorithm>
15 #include <utility>
16 
18 {
19 }
20 
22 {
23 }
24 
25 bool mitk::PropertyExtensions::AddExtension(const std::string &propertyName,
27  const std::string &className,
28  bool overwrite)
29 {
30  if (propertyName.empty())
31  return false;
32 
33  ExtensionMap &extensions = m_Extensions[className];
34  std::pair<ExtensionMapIterator, bool> ret = extensions.insert(std::make_pair(propertyName, extension));
35 
36  if (!ret.second && overwrite)
37  {
38  ret.first->second = extension;
39  ret.second = true;
40  }
41 
42  return ret.second;
43 }
44 
46  const std::string &className)
47 {
48  if (!propertyName.empty())
49  {
50  ExtensionMap &extensions = m_Extensions[className];
51  ExtensionMapConstIterator iter = extensions.find(propertyName);
52 
53  if (iter != extensions.end())
54  return iter->second;
55  }
56 
57  return nullptr;
58 }
59 
60 bool mitk::PropertyExtensions::HasExtension(const std::string &propertyName, const std::string &className)
61 {
62  const ExtensionMap &extensions = m_Extensions[className];
63 
64  return !propertyName.empty() ? extensions.find(propertyName) != extensions.end() : false;
65 }
66 
67 void mitk::PropertyExtensions::RemoveAllExtensions(const std::string &className)
68 {
69  m_Extensions[className].clear();
70 }
71 
72 void mitk::PropertyExtensions::RemoveExtension(const std::string &propertyName, const std::string &className)
73 {
74  if (!propertyName.empty())
75  m_Extensions[className].erase(propertyName);
76 }
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.