50 DEPRECATED(
"int setValueFromVoidPtr( const void *data, unsigned int nr_elements, unsigned int size, int id = 0 )", )
54 virtual
int setValueFromVoidPtr(
void *data,
unsigned int nr_elements,
55 unsigned int size,
int id = 0 ) {
56 return setValueFromVoidPtr( (
const void*)data, nr_elements, size,
id );
68 unsigned int size,
int id = 0 ) = 0;
74 virtual unsigned int size() = 0;
84 unsigned int size,
int id = 0 ) = 0;
98 class VectorClass = std::vector< Type >,
102 AnyNumber< MFieldBase< Type,
114 typedef typename VectorClass::pointer
pointer;
124 typedef typename VectorClass::const_reverse_iterator
132 return value.begin();
136 inline const_iterator
end(
int id = 0 ) {
151 return value.rbegin();
168 return (
unsigned int)
value.size();
174 return value.max_size();
181 return value.capacity();
200 value.resize( n, t );
207 return value.empty();
223 return value.front();
227 inline const_reference
back(
int id = 0 ) {
235 inline void swap( VectorClass &
x,
int id = 0 ) {
240 this->
value.swap( x );
249 this->
value.push_back( x );
279 unsigned int nr_elements,
280 unsigned int len,
int id = 0 ) {
283 if( len !=
sizeof(
value_type ) * nr_elements )
286 std::vector< Type > new_data( nr_elements );
287 for(
unsigned int i = 0; i < nr_elements; ++i ) {
288 new_data[i] =
static_cast< const value_type *
>( data )[i];
290 this->
value.swap( new_data );
296 H3D_DISABLE_UNUSED_PARAMETER_WARNING()
307 unsigned int &nr_elements,
311 nr_elements = (
unsigned int) this->
value.size();
312 if( len < sz * nr_elements ) {
321 for(
unsigned int i = 0; i < nr_elements; ++i ) {
322 data_ptr[i] =
value[i];
324 return sz * nr_elements;
354 template<
class Type >
364 typedef typename std::vector< Type >::iterator
iterator;
378 inline virtual const std::vector< Type > &
getValue(
int id = 0 );
384 inline virtual typename std::vector<Type>::const_reference
387 Console(LogLevel::Debug) <<
"MField(" << this->
name <<
")::getValue()" << endl;
395 if( i >= this->
value.size() ) {
397 s <<
"Trying to access value outside the bounds of field "
402 return this->
value[i];
409 inline virtual void setValue(
const std::vector< Type > &v,
int id = 0 );
417 const Type &v,
int id = 0 ) {
419 Console(LogLevel::Debug) <<
"MField< " <<
typeid( Type ).
name()
420 <<
" >(" << this->
name <<
")::setValue()" << endl;
427 this->
event.ptr = NULL;
436 std::vector< Type > v;
437 X3D::X3DStringToVector< std::vector< Type > >( s, v );
443 this->
push_back( X3D::X3DStringToValue< Type >( s ) );
450 const std::vector< Type > &v =
getValue();
455 for( i = 0; i < v.size() - 1; ++i )
456 s << v[i] << separator;
473 template <
class InputIterator>
514 inline virtual void erase(
const Type &a,
int = 0 ) {
515 iterator i = std::find( this->
value.begin(), this->value.end(), a );
516 if( i != this->
value.end() ) {
517 this->
value.erase( i );
530 const std::vector< Type > &v =
getValue();
537 const std::vector< Type > &v =
getValue();
539 if( element >= v.size() )
553 return this->
value.begin()+(pos-this->
value.begin());
557 template<
class Type >
560 Console(LogLevel::Debug) <<
"MField< " <<
typeid( Type ).name()
561 <<
" >(" << this->name <<
")::update()" << endl;
566 (this->
event.ptr)->
getValue( this->owner->id );
572 template<
class Type >
575 Console(LogLevel::Debug) <<
"MField< " <<
typeid( Type ).name()
576 <<
" >(" << this->name <<
")::setValue()" << endl;
579 this->checkAccessTypeSet(
id );
583 this->
event.ptr = NULL;
588 template<
class Type >
591 Console(LogLevel::Debug) <<
"MField< " <<
typeid( Type ).name()
592 <<
" >(" << this->name <<
")::getValue()" << endl;
595 this->checkAccessTypeGet(
id );
#define H3D_FULL_LOCATION
Contains the TypedField template class.
This file contains functions for convertion from a string to a value of an X3D field type.
string getFullName()
Get the full name of the field including the name of the owner node if it exists (ownername....
Definition: Field.cpp:406
virtual void startEvent()
Start a new event from this field.
Definition: Field.cpp:349
virtual void upToDate()
Check that the field is up-to-date, if not update() is called to make it up-to-date.
Definition: Field.cpp:388
void checkAccessTypeGet(int id)
Check the access type is valid for getting the value of a field.
Definition: Field.cpp:160
void checkAccessTypeSet(int id)
Check the access type is valid for changing the value of a field.
Definition: Field.cpp:185
string name
The name of the field.
Definition: Field.h:312
The common base class for MField types and MFNode.
Definition: MField.h:105
MFieldBase(size_type sz)
Creates a MField with space reserved for n elements.
Definition: MField.h:337
VectorClass::const_reference const_reference
Const reference to Type.
Definition: MField.h:116
void pop_back(int id=0)
Removed the last element.
Definition: MField.h:254
const_iterator end(int id=0)
Returns a const_iterator pointing to the end of the vector.
Definition: MField.h:136
bool empty()
true if the vector's size is 0.
Definition: MField.h:205
size_type max_size()
Returns the largest possible size of the vector.
Definition: MField.h:172
unsigned int size()
Returns the size of the vector.
Definition: MField.h:166
const_reverse_iterator rend(int id=0)
Returns a const_reverse_iterator pointing to the end of the reversed vector.
Definition: MField.h:158
VectorClass vector_return_type
The return type of functions that return the value of the field.
Definition: MField.h:110
const_reverse_iterator rbegin(int id=0)
Returns a const_reverse_iterator pointing to the beginning of the reversed vector.
Definition: MField.h:147
VectorClass value
The encapsulated vector.
Definition: MField.h:346
const_reference operator[](size_type n)
Returns the n'th element.
Definition: MField.h:211
static string classTypeName()
Returns a string name for this field type e.g. MFInt32.
Definition: MField.h:340
const_reference front(int id=0)
Returns the first element.
Definition: MField.h:219
virtual int getValueAsVoidPtr(void *data, unsigned int &nr_elements, unsigned int len, int id=0)
Get the value of the data copied into a memory buffer.
Definition: MField.h:306
const_iterator begin(int id=0)
Returns a const_iterator pointing to the beginning of the vector.
Definition: MField.h:128
void push_back(const Type &x, int id=0)
Inserts a new element at the end.
Definition: MField.h:245
virtual unsigned int valueTypeSize()
Returns the size in bytes of the value type the mfield encapsulates.
Definition: MField.h:329
VectorClass::const_iterator const_iterator
Const iterator used to iterate through a vector.
Definition: MField.h:122
MFieldBase()
Default constructor. Creates an empty MField.
Definition: MField.h:334
VectorClass::difference_type difference_type
A signed integral type.
Definition: MField.h:120
VectorClass::pointer pointer
Pointer to Type.
Definition: MField.h:114
void swap(VectorClass &x, int id=0)
Swaps the contents of two vectors.
Definition: MField.h:235
virtual int setValueFromVoidPtr(const void *data, unsigned int nr_elements, unsigned int len, int id=0)
Set the value of the field given a pointer to where the value of the field is.
Definition: MField.h:278
VectorClass vector_type
The type of the value member.
Definition: MField.h:108
size_type capacity()
Number of elements for which memory has been allocated.
Definition: MField.h:179
void reserve(size_type s)
A request for allocation of additional memory.
Definition: MField.h:191
VectorClass::const_reverse_iterator const_reverse_iterator
Const iterator used to iterate backwards through a vector.
Definition: MField.h:125
void clear(int id=0)
Erases all of the elements.
Definition: MField.h:263
VectorClass::value_type value_type
The type of the values stored in the vector.
Definition: MField.h:112
const_reference back(int id=0)
Returns the last element.
Definition: MField.h:227
VectorClass::size_type size_type
An unsigned integral type.
Definition: MField.h:118
void resize(size_type n, Type t=Type(), int id=0)
Inserts or erases elements at the end such that the size becomes n.
Definition: MField.h:197
Base class for all fields created with the MField template.
Definition: MField.h:44
virtual unsigned int valueTypeSize()=0
Returns the size in bytes of the value type the mfield encapsulates.
virtual int setValueFromVoidPtr(const void *data, unsigned int nr_elements, unsigned int size, int id=0)=0
Set the value of the field given a pointer to where the value of the field is.
virtual ~MFieldClass()
Virtual destructor.
Definition: MField.h:47
virtual unsigned int size()=0
Returns the number of values that is stored in the mfield.
virtual int getValueAsVoidPtr(void *data, unsigned int &nr_elements, unsigned int size, int id=0)=0
Get the value of the data copied into a memory buffer.
Thrown if the index given to getValueByIndex() is outside the boundaries.
Definition: MField.h:368
Template class that adds the Field mechanism to a vector of values.
Definition: MField.h:357
virtual void setValue(const std::vector< Type > &v, int id=0)
Set the value of the field.
Definition: MField.h:573
virtual string getElementAsString(size_t element)
Get the value of an element of the field as a string.
Definition: MField.h:535
virtual void erase(typename MField< Type >::const_iterator pos, int id=0)
Erases the element at position pos.
Definition: MField.h:494
virtual void addElementFromString(const string &s)
Add a new element to an MField from a string value.
Definition: MField.h:442
virtual void setValueFromString(const string &s)
Set the value of the field given a string.
Definition: MField.h:435
iterator iteratorFromConst(typename MField< Type >::const_iterator pos)
Helper function to get an iterator from a const_iterator.
Definition: MField.h:552
MField()
Default constructor. Creates an empty MField.
Definition: MField.h:371
virtual void setValue(typename BaseMField::size_type i, const Type &v, int id=0)
Change the value of one element in the MField.
Definition: MField.h:416
void insert(typename MField< Type >::const_iterator pos, typename BaseMField::size_type n, const Type &x, int id=0)
Inserts n copies of x before pos.
Definition: MField.h:485
MField< Type >::const_iterator insert(typename MField< Type >::const_iterator pos, const Type &x, int id=0)
Inserts x before pos.
Definition: MField.h:462
std::vector< Type >::iterator iterator
iterator used to iterate through a vector.
Definition: MField.h:364
MField(typename BaseMField::size_type sz)
Creates an MField with space reserved for size nodes.
Definition: MField.h:374
virtual void update()
Make the field up to date given that an event has occured.
Definition: MField.h:558
virtual const std::vector< Type > & getValue(int id=0)
Get the value of the MField.
Definition: MField.h:589
void insert(typename MField< Type >::const_iterator pos, InputIterator first, InputIterator last, int id=0)
Inserts the range [first, last) before pos.
Definition: MField.h:474
virtual std::vector< Type >::const_reference getValueByIndex(typename BaseMField::size_type i, int id=0)
Get the value of an element of the MField.
Definition: MField.h:385
virtual string getTypeName()
Returns a string name for this field type e.g. MFInt32.
Definition: MField.h:522
virtual void erase(const Type &a, int=0)
Erase the first element equal to a.
Definition: MField.h:514
virtual string getValueAsString(const string &separator=" ")
Get the value of the field as a string.
Definition: MField.h:448
virtual size_t getSize()
Set the value of the field given a string.
Definition: MField.h:529
virtual void erase(typename MField< Type >::const_iterator first, typename MField< Type >::const_iterator last, int id=0)
Erases the range [first, last)
Definition: MField.h:502
This is a field which value can be set by a string from the X3D parser.
Definition: Field.h:371
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
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