ConfigurationInterface.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Tue Dec 21 22:43:08 CET 2004  ConfigurationInterface.hpp
00003 
00004                         ConfigurationInterface.hpp -  description
00005                            -------------------
00006     begin                : Tue December 21 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 
00039 #ifndef RTT_CONFIGURATIONINTERFACE_HPP
00040 #define RTT_CONFIGURATIONINTERFACE_HPP
00041 
00042 #include <memory>
00043 #include <map>
00044 #include "Attribute.hpp"
00045 #include "internal/DataSources.hpp"
00046 #include "base/DataObjectInterface.hpp"
00047 #include "Property.hpp"
00048 #include "PropertyBag.hpp"
00049 
00050 namespace RTT
00051 {
00060     class RTT_API ConfigurationInterface
00061     {
00062     public:
00063 
00067         ConfigurationInterface();
00068         ~ConfigurationInterface();
00069 
00074         typedef std::vector<std::string> AttributeNames;
00075 
00080         typedef std::vector<base::AttributeBase*> AttributeObjects;
00081 
00085         void clear();
00086 
00090         bool hasAttribute( const std::string& name ) const;
00091 
00100         template<class T>
00101         bool addAttribute( const std::string& name, T& attr) {
00102             if ( !chkPtr("addAttribute", name, &attr) ) return false;
00103             Alias a(name, new internal::ReferenceDataSource<T>(attr));
00104             return this->addAttribute( a );
00105         }
00106 
00114         template<class T>
00115         Attribute<T>& addAttribute( const std::string& name, Attribute<T>& attr) {
00116             if ( !chkPtr("addAttribute", name, &attr) ) return attr;
00117             if ( !attr.ready() )
00118                 attr = Attribute<T>(name);
00119             else
00120                 attr.setName(name);
00121             this->addAttribute( attr );
00122             assert(attr.ready());
00123             return attr;
00124         }
00125 
00134         template<class T>
00135         bool addConstant( const std::string& name, const T& cnst) {
00136             if ( !chkPtr("addConstant", name, &cnst) ) return false;
00137             Alias a(name, new internal::ConstReferenceDataSource<T>(cnst));
00138             return this->addAttribute( a );
00139         }
00140 
00149         template<class T>
00150         Constant<T>& addConstant( const std::string& name, Constant<T>& cnst) {
00151             if ( !chkPtr("addConstant", name, &cnst) ) return cnst;
00152             if ( !cnst.ready() )
00153                 cnst = Constant<T>(name, T());
00154             else
00155                 cnst.setName(name);
00156             this->addConstant( cnst );
00157             assert(cnst.ready());
00158             return cnst;
00159         }
00160 
00170         template<class T>
00171         Property<T>& addProperty( const std::string& name, T& prop) {
00172             if ( !chkPtr("addProperty", name, &prop) ) return internal::NA<Property<T>& >::na();
00173             return this->properties()->addProperty( name, prop );
00174         }
00175 
00183         template<class T>
00184         Property<T>& addProperty( const std::string& name, Property<T>& prop) {
00185             if ( !chkPtr("addProperty", name, &prop) ) return prop;
00186             if ( !prop.ready() )
00187                 prop = Property<T>(name);
00188             else
00189                 prop.setName(name);
00190             this->properties()->addProperty( prop );
00191             assert(prop.ready());
00192             return prop;
00193         }
00194 
00204         bool addAttribute( base::AttributeBase& a )
00205         {
00206             if ( !chkPtr("addAttribute", "AttributeBase", &a) ) return false;
00207             return a.getDataSource() ? setValue( a.clone() ) : false;
00208         }
00209 
00218         base::AttributeBase* getAttribute( const std::string& name ) const
00219         {
00220             return this->getValue( name );
00221         }
00222 
00226         void removeAttribute( const std::string& name );
00227 
00232         bool addConstant( base::AttributeBase& c)
00233         {
00234             return c.getDataSource() ? setValue( c.clone() ) :  false;
00235         }
00236 
00245         base::AttributeBase* getConstant( const std::string& name ) const
00246         {
00247             return this->getValue( name );
00248         }
00249 
00253         bool hasProperty( const std::string& name ) const;
00254 
00260         bool addProperty( base::PropertyBase& pb );
00261 
00266         bool removeProperty( base::PropertyBase& p );
00267 
00275         base::PropertyBase* getProperty(const std::string& name) const
00276         {
00277             return bag.find(name);
00278         }
00279 
00285         bool setValue( base::AttributeBase* ab );
00286 
00296         base::AttributeBase* getValue( const std::string& name ) const;
00297 
00301         bool removeValue(const std::string& name );
00302 
00310         ConfigurationInterface* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& repl, bool instantiate ) const;
00311 
00315         void loadValues( AttributeObjects const& new_values);
00316 
00320         AttributeObjects const& getValues() const {
00321             return values;
00322         }
00323 
00327         AttributeNames getAttributeNames() const;
00328 
00332         PropertyBag* properties();
00333 
00334     protected:
00335         bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
00336         typedef std::vector<base::AttributeBase*> map_t;
00337         map_t values;
00338         PropertyBag bag;
00339     };
00340 }
00341 
00342 #endif


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:51