MeVisLab Toolbox Reference
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 
30 class PropertyContainer;
31 class SmartPropertyIndex;
32 
33 class VESSELGRAPH_EXPORT PropertyManager : public Base, public IntrusivePtrBase<PropertyManager> {
34 public:
36  typedef boost::intrusive_ptr<type> Pointer;
37  typedef boost::intrusive_ptr<const type> ConstPointer;
38  typedef std::map<std::string, PropertyValue> PropertyMap;
39 
44  ~PropertyManager() override;
45 
48 
50  bool operator==(const PropertyManager& other) const;
51 
54 
57  size_t createProperty(const std::string& name, const PropertyValue& defaultValue);
58 
60  const PropertyValue& getPropertyDefault(size_t propertyIndex) const { return _defaultValues[propertyIndex]; }
61  const PropertyValue& getPropertyDefault(const std::string& propertyName) const { return _defaultValues[getPropertyIndex(propertyName)]; }
62 
65 
67  size_t getPropertyIndex(const std::string& propertyName) const;
68 
70  const std::string& getPropertyName(size_t index) const { return _names[index]; }
71 
73  const std::vector<std::string>& getPropertyNames() const { return _names; }
74 
76  template<typename T>
77  std::vector<std::string> getPropertyNames() const;
78 
80  bool hasProperty(const std::string& name) const { return std::find(_names.begin(), _names.end(), name)!=_names.end(); }
81 
83  size_t numberOfProperties() const { return _names.size(); }
84 
86  void removeProperty(const std::string& name);
87 
88 private:
89  friend class PropertyContainer;
90  friend class SmartPropertyIndex;
91 
95  void _register(PropertyContainer* properties) { _propertyContainers.insert(properties); }
97  void _unregister(PropertyContainer* properties) { _propertyContainers.erase(properties); }
98 
100  void _register(SmartPropertyIndex* index) { _smartIndices.insert(index); }
102  void _unregister(SmartPropertyIndex* index) { _smartIndices.erase(index); }
103 
105  void _notifySmartIndices() const;
106 
108  std::vector<std::string> _names;
109 
111  std::vector<PropertyValue> _defaultValues;
112 
114  std::set<PropertyContainer*> _propertyContainers;
116  std::set<SmartPropertyIndex*> _smartIndices;
117 
118 public:
122  void addStateToTree(TreeNode* parent) const override;
123 
126 
128  void readStateFromTree(TreeNode* parent) override;
130 
132 };
133 
134 template<typename T>
135 std::vector<std::string> PropertyManager::getPropertyNames() const
136 {
137  // Suppress annoying boost warnings on linux bothering many dependent
138  // projects where it is not allowed any more and where it cannot be
139  // suppressed with systemincludes since it's a macro.
140 #if defined(__GNUC__)
141  #if !defined(MACOS) || defined(__clang__)
142  #pragma GCC diagnostic push
143  #pragma GCC diagnostic ignored "-Wold-style-cast"
144  #endif
145 #endif
146  BOOST_MPL_ASSERT(( boost::mpl::contains<PropertyValue::SupportedPropertyTypes, T> ));
147 #if defined(__GNUC__)
148  // pragma GCC diagnostic push is not available on the old Mac gcc.
149  // Thus we can only use this mechanism on linux, or if we use clang.
150  #if !defined(MACOS) || defined(__clang__)
151  #pragma GCC diagnostic pop
152  #endif
153 #endif
154 
155  std::vector<std::string> names;
156 
157  T t {};
158  PropertyValue v(t);
159  const size_t which = v.which();
160  for(size_t i=0;i<_defaultValues.size(); ++i) {
161  if (_defaultValues[i].which()==which) {
162  names.push_back(_names[i]);
163  }
164  }
165 
166  return names;
167 }
168 
170 
171 #endif // __MLPropertyManager_H
@ T
Definition: SoKeyGrabber.h:71
A base-class enabling the use of boost::intrusive_ptr in derived classes.
size_t getPropertyIndex(const std::string &propertyName) const
Return the index of property with name name. Throws ML_BAD_PARAMETER if the property does not exist.
PropertyManager type
void clearProperties()
Clear the list of property names and all registered GraphProperties.
PropertyManager & operator=(const PropertyManager &item)
Assignment operator. Resets all registered GraphProperties.
const std::vector< std::string > & getPropertyNames() const
Return the list of available property names.
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
const PropertyValue & getPropertyDefault(const std::string &propertyName) const
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
void addStateToTree(TreeNode *parent) const override
~PropertyManager() override
ML_CLASS_HEADER(PropertyManager)
bool hasProperty(const std::string &name) const
Returns whether a property with name name exists.
const std::string & getPropertyName(size_t index) const
Return the name of property with index index.
const PropertyValue & getPropertyDefault(size_t propertyIndex) const
Get the default value that is set for the property.
size_t numberOfProperties() const
Return the number of properties currently available.
PropertyManager(const PropertyManager &other)
Copy Constructor.
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.
#define VESSELGRAPH_END_NAMESPACE
#define VESSELGRAPH_EXPORT
Definiert systemspezifische Macros, die f"ur diese DLL gelten sollen.
#define VESSELGRAPH_BEGIN_NAMESPACE