MeVisLab Toolbox Reference
mlFieldAddOnList.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3//----------------------------------------------------------------------------------
5
10//----------------------------------------------------------------------------------
11#pragma once
12
14#include <mlFieldAddOnBase.h>
15
17
18//----------------------------------------------------------------------------------
28//----------------------------------------------------------------------------------
29template <typename FIELD_ADD_ON_BASE_CLASS, typename PIMPL_OBJ_TYPE=void*>
30class FieldAddOnList : public FIELD_ADD_ON_BASE_CLASS
31{
32public:
33
35 typedef std::vector<FIELD_ADD_ON_BASE_CLASS*> FieldAddOnContainer;
36
39 FIELD_ADD_ON_BASE_CLASS(fieldContainerRef),
40 _pImpl(),
41 _fieldAddOns()
42 {}
43
45 ~FieldAddOnList() override
46 {
47 // FieldAddOns are not owned by this container, thus do nothing here but container resetting.
48 getFieldAddOns().clear();
49 }
50
52 inline FieldAddOnContainer &getFieldAddOns(){ return _fieldAddOns; }
53
55 inline const FieldAddOnContainer &getFieldAddOns() const { return _fieldAddOns; }
56
58 virtual void registerFieldAddOn(FIELD_ADD_ON_BASE_CLASS *fieldAddOn)
59 {
60 if (fieldAddOn){
61 getFieldAddOns().push_back(fieldAddOn);
62 }
63 }
64
66 virtual bool hasFieldAddOn(FIELD_ADD_ON_BASE_CLASS *fieldAddOn) const
67 {
68 for (size_t c=0; c < getFieldAddOns().size(); ++c){
69 if (getFieldAddOns()[c] == fieldAddOn){
70 return true;
71 }
72 }
73 return false;
74 }
75
77
80 void addFields() override
81 {
82 auto it = _fieldAddOns.begin();
83 for (; it != getFieldAddOns().end(); it++){ (*it)->addFields(); }
84 }
85
88 {
89 auto it = getFieldAddOns().begin();
90 for (; it != getFieldAddOns().end(); it++){ (*it)->handleFieldActivationChanges(); }
91 }
92
98 {
99 FieldAddOnBase::FieldChangeState retVal = FieldAddOnBase::NoChange;
100
101 auto it = _fieldAddOns.begin();
102 for (; it != getFieldAddOns().end(); it++){
103 // Handle changes of each FieldAddOn and make the "strongest" change state survive.
104 const FieldAddOnBase::FieldChangeState currState = (*it)->handleFieldChanges(field);
105 retVal = FieldAddOnBase::getMergedFieldChangeState(currState, retVal);
106 }
107 return retVal;
108 }
110
114
115private:
117 FieldAddOnContainer _fieldAddOns;
118
121
123 FieldAddOnList & operator=(const FieldAddOnList&);
124};
125
Project global and OS specific declarations.
FieldChangeState
Describes the type of a field changes detected in handleFieldChanges(Field *field).
Class managing a list of FieldAddOns to simplify usage of multiple AddOns; AddOns are never owned by ...
void addFields() override
Add fields to field container of module.
void handleFieldActivationChanges() override
Handle class changes according to Module::activateAttachments.
FieldAddOnList(FieldContainer &fieldContainerRef)
Constructor, setting the reference of the FieldContainer managing the fields.
FieldAddOnContainer & getFieldAddOns()
Returns the referenced container.
FieldAddOnBase::FieldChangeState handleFieldChanges(Field *field) override
Handle field notifications according to Module::handleNotification functionality.
virtual bool hasFieldAddOn(FIELD_ADD_ON_BASE_CLASS *fieldAddOn) const
Returns true if the passed fieldPtr is in _fieldPointers, otherwise false.
const FieldAddOnContainer & getFieldAddOns() const
Returns the constant referenced container.
~FieldAddOnList() override
Destructor.
std::vector< FIELD_ADD_ON_BASE_CLASS * > FieldAddOnContainer
The internally used container to manage the FieldAddOns.
virtual void registerFieldAddOn(FIELD_ADD_ON_BASE_CLASS *fieldAddOn)
Register a FieldAddOn in *this; nullptr fieldAddOn pointers are ignored and not added.
PIMPL_OBJ_TYPE _pImpl
User defined object not used in this base class (only default constructor is called),...
Defines the class FieldContainer to encapsulate a vector of fields for (see class Field).
Base class for all fields used in the ML.
Definition mlField.h:73
Header file of the abstract base class FieldAddOnBase managing fields independently of an ML Module.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.