MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00004 00009 //---------------------------------------------------------------------------------- 00010 00011 #ifndef __mlPropertyIndex_H_ 00012 #define __mlPropertyIndex_H_ 00013 00014 #include "mlVesselGraphSystem.h" 00015 00016 #include "mlIntrusivePtrBase.h" 00017 #include "mlPropertyValue.h" 00018 #include "mlPropertyManager.h" 00019 00020 ML_START_NAMESPACE 00021 00022 class SmartPropertyIndex : public IntrusivePtrBase<SmartPropertyIndex> { 00023 public: 00024 typedef SmartPropertyIndex type; 00025 typedef boost::intrusive_ptr<type> PointerType; 00026 typedef boost::intrusive_ptr<const type> ConstPointerType; 00027 00028 SmartPropertyIndex(const PropertyManager::Pointer& manager, const std::string& propertyName) : 00029 _manager(manager), _propertyName(propertyName) { _manager->_register(this); update(); }; 00030 00031 SmartPropertyIndex(const SmartPropertyIndex& other) : 00032 _manager(other._manager), _propertyName(other._propertyName), _currentIndex(other._currentIndex), 00033 _valid(other._valid) { _manager->_register(this); } 00034 00035 ~SmartPropertyIndex() { _manager->_unregister(this); } 00036 00037 operator size_t() const { if (!_valid) throw ML_BAD_PARAMETER; return _currentIndex; } 00038 00039 void update() const { _valid = _manager->hasProperty(_propertyName); if (_valid) _currentIndex = _manager->getPropertyIndex(_propertyName); } 00040 00041 PropertyManager* getManager() { return _manager.get(); } 00042 const PropertyManager* getManager() const { return _manager.get(); } 00043 const std::string& getName() const { return _propertyName; } 00044 bool isValid() const { return _valid; } 00045 00046 private: 00047 SmartPropertyIndex& operator=(const SmartPropertyIndex& other); 00048 00049 PropertyManager::Pointer _manager; 00050 const std::string _propertyName; 00051 mutable size_t _currentIndex; 00052 mutable bool _valid; 00053 }; 00054 00055 ML_END_NAMESPACE 00056 00057 #endif // __mlPropertyIndex_H_