Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkScalarListLookupTable.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 
14 #include <stdexcept>
15 #include <iostream>
17 {
18  return "ScalarListLookupTable";
19 }
20 
22 {
23  m_LookupTable[key] = value;
24 }
25 
27 {
28  LookupTableType::const_iterator it = m_LookupTable.find(key);
29  return (it != m_LookupTable.end());
30 }
31 
34 {
35  LookupTableType::const_iterator it = m_LookupTable.find(key);
36 
37  if (it != m_LookupTable.end())
38  {
39  return it->second;
40  }
41  else
42  {
43  throw std::range_error("id does not exist in the lookup table");
44  }
45 }
46 
49 {
50  return m_LookupTable;
51 }
52 
54 {
55  m_LookupTable = table;
56 };
57 
58 
60 {
61  return (m_LookupTable == lookupTable.m_LookupTable);
62 }
64 {
65  return !(m_LookupTable == lookupTable.m_LookupTable);
66 }
67 
70 {
71  if (this == &other)
72  {
73  return *this;
74  }
75  else
76  {
78  return *this;
79  }
80 }
81 
82 std::ostream& mitk::operator<<(std::ostream& stream, const ScalarListLookupTable& l)
83 {
84  typedef ScalarListLookupTable::LookupTableType::const_iterator MapIterType;
85  typedef ScalarListLookupTable::ValueType::const_iterator VectorIterType;
86  MapIterType mapStart = l.GetLookupTable().begin();
87  MapIterType mapEnd = l.GetLookupTable().end();
88  stream << "[";
89 
90  for (MapIterType i = mapStart; i != mapEnd; ++i)
91  {
92  if (i != mapStart)
93  {
94  stream << ", ";
95  }
96 
97  stream << i->first << " -> [";
98 
99  VectorIterType vectorStart = i->second.begin();
100  VectorIterType vectorEnd = i->second.end();
101 
102  for (VectorIterType j = vectorStart; j != vectorEnd; ++j)
103  {
104  if (j != vectorStart)
105  {
106  stream << ", ";
107  }
108 
109  stream << *j;
110  }
111 
112  stream << "]";
113  }
114 
115  return stream << "]";
116 };
bool operator!=(const ScalarListLookupTable &lookupTable) const
void SetTableValue(const KeyType &key, const ValueType &value)
Sets the list at the given map key to the given value.
virtual const char * GetNameOfClass() const
Data class for modelfit properties that store a map of lists (e.g. static parameters).
void SetLookupTable(const LookupTableType &table)
bool ValueExists(const KeyType &key) const
Returns true if the list with the given name exists.
const LookupTableType & GetLookupTable() const
Returns the map of lists.
const ValueType & GetTableValue(const KeyType &key) const
Returns the list with the given name.
virtual ScalarListLookupTable & operator=(const ScalarListLookupTable &other)
bool operator==(const ScalarListLookupTable &lookupTable) const
std::map< KeyType, ValueType > LookupTableType
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)