MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlPropertyAccessor.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_ACCESSOR_H
14#define ML_PROPERTY_ACCESSOR_H
15
16
18
19#include "mlVesselGraphSystem.h"
20
21#include "mlIntrusivePtrBase.h"
22#include "mlPropertyContainer.h"
23#include "mlPropertyIndex.h"
24#include "mlPropertyManager.h"
25
27#include <boost/mem_fn.hpp>
28#include <boost/type_traits/add_const.hpp>
29#include <boost/type_traits/add_reference.hpp>
30#include <boost/type_traits/remove_const.hpp>
32
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable : 4344)
36#endif
37
39
40template <typename T> class DefaultPropertyAccessor : IntrusivePtrBase<DefaultPropertyAccessor<T>>
41{
42public:
44 typedef boost::intrusive_ptr<type> PointerType;
45 typedef boost::intrusive_ptr<const type> ConstPointerType;
46
48 const T& defaultValue)
49 : _index(manager, propertyName)
50 , _defaultValue(defaultValue) {};
51
53 const T& operator()(const PropertyContainer& container) const;
54
55 const T& get(const PropertyContainer& container) const
56 {
57 return operator()(container);
58 }
59 void set(PropertyContainer& container, const T& value) const
60 {
61 operator()(container) = value;
62 }
63
64private:
65 SmartPropertyIndex _index;
66 T _defaultValue;
67};
68
70{
71 if (_index.getManager() != container.getPropertyManager()) {
72 throw ML_BAD_PARAMETER;
73 }
74 if (!_index.isValid()) {
75 container.getPropertyManager()->createProperty(_index.getName(), _defaultValue);
76 }
77 return container.property<T>(_index);
78}
79
80template <typename T> const T& DefaultPropertyAccessor<T>::operator()(const PropertyContainer& container) const
81{
82 if (_index.getManager() != container.getPropertyManager()) {
83 throw ML_BAD_PARAMETER;
84 }
85 if (_index.isValid()) {
86 return container.property<T>(_index);
87 }
88 else {
89 return _defaultValue;
90 }
91}
92
93
95
96#ifdef _MSC_VER
97#pragma warning(pop)
98#endif
99
100#endif // __MLPropertyAccessor_H
@ T
Project global and OS specific declarations.
const T & get(const PropertyContainer &container) const
DefaultPropertyAccessor(const PropertyManager::Pointer &manager, const std::string &propertyName, const T &defaultValue)
DefaultPropertyAccessor< T > type
T & operator()(PropertyContainer &container) const
boost::intrusive_ptr< type > PointerType
boost::intrusive_ptr< const type > ConstPointerType
void set(PropertyContainer &container, const T &value) const
A base-class enabling the use of boost::intrusive_ptr in derived classes.
boost::intrusive_ptr< type > Pointer
A self-updating index for efficient name-based access of properties.
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm,...
Definition mlTypeDefs.h:879
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define VESSELGRAPH_END_NAMESPACE
#define VESSELGRAPH_BEGIN_NAMESPACE