29 #ifndef __THREAD_SAFE_FIELDS_H__
30 #define __THREAD_SAFE_FIELDS_H__
53 template<
class BaseField >
60 inline virtual void setValue(
const typename BaseField::value_type &v,
68 void * param[] = { &this->value, &
rt_value };
74 inline virtual const typename BaseField::value_type &
getValue(
int id = 0 ) {
89 void * param[] = { &
rt_value, &this->value };
101 void * * data =
static_cast< void * *
>( _data );
102 typename BaseField::value_type *new_value =
103 static_cast< typename BaseField::value_type *
>( data[0] );
104 typename BaseField::value_type *
rt_value =
105 static_cast< typename BaseField::value_type *
>( data[1] );
116 void * param[] = { &this->value, &
rt_value };
144 template<
class BaseField >
151 inline virtual void setValue(
typename BaseField::value_type v,
165 virtual typename BaseField::typed_value_type
getValue(
int id = 0 ) {
167 return static_cast< typename BaseField::typed_value_type
>(
rt_value.
get() );
190 void * * data =
static_cast< void * *
>( _data );
191 typename BaseField::value_type new_value =
192 static_cast< typename BaseField::value_type
>( data[0] );
200 virtual void onAdd(
typename BaseField::value_type i ) {
230 template<
class BaseField >
241 const vector< typename BaseField::value_type > &v,
249 void * param[] = { &this->value, &
rt_value };
259 inline virtual void setValue(
typename BaseField::size_type i,
260 const typename BaseField::value_type &t,
268 void * param[] = { &this->value, &
rt_value };
274 inline virtual void swap(
typename BaseField::vector_type &
x,
int id = 0 ) {
281 void * param[] = { &this->value, &
rt_value };
287 inline virtual void push_back(
const typename BaseField::value_type &
x,
295 void * param[] = { &this->value, &
rt_value };
308 void * param[] = { &this->value, &
rt_value };
314 inline virtual void clear(
int id = 0 ) {
321 void * param[] = { &this->value, &
rt_value };
327 inline virtual typename BaseField::const_iterator
begin(
int id = 0 ) {
337 inline virtual typename BaseField::const_iterator
end(
int id = 0 ) {
350 inline virtual typename BaseField::const_reverse_iterator
rbegin(
int id = 0 ) {
362 inline virtual typename BaseField::const_reverse_iterator
rend(
int id = 0 ) {
372 inline virtual unsigned int size() {
382 inline virtual typename BaseField::size_type
max_size() {
393 inline virtual typename BaseField::size_type
capacity() {
412 inline virtual typename BaseField::const_reference
operator[](
typename BaseField::size_type n ) {
422 inline virtual typename BaseField::const_reference
front(
int id = 0 ) {
432 inline virtual typename BaseField::const_reference
back(
int id = 0 ) {
442 inline virtual const typename BaseField::vector_type &
getValue(
int id = 0 ) {
457 void * param[] = { &
rt_value, &this->value };
469 void * * data =
static_cast< void * *
>( _data );
470 typename BaseField::vector_type *new_value =
471 static_cast< typename BaseField::vector_type *
>( data[0] );
472 typename BaseField::vector_type *
rt_value =
473 static_cast< typename BaseField::vector_type *
>( data[1] );
484 void * param[] = { &this->value, &
rt_value };
Header file for PeriodicUpdate, template field modifier.
RefCountedClassType * get() const
void reset(RefCountedClassType *p=0)
static bool inHapticThread()
static void synchronousHapticCB(PeriodicThreadBase::CallbackFunc func, void *data)
static bool inMainThread()
The PeriodicUpdate is a template modifier that changes the way the field is updated.
Definition: PeriodicUpdate.h:74
virtual void upToDate()
upToDate is specialized to record the time of the call to the function in the last_up_to_date member.
Definition: PeriodicUpdate.h:125
<>
Definition: ThreadSafeFields.h:231
virtual unsigned int size()
Returns the size of the vector.
Definition: ThreadSafeFields.h:372
virtual bool empty()
true if the vector's size is 0.
Definition: ThreadSafeFields.h:403
virtual void setValue(const vector< typename BaseField::value_type > &v, int id=0)
Set the value of the field.
Definition: ThreadSafeFields.h:240
virtual BaseField::const_reverse_iterator rbegin(int id=0)
Returns a const_reverse_iterator pointing to the beginning of the reversed vector.
Definition: ThreadSafeFields.h:350
ThreadSafeMField()
Constructor.
Definition: ThreadSafeFields.h:234
BaseField::vector_type rt_value
The copy of the field value to be used in the haptics threads.
Definition: ThreadSafeFields.h:489
virtual void upToDate()
Make sure that the field is up-to-date.
Definition: ThreadSafeFields.h:453
virtual void clear(int id=0)
Erases all of the elements.
Definition: ThreadSafeFields.h:314
bool rt_value_changed
Flag indicating if the rt_value has been changed by a haptics thread.
Definition: ThreadSafeFields.h:493
static H3DUtil::PeriodicThread::CallbackCode transferValue(void *_data)
Callback function to transfer copy a value between two pointers of the same type.
Definition: ThreadSafeFields.h:468
virtual void push_back(const typename BaseField::value_type &x, int id=0)
Inserts a new element at the end.
Definition: ThreadSafeFields.h:287
virtual void setValue(typename BaseField::size_type i, const typename BaseField::value_type &t, int id=0)
Change the value of one element in the MField.
Definition: ThreadSafeFields.h:259
virtual void update()
The update function is specialized to synchronize with the haptics threads and copy the new value of ...
Definition: ThreadSafeFields.h:481
virtual void swap(typename BaseField::vector_type &x, int id=0)
Swaps the contents of two vectors.
Definition: ThreadSafeFields.h:274
virtual BaseField::const_reference operator[](typename BaseField::size_type n)
Returns the n'th element.
Definition: ThreadSafeFields.h:412
virtual BaseField::const_reference back(int id=0)
Returns the last element.
Definition: ThreadSafeFields.h:432
virtual BaseField::const_reference front(int id=0)
Returns the first element.
Definition: ThreadSafeFields.h:422
virtual const BaseField::vector_type & getValue(int id=0)
Gets the value of the field.
Definition: ThreadSafeFields.h:442
virtual BaseField::const_reverse_iterator rend(int id=0)
Returns a const_reverse_iterator pointing to the end of the reversed vector.
Definition: ThreadSafeFields.h:362
virtual BaseField::size_type max_size()
Returns the largest possible size of the vector.
Definition: ThreadSafeFields.h:382
virtual BaseField::const_iterator end(int id=0)
Returns a const_iterator pointing to the end of the vector.
Definition: ThreadSafeFields.h:337
void pop_back(int id=0)
Removed the last element.
Definition: ThreadSafeFields.h:301
virtual BaseField::size_type capacity()
Number of elements for which memory has been allocated.
Definition: ThreadSafeFields.h:393
virtual BaseField::const_iterator begin(int id=0)
Returns a const_iterator pointing to the beginning of the vector.
Definition: ThreadSafeFields.h:327
<>
Definition: ThreadSafeFields.h:145
virtual void onAdd(typename BaseField::value_type i)
onAdd is extended to change the rt_image value in a thread safe way.
Definition: ThreadSafeFields.h:200
ThreadSafeRefSField()
Constructor.
Definition: ThreadSafeFields.h:148
virtual BaseField::typed_value_type getValue(int id=0)
Get the value of the field.
Definition: ThreadSafeFields.h:165
AutoRef< typename BaseField::class_type > rt_value
The reference for the haptics loop.
Definition: ThreadSafeFields.h:208
bool rt_value_changed
Flag indicating if the rt_value has been changed by a haptics thread.
Definition: ThreadSafeFields.h:212
virtual void setValue(typename BaseField::value_type v, int id=0)
Set the value of the field.
Definition: ThreadSafeFields.h:151
virtual void upToDate()
Make sure that the field is up-to-date.
Definition: ThreadSafeFields.h:176
<>
Definition: ThreadSafeFields.h:54
virtual void update()
The update function is specialized to synchronize with the haptics threads and copy the new value of ...
Definition: ThreadSafeFields.h:113
bool rt_value_changed
Flag indicating if the rt_value has been changed by a haptics thread.
Definition: ThreadSafeFields.h:125
virtual const BaseField::value_type & getValue(int id=0)
Get the value of the field.
Definition: ThreadSafeFields.h:74
ThreadSafeSField()
Constructor.
Definition: ThreadSafeFields.h:57
static H3DUtil::PeriodicThread::CallbackCode transferValue(void *_data)
Callback function to transfer copy a value between two pointers of the same type.
Definition: ThreadSafeFields.h:100
virtual void setValue(const typename BaseField::value_type &v, int id=0)
Set the value of the field.
Definition: ThreadSafeFields.h:60
BaseField::value_type rt_value
The copy of the field value to be used in the haptics threads.
Definition: ThreadSafeFields.h:121
virtual void upToDate()
Make sure that the field is up-to-date.
Definition: ThreadSafeFields.h:85
H3DDouble & operator[](int i)
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