28 #ifndef __FIELDTEMPLATES_H__
29 #define __FIELDTEMPLATES_H__
51 virtual void setValue(
const typename SF::value_type &v,
int id = 0 ) {
52 typename SF::value_type old_value = this->value;
53 SF::setValue( v,
id );
54 if( this->value != old_value ) {
61 virtual void onValueChange(
const typename SF::value_type &new_value ) = 0;
63 virtual void update() {
64 typename SF::value_type old_value = this->value;
66 if( this->value != old_value ) {
81 virtual void setValue(
const typename SF::value_type &v,
int id = 0 ) {
82 SF::setValue( v,
id );
88 virtual void onNewValue(
const typename SF::value_type &new_value ) = 0;
90 virtual void update() {
101 template<
class RefCountedType,
class BaseRefCountType >
105 void onAdd(
typename BaseRefCountType::value_type n) {
106 if( !
dynamic_cast< RefCountedType *
>( n ) ) {
108 s <<
"Expecting " <<
typeid( RefCountedType ).name();
109 throw InvalidNodeType(
typeid( n ).name(),
114 BaseRefCountType::onAdd( n );
129 template<
class BaseFieldType >
135 BaseFieldType::propagateEvent( e );
144 template<
class FieldType >
151 FieldType::propagateEvent( e );
152 event_fields.insert( e.
ptr );
160 FieldType::upToDate();
161 event_fields.clear();
167 return event_fields.find( f ) != event_fields.end();
173 return event_fields.size();
178 template<
class FieldType2 >
186 set< Field * > event_fields;
#define H3D_FULL_LOCATION
Contains base classes used to create multivalued fields.
Contains the SField template class.
Contains the TypedField template class.
The EventCollection field collects all fields routed to it that generates event between calls to the ...
Definition: FieldTemplates.h:145
size_t nrPendingEvents()
Returns the number of input fields that has generated an event to this field since the last call to t...
Definition: FieldTemplates.h:172
bool hasCausedEvent(Field *f)
Returns true if the Field given has generated an event to this field since the last call to the updat...
Definition: FieldTemplates.h:166
virtual void upToDate()
Check that the field is up-to-date, if not update() is called to make it up-to-date.
Definition: FieldTemplates.h:159
virtual void propagateEvent(Field::Event e)
When the event is propagated the field that created the event is saved.
Definition: FieldTemplates.h:150
bool hasCausedEvent(H3DUniquePtr< FieldType2 > &f)
Returns true if the Field given has generated an event to this field since the last call to the updat...
Definition: FieldTemplates.h:179
The Field class.
Definition: Field.h:46
Template for adding the virtual function onNewValue that can be overridden in subclasses in order to ...
Definition: FieldTemplates.h:79
virtual void onNewValue(const typename SF::value_type &new_value)=0
This function is called when the field is updated to a value.
Template for adding the virtual function onValueChange that can be overridden in subclasses in order ...
Definition: FieldTemplates.h:49
virtual void onValueChange(const typename SF::value_type &new_value)=0
This function is called when the value in the field has changed.
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: FieldTemplates.h:102
void onAdd(typename BaseRefCountType::value_type n)
We check that the type of the Node is of the correct type.
Definition: FieldTemplates.h:105
virtual RefCountedType * getValue()
Get the value casted to the RefCountType.
Definition: FieldTemplates.h:119
H3D_VALUE_EXCEPTION(string, InvalidType)
An exception thrown when a field is of the wrong type when it is checked.
Type getValue(const char *s, const char *&rest)
Function that reads characters from a char * and converts them to a given type.
Definition: X3DFieldConversion.h:134
H3D API namespace.
Definition: Anchor.h:38
The AutoUpdate field is a template to force the BaseField to update itself as soon as an event is rec...
Definition: FieldTemplates.h:130
virtual void propagateEvent(Field::Event e)
Receive an event from another field.
Definition: FieldTemplates.h:134
The Event struct encapsulates an event in the field network.
Definition: Field.h:75
Field * ptr
The Field that caused the event.
Definition: Field.h:84