MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlPropertyManager.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2010, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_PROPERTY_MANAGER_H
14#define ML_PROPERTY_MANAGER_H
15
16
18
19#include "mlVesselGraphSystem.h"
20
21#include "mlIntrusivePtrBase.h"
22#include "mlPropertyValue.h"
23
24#include <set>
25#include <vector>
26#include <boost/intrusive_ptr.hpp>
27
29
32
33class VESSELGRAPH_EXPORT PropertyManager : public Base, public IntrusivePtrBase<PropertyManager>
34{
35public:
37 typedef boost::intrusive_ptr<type> Pointer;
38 typedef boost::intrusive_ptr<const type> ConstPointer;
39 typedef std::map<std::string, PropertyValue> PropertyMap;
40
45 ~PropertyManager() override;
46
49
51 bool operator==(const PropertyManager& other) const;
52
55
58 size_t createProperty(const std::string& name, const PropertyValue& defaultValue);
59
62 {
63 return _defaultValues[propertyIndex];
64 }
65 const PropertyValue& getPropertyDefault(const std::string& propertyName) const
66 {
67 return _defaultValues[getPropertyIndex(propertyName)];
68 }
69
72
74 size_t getPropertyIndex(const std::string& propertyName) const;
75
77 std::optional<size_t> getOptionalPropertyIndex(const std::string& propertyName) const;
78
80 const std::string& getPropertyName(size_t index) const
81 {
82 return _names[index];
83 }
84
86 const std::vector<std::string>& getPropertyNames() const
87 {
88 return _names;
89 }
90
92 template <typename T> std::vector<std::string> getPropertyNames() const;
93
95 bool hasProperty(const std::string& name) const
96 {
97 return std::find(_names.begin(), _names.end(), name) != _names.end();
98 }
99
101 size_t numberOfProperties() const
102 {
103 return _names.size();
104 }
105
107 void removeProperty(const std::string& name);
108
109private:
110 friend class PropertyContainer;
111 friend class SmartPropertyIndex;
112
116 void _register(PropertyContainer* properties)
117 {
118 _propertyContainers.insert(properties);
119 }
121 void _unregister(PropertyContainer* properties)
122 {
123 _propertyContainers.erase(properties);
124 }
125
127 void _register(SmartPropertyIndex* index)
128 {
129 _smartIndices.insert(index);
130 }
132 void _unregister(SmartPropertyIndex* index)
133 {
134 _smartIndices.erase(index);
135 }
136
138 void _notifySmartIndices() const;
139
141 std::vector<std::string> _names;
142
144 std::vector<PropertyValue> _defaultValues;
145
147 std::set<PropertyContainer*> _propertyContainers;
149 std::set<SmartPropertyIndex*> _smartIndices;
150
151public:
155 void addStateToTree(TreeNode* parent) const override;
156
159
161 void readStateFromTree(TreeNode* parent) override;
163
165};
166
167template <typename T> std::vector<std::string> PropertyManager::getPropertyNames() const
168{
169 // Suppress annoying boost warnings on linux bothering many dependent
170 // projects where it is not allowed any more and where it cannot be
171 // suppressed with system includes since it's a macro.
172#if defined(__GNUC__)
173#pragma GCC diagnostic push
174#pragma GCC diagnostic ignored "-Wold-style-cast"
175#endif
176 BOOST_MPL_ASSERT((boost::mpl::contains<PropertyValue::SupportedPropertyTypes, T>));
177#if defined(__GNUC__)
178#pragma GCC diagnostic pop
179#endif
180
181 std::vector<std::string> names;
182
183 T t{};
184 PropertyValue v(t);
185 const size_t which = v.which();
186 for (size_t i = 0; i < _defaultValues.size(); ++i) {
187 if (_defaultValues[i].which() == which) {
188 names.push_back(_names[i]);
189 }
190 }
191
192 return names;
193}
194
196
197#endif // __MLPropertyManager_H
@ T
A base-class enabling the use of boost::intrusive_ptr in derived classes.
PropertyManager & operator=(const PropertyManager &item)
Assignment operator. Resets all registered GraphProperties.
size_t getPropertyIndex(const std::string &propertyName) const
Return the index of property with name propertyName. Throws std::logic_error if the property does not...
PropertyManager type
void clearProperties()
Clear the list of property names and all registered GraphProperties.
PropertyManager()
Empty default constructor.
bool operator==(const PropertyManager &other) const
Comparison operator, checks names and defaultValues without respect to their order.
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
boost::intrusive_ptr< const type > ConstPointer
boost::intrusive_ptr< type > Pointer
void removeProperty(const std::string &name)
Remove property with name name. Throws ML_BAD_PARAMETER if the property does not exists.
std::map< std::string, PropertyValue > PropertyMap
const PropertyValue & getPropertyDefault(size_t propertyIndex) const
Get the default value that is set for the property.
void addStateToTree(TreeNode *parent) const override
~PropertyManager() override
const std::string & getPropertyName(size_t index) const
Return the name of property with index index.
const PropertyValue & getPropertyDefault(const std::string &propertyName) const
ML_CLASS_HEADER(PropertyManager)
bool hasProperty(const std::string &name) const
Returns whether a property with name name exists.
std::optional< size_t > getOptionalPropertyIndex(const std::string &propertyName) const
Return the index of property with name propertyName, if it exists.
size_t numberOfProperties() const
Return the number of properties currently available.
PropertyManager(const PropertyManager &other)
Copy Constructor.
const std::vector< std::string > & getPropertyNames() const
Return the list of available property names.
PropertyMap getPropertyDefaultMap() const
Get a map of property-names and default-values.
ML_SET_ADDSTATE_VERSION(1)
Set current addStateToTree() version number:
size_t createProperty(const std::string &name, const PropertyValue &defaultValue)
Create property with name name and return its' index.
Class PropertyValue, which is used to hold properties of a given set of allowed types in typesafe way...
size_t which() const
A self-updating index for efficient name-based access of properties.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define VESSELGRAPH_END_NAMESPACE
#define VESSELGRAPH_EXPORT
Definiert systemspezifische Macros, die f"ur diese DLL gelten sollen.
#define VESSELGRAPH_BEGIN_NAMESPACE