X3DBindableNode.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
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

Generated on Thu Aug 24 12:38:35 2006 for H3D API by  doxygen 1.4.5