MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlPropertyIndex.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_INDEX_H
14#define ML_PROPERTY_INDEX_H
15
16
18
19#include "mlVesselGraphSystem.h"
20
21#include "mlIntrusivePtrBase.h"
22#include "mlPropertyValue.h"
23#include "mlPropertyManager.h"
24
26
27class SmartPropertyIndex : public IntrusivePtrBase<SmartPropertyIndex>
28{
29public:
31 typedef boost::intrusive_ptr<type> PointerType;
32 typedef boost::intrusive_ptr<const type> ConstPointerType;
33
35 : _manager(manager)
36 , _propertyName(propertyName)
37 {
38 _manager->_register(this);
39 update();
40 };
41
43 : _manager(other._manager)
44 , _propertyName(other._propertyName)
45 , _currentIndex(other._currentIndex)
46 , _valid(other._valid)
47 {
48 _manager->_register(this);
49 }
50
52 {
53 _manager->_unregister(this);
54 }
55
56 operator size_t() const
57 {
58 if (!_valid)
59 throw ML_BAD_PARAMETER;
60 return _currentIndex;
61 }
62
63 void update() const
64 {
65 _valid = _manager->hasProperty(_propertyName);
66 if (_valid)
67 _currentIndex = _manager->getPropertyIndex(_propertyName);
68 }
69
71 {
72 return _manager.get();
73 }
75 {
76 return _manager.get();
77 }
78 const std::string& getName() const
79 {
80 return _propertyName;
81 }
82 bool isValid() const
83 {
84 return _valid;
85 }
86
87private:
89
91 const std::string _propertyName;
92 mutable size_t _currentIndex;
93 mutable bool _valid;
94};
95
97
98#endif // __mlPropertyIndex_H_
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.
const PropertyManager * getManager() const
boost::intrusive_ptr< const type > ConstPointerType
PropertyManager * getManager()
SmartPropertyIndex type
SmartPropertyIndex(const PropertyManager::Pointer &manager, const std::string &propertyName)
const std::string & getName() const
SmartPropertyIndex(const SmartPropertyIndex &other)
boost::intrusive_ptr< type > PointerType
#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