00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __X3DBINDABLENODE_H__
00030 #define __X3DBINDABLENODE_H__
00031
00032 #include <iostream>
00033 #include <deque>
00034 #include "X3DChildNode.h"
00035 #include "SFBool.h"
00036 #include "SFTime.h"
00037
00038 namespace H3D {
00039
00108 class H3DAPI_API X3DBindableNode : public X3DChildNode {
00109 public:
00110 typedef std::deque< X3DBindableNode* > StackType;
00111 typedef map< string, StackType> StackMapType;
00112
00115 struct H3DAPI_API SFSetBind : public SFBool {
00116 virtual inline void update() {
00117 SFBool::update();
00118 if( value )
00119 static_cast< X3DBindableNode * >( owner )->toStackTop();
00120 else
00121 static_cast< X3DBindableNode * >( owner )->removeFromStack();
00122 }
00123
00125 inline virtual void setValue( const bool &v, int id = 0 ) {
00126 SFBool::setValue( v, id );
00127 if( value )
00128 static_cast< X3DBindableNode * >( owner )->toStackTop();
00129 else
00130 static_cast< X3DBindableNode * >( owner )->removeFromStack();
00131 }
00132 };
00133
00134
00136 X3DBindableNode( const string &_bindable_stack_name,
00137 Inst< SFSetBind > _set_bind = 0,
00138 Inst< SFNode > _metadata = 0,
00139 Inst< SFTime > _bindTime = 0,
00140 Inst< SFBool > _isBound = 0 );
00141
00143 virtual inline ~X3DBindableNode() {
00144 removeFromStack();
00145 }
00146
00149 static X3DBindableNode * getActive( const string &bindable_stack_name ) {
00150 if ( !stack[bindable_stack_name].empty() )
00151 return stack[bindable_stack_name].front();
00152 else
00153 return 0;
00154 }
00155
00157 static inline const StackType &getStack
00158 ( const string &bindable_stack_name ) {
00159 return stack[ bindable_stack_name ];
00160 }
00161
00163 virtual void toStackTop();
00164
00166 virtual void removeFromStack();
00167
00169 inline bool isStackTop() {
00170 const StackType &s = getStack( bindable_stack_name );
00171 if( s.size() > 0 ) return this == s.front();
00172 else return false;
00173 }
00174
00179 auto_ptr< SFSetBind > set_bind;
00180
00185 auto_ptr< SFTime > bindTime;
00186
00190 auto_ptr< SFBool > isBound;
00191
00193 static H3DNodeDatabase database;
00194
00195 protected:
00196 string bindable_stack_name;
00198 static StackMapType stack;
00199 };
00200 }
00201
00202 #endif