00001 /*************************************************************************** 00002 tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 AttributeRepository.hpp 00003 00004 AttributeRepository.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 ATTRIBUTEREPOSITORY_HPP 00040 #define ATTRIBUTEREPOSITORY_HPP 00041 00042 #include <memory> 00043 #include <map> 00044 #include "Attribute.hpp" 00045 #include "DataSources.hpp" 00046 #include "DataObjectInterfaces.hpp" 00047 #include "Property.hpp" 00048 #include "PropertyBag.hpp" 00049 00050 namespace RTT 00051 { 00058 class AttributeRepository 00059 { 00060 typedef std::vector<AttributeBase*> map_t; 00061 map_t values; 00065 mutable PropertyBag* bag; 00066 00067 public: 00068 00072 AttributeRepository(); 00073 ~AttributeRepository(); 00074 00079 typedef std::vector<std::string> AttributeNames; 00080 00085 typedef std::vector<AttributeBase*> AttributeObjects; 00086 00090 void clear(); 00091 00095 bool hasAttribute( const std::string& name ) const; 00096 00103 bool addAttribute( AttributeBase* a ) 00104 { 00105 return a->getDataSource() && setValue( a->clone() ); 00106 } 00107 00118 template<class T> 00119 Attribute<T>* getAttribute( const std::string& name ) const 00120 { 00121 return dynamic_cast<Attribute<T>*>( this->getValue( name ) ); 00122 } 00123 00127 void removeAttribute( const std::string& name ); 00128 00133 bool addConstant( AttributeBase* c) 00134 { 00135 return c->getDataSource() && setValue( c->clone() ); 00136 } 00137 00146 template<class T> 00147 Constant<T>* getConstant( const std::string& name ) const 00148 { 00149 return dynamic_cast<Constant<T>*>( this->getValue( name ) ); 00150 } 00151 00155 bool hasProperty( const std::string& name ) const; 00156 00162 bool addProperty( PropertyBase* pb ); 00163 00168 bool removeProperty( PropertyBase* p ); 00169 00175 bool setValue( AttributeBase* ab ); 00176 00186 AttributeBase* getValue( const std::string& name ) const; 00187 00191 bool removeValue(const std::string& name ); 00192 00200 template<class T> 00201 bool addDataObject( DataObjectInterface<T>* doi) { 00202 return this->setValue( new Alias<T>(doi, doi->getName() )); 00203 } 00204 00212 AttributeRepository* copy( std::map<const DataSourceBase*, DataSourceBase*>& repl, bool instantiate ) const; 00213 00218 AttributeNames names() const; 00219 00223 AttributeNames getAttributes() const; 00224 00231 PropertyBag* properties() const; 00232 00233 }; 00234 } 00235 00236 #endif
1.5.8