PropertyBagIntrospector.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Apr 22 20:40:57 CEST 2004  PropertyBagIntrospector.hpp
00003 
00004                         PropertyBagIntrospector.hpp -  description
00005                            -------------------
00006     begin                : Thu April 22 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 #ifndef PROPERTYBAGINTROSPECTOR
00039 #define PROPERTYBAGINTROSPECTOR
00040 
00041 #include "PropertyBag.hpp"
00042 #include "Property.hpp"
00043 #include "PropertyIntrospection.hpp"
00044 #include <stack>
00045 
00046 #ifdef ORO_PRAGMA_INTERFACE
00047 #pragma interface
00048 #endif
00049 
00050 namespace RTT
00051 {
00052 
00057     class RTT_API PropertyBagIntrospector
00058         : public PropertyBagVisitor
00059     {
00060         std::stack<PropertyBag*> mystack;
00061     public:
00069         PropertyBagIntrospector( PropertyBag& bag )
00070         {
00071             mystack.push( &bag );
00072         }
00073 
00074         virtual ~PropertyBagIntrospector()
00075         {
00076             mystack.pop();
00077         }
00078 
00083         void reset( PropertyBag& new_bag)
00084         {
00085             mystack.pop();
00086             mystack.push( &new_bag );
00087         }
00088 
00089 
00094         void introspect(const PropertyBag& v )
00095         {
00096             v.identify(this);
00097         }
00098 
00099         virtual void introspect(PropertyBase* v)
00100         {
00101             // if it is decomposable, identify a new bag, otherwise add a clone.
00102             Property<PropertyBag> res(v->getName(), v->getDescription() );
00103             if ( v->getTypeInfo()->decomposeType( v->getDataSource(), res.value() ))
00104                 res.identify( this );
00105             else
00106                 mystack.top()->add( v->clone() );
00107             deleteProperties(res.value());
00108         }
00109 
00110         virtual void introspect(Property<PropertyBag> &v)
00111         {
00112             PropertyBag* cur_bag = mystack.top();
00113             Property<PropertyBag>* bag_cl
00114                 = new Property<PropertyBag>( v.getName(),
00115                                              v.getDescription(),
00116                                              PropertyBag( v.get().getType() ) );
00117             cur_bag->add( bag_cl );
00118 
00119             mystack.push( &bag_cl->value() );
00120 
00121             v.value().identify(this);
00122 
00123             mystack.pop();
00124         }
00125     };
00126 }
00127 
00128 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3