MeVisLab Toolbox Reference
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> {
28public:
30 typedef boost::intrusive_ptr<type> PointerType;
31 typedef boost::intrusive_ptr<const type> ConstPointerType;
32
34 _manager(manager), _propertyName(propertyName) { _manager->_register(this); update(); };
35
37 _manager(other._manager), _propertyName(other._propertyName), _currentIndex(other._currentIndex),
38 _valid(other._valid) { _manager->_register(this); }
39
40 ~SmartPropertyIndex() { _manager->_unregister(this); }
41
42 operator size_t() const { if (!_valid) throw ML_BAD_PARAMETER; return _currentIndex; }
43
44 void update() const { _valid = _manager->hasProperty(_propertyName); if (_valid) _currentIndex = _manager->getPropertyIndex(_propertyName); }
45
46 PropertyManager* getManager() { return _manager.get(); }
47 const PropertyManager* getManager() const { return _manager.get(); }
48 const std::string& getName() const { return _propertyName; }
49 bool isValid() const { return _valid; }
50
51private:
53
55 const std::string _propertyName;
56 mutable size_t _currentIndex;
57 mutable bool _valid;
58};
59
61
62#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:823
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define VESSELGRAPH_END_NAMESPACE
#define VESSELGRAPH_BEGIN_NAMESPACE