31 #ifndef __H3DNODEDATABSE_H__
32 #define __H3DNODEDATABSE_H__
43 #define FIELDDB_ELEMENT( base, field, access ) \
44 FieldDBInsert field( access( &base::database, #field, &base::field ) );
47 #define FIELDDB_ELEMENT_EX( base, field, access, fieldst ) \
48 FieldDBInsert fieldst( access( &base::database, #fieldst, &base::field ) );
53 typedef Node*( *H3DCreateNodeFunc)();
55 struct H3DNodeDatabase;
110 if( ptr && n == ptr->getOwner() )
122 template<
class N,
class F >
127 H3DUniquePtr<F> N:: *_ptr ) :
133 const N *node =
dynamic_cast<const N*
>(n);
135 return (node->*
ptr).get();
141 const H3DUniquePtr<F> N:: *
ptr;
145 template<
class N,
class F >
147 const std::string& _name,
148 H3DUniquePtr<F> N:: *_ptr ) {
156 template<
class N,
class F >
158 const std::string &_name,
159 H3DUniquePtr<F> N:: *_ptr ) {
166 template<
class N,
class F >
168 const std::string &_name,
169 H3DUniquePtr<F> N:: *_ptr ) {
177 template<
class N,
class F >
179 const std::string &_name,
180 H3DUniquePtr<F> N:: *_ptr ) {
198 const std::type_info& t;
206 return t.before (o.t) != 0;
210 typedef map< string, FieldDBElement* > FieldDBType;
211 typedef map< TypeInfoWrapper, H3DNodeDatabase* > H3DNodeDatabaseType;
212 typedef H3DNodeDatabaseType::const_iterator NodeDatabaseConstIterator;
246 if( status == INHERITED )
247 return *(*inherited_iterator);
250 return (*local_iterator).first;
255 if( status == INHERITED )
256 return (*inherited_iterator).getFieldDBElement();
259 return (*local_iterator).second;
264 if( status == INHERITED )
265 return (*inherited_iterator).getField( n );
268 return (*local_iterator).second->getField( n ) ;
307 H3DCreateNodeFunc _createf,
308 const type_info &_ti,
315 const string &_alias,
316 H3DCreateNodeFunc _createf,
317 const type_info &_ti,
334 aliases.push_back( alias );
341 static Node *createNode(
const string &name );
356 if( createf )
return createf();
369 bool removeField (
const string& _name,
Node* _node= NULL );
373 Field *getField(
const Node * n,
const string& f )
const;
377 void initFields(
Node* )
const;
380 void clearDynamicFields();
384 void clearDynamicFields(
Node *n );
388 Field *getFieldHelp(
const Node * n,
const string& f )
const;
394 const H3DCreateNodeFunc createf;
406 static bool initialized;
410 list< string > aliases;
419 static NodeDatabaseConstIterator
begin() {
420 return database->begin();
424 static NodeDatabaseConstIterator
end() {
425 return database->end();
442 return fields.size();
455 typedef map< const Node *, H3DNodeDatabase* > H3DNodeInstanceDatabase;
459 H3DNodeInstanceDatabase node_instance_database;
460 bool database_allocated_dynamic;
464 struct FieldDBInsert {
465 FieldDBInsert( FieldDBElement *f ) {
466 f->getContainer()->addField( f );
Contains the Field class.
Base header file that handles all configuration related settings.
The Field class.
Definition: Field.h:46
AccessType
The different access types that a field can have.
Definition: Field.h:53
@ INPUT_OUTPUT
No restrictions on access to the field values or routes.
Definition: Field.h:69
@ INPUT_ONLY
The value of the field can only set, not read.
Definition: Field.h:67
@ INITIALIZE_ONLY
The value of the field can only be changed before the Node that is the owner of the field has been in...
Definition: Field.h:57
@ OUTPUT_ONLY
The value of the field can only read, not set.
Definition: Field.h:62
The FieldDBConstIterator is an iterator class used for iterating over the field instances in an H3DNo...
Definition: H3DNodeDatabase.h:217
H3DUniquePtr< FieldDBConstIterator > inherited_iterator
Iterator used for iterating through the fields inherited from the parent database if it exists.
Definition: H3DNodeDatabase.h:296
Status
Defines the status of the iterator.
Definition: H3DNodeDatabase.h:277
@ INHERITED
The iterator is currently iterating through the field definitions of the inherited database fields.
Definition: H3DNodeDatabase.h:283
@ LOCAL
The iterator is currently iterating through the local field definitions.
Definition: H3DNodeDatabase.h:280
Status status
The status of the iterator.
Definition: H3DNodeDatabase.h:290
string operator*()
Dereference operator.
Definition: H3DNodeDatabase.h:245
FieldDBElement * getFieldDBElement()
Get the FieldDBElement associated with the iterator.
Definition: H3DNodeDatabase.h:254
bool operator!=(FieldDBConstIterator iter)
Not equals operator.
Definition: H3DNodeDatabase.h:240
H3DNodeDatabase * ndb
The database which fields this iterator iterates through.
Definition: H3DNodeDatabase.h:298
Field * getField(Node *n)
Get the Field * associated with the iterator.
Definition: H3DNodeDatabase.h:263
FieldDBConstIterator & operator++(int)
Pre-increment operator.
Definition: H3DNodeDatabase.h:229
FieldDBType::const_iterator local_iterator
Iterator used for iterating through the local fields in the H3DNodeDatabase.Only valid if status == L...
Definition: H3DNodeDatabase.h:293
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
bool operator==(const DualQuaternion &q1, const DualQuaternion &q2)
H3D API namespace.
Definition: Anchor.h:38
FieldDBTemplate< N, F > * INPUT_OUTPUT(H3DNodeDatabase *_container, const std::string &_name, H3DUniquePtr< F > N::*_ptr)
Specialization to handle case where access type is INPUT_OUTPUT.
Definition: H3DNodeDatabase.h:178
FieldDBTemplate< N, F > * OUTPUT_ONLY(H3DNodeDatabase *_container, const std::string &_name, H3DUniquePtr< F > N::*_ptr)
Specialization to handle case where access type is OUTPUT_ONLY.
Definition: H3DNodeDatabase.h:157
FieldDBTemplate< N, F > * INITIALIZE_ONLY(H3DNodeDatabase *_container, const std::string &_name, H3DUniquePtr< F > N::*_ptr)
Specialization to handle case where access type is INITIALIZE_ONLY.
Definition: H3DNodeDatabase.h:146
FieldDBTemplate< N, F > * INPUT_ONLY(H3DNodeDatabase *_container, const std::string &_name, H3DUniquePtr< F > N::*_ptr)
Specialization to handle case where access type is INPUT_ONLY.
Definition: H3DNodeDatabase.h:167
The DynamicFieldDBElement is a FieldDBElement for fields that are not actual members of a Node class,...
Definition: H3DNodeDatabase.h:100
Field * ptr
The pointer to the field.
Definition: H3DNodeDatabase.h:117
virtual Field * getField(const Node *n) const
Given a Node get a pointer to the field in that node that is represented by this FieldDBElement.
Definition: H3DNodeDatabase.h:109
A FieldDBElement is an encapsulation of a field in a H3DNodeDatabase.
Definition: H3DNodeDatabase.h:58
FieldDBElement(H3DNodeDatabase *_container, const string &_name, const Field::AccessType _access)
Constructor.
Definition: H3DNodeDatabase.cpp:255
Field::AccessType getAccessType()
Get the access type of the field.
Definition: H3DNodeDatabase.h:82
H3DNodeDatabase * getContainer()
Get the H3DNodeDatabase this instance is part of.
Definition: H3DNodeDatabase.h:72
const string & getName()
Get the name of the field.
Definition: H3DNodeDatabase.h:77
virtual Field * getField(const Node *) const
Given a Node get a pointer to the field in that node that is represented by this FieldDBElement.
Definition: H3DNodeDatabase.h:88
virtual ~FieldDBElement()
Destructor.
Definition: H3DNodeDatabase.h:69
Template class for specifying specialized FieldDBElement instances.
Definition: H3DNodeDatabase.h:123
const H3DUniquePtr< F > N::* ptr
The member pointer in the node for the field.
Definition: H3DNodeDatabase.h:141
virtual Field * getField(const Node *n) const
Given a Node get a pointer to the field in that node that is represented by this FieldDBElement.
Definition: H3DNodeDatabase.h:132
Wrapper class to be able to put type_info as a key in a map.
Definition: H3DNodeDatabase.h:197
TypeInfoWrapper(const std::type_info &t_)
Constructor.
Definition: H3DNodeDatabase.h:201
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
void addAlias(const string &alias)
Add an alias for the node in the database.
Definition: H3DNodeDatabase.h:333
FieldDBConstIterator fieldDBEnd()
Returns an iterator pointing at the end of fields in the H3DNodeDatabase.
Definition: H3DNodeDatabase.h:435
const type_info & getTypeInfo()
Get the type_info of the node in the database object.
Definition: H3DNodeDatabase.h:349
size_t fieldDBSize()
Returns the number of fields in the H3DNodeDatabase.
Definition: H3DNodeDatabase.h:440
const string & getName()
Get the name of the node in the database object.
Definition: H3DNodeDatabase.h:344
static H3DNodeDatabaseType * database
The database with all H3DNodeDatabase instances.
Definition: H3DNodeDatabase.h:414
FieldDBConstIterator fieldDBBegin()
Gets an iterator to the beginning first field in the H3DNodeDatabase.
Definition: H3DNodeDatabase.h:430
Node * createNode()
Create a new instance of the node type the database object refers to.
Definition: H3DNodeDatabase.h:355
static NodeDatabaseConstIterator begin()
Iterator to the first element in the database.
Definition: H3DNodeDatabase.h:419
static NodeDatabaseConstIterator end()
Returns an iterator pointing at the end of the H3DNodeDatabase created.
Definition: H3DNodeDatabase.h:424