MeVisLab Toolbox Reference
mlField.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, 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_FIELD_H
14#define ML_FIELD_H
15
19
20// ML-includes
21#include "mlInitSystemML.h"
22#include "mlRuntimeSubClass.h"
23#include "mlFieldSensor.h"
24
25#include <string>
26#include <vector>
27
28ML_START_NAMESPACE
29
30class OutputConnectorField;
31class BaseField;
32class SoNodeField;
33class NotifyField;
34class FieldContainer;
35
36//-------------------------------------------------------------------------
71//-------------------------------------------------------------------------
73{
74
75public:
76
77 //---------------------------------------------------------------------------
80 //---------------------------------------------------------------------------
82 Field(const std::string& name = std::string());
83
85 virtual ~Field();
87
88 //---------------------------------------------------------------------------
91 //---------------------------------------------------------------------------
92
95
97
98 //----------------------------------------------------------
101 //----------------------------------------------------------
103 const std::string& getName() const { return _name; }
104
106 void setName(const std::string& name) { _name = name; }
107
110 std::string getFullName() const;
112
113 //----------------------------------------------------------
116 //----------------------------------------------------------
118 bool isOutputOnly() const;
119
121 void setOutputOnly(bool outputOnly = true);
123
124 //----------------------------------------------------------
127 //----------------------------------------------------------
128
131 virtual void setStringValue(const std::string& value) =0;
132
139 virtual std::string getStringValue() const =0;
140
144 virtual MLint isValidValue(){ return 1; }
145
146
150 void copyCStringValue(char* valueBuffer, MLint bufferSize);
151
153 MLint getCStringValueSize(){ return static_cast<MLint>(getStringValue().size()); }
155
156
157 //------------------------------------------------------------------------
160 //------------------------------------------------------------------------
163
166
169
175 void attachField(BaseField* targetField);
176 void attachField(SoNodeField* targetField);
177 void attachField(NotifyField* targetField);
178
182 void attachField(Field* targetField, bool propagateValueOnConnect);
183
185 void detachField(Field* targetField);
186
189
192
195
198
201
204
206 Field* getSourceField(size_t index);
207
223
227 void enableNotifications(bool flag);
228
232
239 static void enableNotificationsGlobally(bool flag);
240
247
254
255protected:
259
262
265
269 virtual void setValueFromField(const Field& field);
270
272 std::string _name;
273
275 std::vector <FieldSensor*> _sensors;
276
279 std::vector <Field*> _destinationFields;
280
283 std::vector <Field*> _sourceFields;
284
287
289 struct Flags {
291 unsigned int insideTouch:1;
292 unsigned int notifyAttachmentsFlag:1;
293 unsigned int outputOnly:1;
294 };
295
297
300
301private:
302 friend class FieldContainer;
303
305 void setFieldContainer(FieldContainer* container) { _fieldContainer = container; }
306
307 // Disallow copying
308 Field(const Field&) {}
309 Field& operator=(const Field&) { return *this; }
310
313};
314
315ML_END_NAMESPACE
316
317
318//-----------------------------------------------------------------------------------
319// Stream output for std::ostream
320//-----------------------------------------------------------------------------------
321namespace std
322{
323
325 MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::Field &v);
326
327}
328
329
330#endif // __mlField_H
331
332
333
Strength
Enumeration type describing the strength of notifications.
@ CHANGED
Subject (i.e., the field) is notified and/or changed.
void setName(const std::string &name)
Sets the name of field. Should be called only once after or while construction.
Definition mlField.h:106
virtual std::string getStringValue() const =0
size_t getNumDestinationFields()
Returns the number of destination fields that could receive notifications or value sets.
Field(const std::string &name=std::string())
Constructor: Creates a field with name.
static bool areNotificationsEnabledGlobally()
void attachField(Field *targetField, bool propagateValueOnConnect)
Flags _flags
Definition mlField.h:296
void detachFieldSensor(FieldSensor *sensor)
Detaches the field sensor sensor of this class instance in both directions.
FieldContainer * _fieldContainer
The owning field container.
Definition mlField.h:286
MLint getCStringValueSize()
Returns the length of the character string of the string value of the field.
Definition mlField.h:153
void setOutputOnly(bool outputOnly=true)
Marks this field as a pure output field that is only changed by its module.
Field * getDestinationField(size_t index)
Returns the destination field at index. Returns NULL if index is out of range.
void attachField(OutputConnectorField *targetField)
std::vector< Field * > _destinationFields
Definition mlField.h:279
void copyCStringValue(char *valueBuffer, MLint bufferSize)
std::vector< Field * > _sourceFields
Definition mlField.h:283
void attachField(BaseField *targetField)
size_t getNumSourceFields()
Returns the number of source fields that could send notifications or value sets.
std::string _name
The name of this field.
Definition mlField.h:272
virtual ~Field()
Destructor: Destroys a field and removes all connection to fields and sensors.
void detachAllFields()
Disconnects all source and target fields of this instance in both directions.
static void enableNotificationsGlobally(bool flag)
void detachDestinationFields()
Disconnects all target fields of this instance in both directions.
static MLint & enableNotificationsCounterState()
virtual MLint isValidValue()
Definition mlField.h:144
virtual void setStringValue(const std::string &value)=0
void detachField(Field *targetField)
Disconnects connections between the target field targetField and this instance.
bool isOutputOnly() const
Returns whether this field is marked as a pure output field.
void detachFieldSensors()
Detaches all field sensors of this class instance in both directions.
void detachSourceField(Field *field)
Removes a source field from this instance. If not found, then this call does nothing.
virtual void touch(FieldSensor::Strength strength=FieldSensor::CHANGED)
void detachSourceFields()
Disconnects all source fields of this instance in both directions.
FieldContainer * getFieldContainer() const
Returns the field container of the field (which may be NULL).
Definition mlField.h:94
Field * getSourceField(size_t index)
Returns the source field at index. Returns NULL if index is out of range.
std::string getFullName() const
std::vector< FieldSensor * > _sensors
List of field sensors.
Definition mlField.h:275
void attachSourceField(Field *field)
void detachFieldInternal(Field *field)
Only removes the given field from the destination list.
const std::string & getName() const
Returns the name of field.
Definition mlField.h:103
virtual void setValueFromField(const Field &field)
friend class FieldContainer
Definition mlField.h:302
void attachFieldSensor(FieldSensor *sensor)
Attaches a field sensor sensor of this class instance in both directions.
void attachField(NotifyField *targetField)
bool areNotificationsEnabled()
void attachField(SoNodeField *targetField)
void enableNotifications(bool flag)
static MLint _enableNotifications
Flag that disables the notification process of field (-sensors) globally.
Definition mlField.h:299
#define MLEXPORT
Code it as import symbol if compiled elsewhere.
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
MLint64 MLint
Definition mlTypeDefs.h:489
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
Flags for internal usage.
Definition mlField.h:289
unsigned int insideTouch
< Flag to suppress multiple notifications of fields, which otherwise could lead to endless loops.
Definition mlField.h:291
unsigned int observersWereRemovedInsideTouch
< Flag that indicates that the sensor/destination fields lists contain NULL entries
Definition mlField.h:290
unsigned int notifyAttachmentsFlag
< Flag to suppress the notification of connected fields and field sensors when field values are set.
Definition mlField.h:292
unsigned int outputOnly
< Flag to mark this field as a pure output field (this is used by the MeVisLab IDE).
Definition mlField.h:293