ConfigurationInterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 ConfigurationInterface.cxx
3 
4  ConfigurationInterface.cxx - description
5  -------------------
6  begin : Tue December 21 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 
41 #include "internal/mystd.hpp"
42 #include <functional>
43 #include <boost/bind.hpp>
44 
45 namespace RTT {
46  using namespace detail;
47  using namespace std;
48  using namespace boost;
49 
51  {
52  }
53 
55  {
56  // we do not claim automatically ownership
57  // call clear() manually to delete all contents.
58  }
59 
60  ConfigurationInterface* ConfigurationInterface::copy( std::map<const DataSourceBase*, DataSourceBase*>& repl, bool inst ) const
61  {
63  for ( map_t::const_iterator i = values.begin(); i != values.end(); ++i ) {
64  ar->setValue((*i)->copy( repl, inst ) );
65  }
66  return ar;
67  }
68 
69 
71  {
72  for ( map_t::iterator i = values.begin(); i != values.end(); ++i )
73  delete *i;
74  values.clear();
75  bag.clear();
76  }
77 
79  {
80  if ( !value->getDataSource() || value->getName().empty() )
81  return false;
82  map_t::iterator i = find( values.begin(), values.end(), value );
83  if ( i != values.end() ) {
84  *i = value;
85  } else
86  values.push_back( value );
87  return true;
88  }
89 
91  if ( bag.find( pb.getName() ) )
92  return false;
93  bag.add( &pb );
94  return true;
95  }
96  void ConfigurationInterface::removeAttribute( const std::string& name ) {
97  removeValue(name);
98  }
99 
100  bool ConfigurationInterface::removeValue( const std::string& name )
101  {
102  map_t::iterator i = find_if( values.begin(), values.end(), boost::bind(equal_to<std::string>(),name, boost::bind(&AttributeBase::getName, _1)) );
103  if ( i != values.end() ) {
104  delete (*i);
105  values.erase( i );
106  return true;
107  }
108  return false;
109  }
110 
111  AttributeBase* ConfigurationInterface::getValue( const std::string& name ) const
112  {
113  map_t::const_iterator i = find_if( values.begin(), values.end(), boost::bind(equal_to<std::string>(),name, boost::bind(&AttributeBase::getName, _1)) );
114  if ( i == values.end() ) return 0;
115  else return *i;
116  }
117 
118  bool ConfigurationInterface::hasAttribute( const std::string& name ) const
119  {
120  map_t::const_iterator i = find_if( values.begin(), values.end(), boost::bind(equal_to<std::string>(),name, boost::bind(&AttributeBase::getName, _1)) );
121  return i != values.end();
122  }
123 
124  bool ConfigurationInterface::hasProperty( const std::string& name ) const
125  {
126  return (bag.find(name) != 0);
127  }
128 
130  {
131  if ( bag.find( p.getName() ) ) {
132  bag.remove(&p);
133  return true;
134  }
135  return false;
136  }
137 
138  std::vector<std::string> ConfigurationInterface::getAttributeNames() const
139  {
140  std::vector<std::string> ret;
141  std::transform( values.begin(), values.end(), back_inserter(ret), boost::bind(&AttributeBase::getName, _1) );
142  return ret;
143  }
144 
146  values.insert(values.end(), new_values.begin(), new_values.end());
147  }
148 
149 
151  {
152  return &bag;
153  }
154 }
155 
156 bool RTT::ConfigurationInterface::chkPtr(const std::string & where, const std::string & name, const void *ptr)
157 {
158  if ( ptr == 0) {
159  log(Error) << "You tried to add a null pointer in '"<< where << "' for the object '" << name << "'. Fix your code !"<< endlog();
160  return false;
161  }
162  return true;
163 }
164 
165 
bool setValue(base::AttributeBase *ab)
bool hasAttribute(const std::string &name) const
Definition: mystd.hpp:163
A container for holding references to properties.
Definition: PropertyBag.hpp:96
virtual DataSourceBase::shared_ptr getDataSource() const =0
void removeAttribute(const std::string &name)
void loadValues(AttributeObjects const &new_values)
base::AttributeBase * getValue(const std::string &name) const
bool chkPtr(const std::string &where, const std::string &name, const void *ptr)
A class for keeping track of Attribute, Constant and Property objects of a TaskContext. It allows plugins and remote components to browse the attributes and properties of a TaskContext.
bool removeValue(const std::string &name)
Property< T > & addProperty(const std::string &name, T &prop)
bool hasProperty(const std::string &name) const
AttributeNames getAttributeNames() const
std::vector< base::AttributeBase * > AttributeObjects
const std::string & getName() const
std::vector< typename MapT::mapped_type > values(const MapT &map)
Definition: mystd.hpp:140
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
const std::string & getName() const
Definition: Attribute.cpp:59
ConfigurationInterface * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &repl, bool instantiate) const
bool removeProperty(base::PropertyBase &p)
static Logger & log()
Definition: Logger.hpp:350
static Logger::LogFunction endlog()
Definition: Logger.hpp:362


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32