38 #ifdef ORO_PRAGMA_INTERFACE 39 #pragma implementation 49 #include <boost/scoped_ptr.hpp> 53 using namespace detail;
57 : mproperties(), type(
"PropertyBag")
152 names.push_back( (*i)->getName() );
158 std::vector<std::string> names;
163 names.push_back( (*i)->getName() );
175 if ( (*i)->getName() == name )
176 names.push_back( (*i) );
206 struct FindProp :
public std::binary_function<const base::PropertyBase*,const std::string, bool>
270 if ( _description.empty() )
296 for(
int i=0; i !=
size; ++i) {
312 std::string::size_type start = 0;
313 if ( separator.length() != 0 && nameSequence.find(separator) == 0 )
314 start = separator.length();
315 std::string::size_type len = nameSequence.find(separator, start);
316 if (len != std::string::npos) {
317 token = nameSequence.substr(start,len-start);
318 start = len + separator.length();
319 if ( start >= nameSequence.length() )
320 start = std::string::npos;
323 token = nameSequence.substr(start);
324 start = std::string::npos;
326 result = bag.
find(token);
330 if ( result_bag != 0 && start != std::string::npos ) {
342 void listPropertiesHelper(
const PropertyBag& source,
const std::string& separator,
const string& prefix, vector<string>& result)
347 string itemname = prefix.empty() ? (*it)->
getName() : prefix + separator + (*it)->getName();
348 result.push_back( itemname );
349 if ( sub && sub->
ready() ) {
350 listPropertiesHelper( sub->
value(), separator, itemname, result );
358 void listDescriptionsHelper(
const PropertyBag& source,
const std::string& separator, vector<string>& result)
363 result.push_back( (*it)->getDescription() );
364 if ( sub && sub->
ready() ) {
365 listDescriptionsHelper( sub->
value(), separator, result );
374 vector<string> result;
375 listPropertiesHelper( source, separator,
"", result);
381 vector<string> result;
382 listDescriptionsHelper( source, separator, result);
389 if ( path.empty() || path == separator )
393 if ( path.find(separator) != string::npos ) {
394 pname = path.substr( 0, path.find(separator));
395 rest = path.substr( path.find(separator) + separator.length() );
400 if ( pname.empty() && !rest.empty() )
407 parent = bag.
find(pname);
411 log(
Error) <<
"Path component '" << pname <<
"' in path '"<<path<<
"' does not point to a PropertyBag."<<
endlog();
421 if ( path.empty() || path == separator )
424 if ( path.find( separator ) == string::npos)
427 string prefix = path.substr( 0, path.rfind(separator));
428 string pname = path.substr( path.rfind(separator) + separator.length() );
430 if ( prefix.empty() )
434 if ( !parent.
ready() )
436 return parent.
value().removeProperty( parent.
value().find( pname ) );
443 log(
Debug) <<
"updateProperties: updating Property " 447 log(
Debug) <<
"refreshProperties: refreshing Property " 452 if ( (update && target->
update( source ) == false ) || (!update && target->
refresh( source ) == false ) ) {
466 log(
Error) << (update ?
"updateProperties: " :
"refreshProperties: ") <<
" Could not update, nor convert Property " 468 <<
": type mismatch, can not update with " 477 dummy->getDataSource()->update( converted.get() );
478 assert(dummy->getTypeInfo() == converted->getTypeInfo() );
481 target->
update(dummy.get());
485 << target->
getType() <<
" "<< source->
getName() <<
" to type " <<dummy->getType()
498 log(
Error) <<
"Can not populate typed PropertyBag '"<< target.
getType() <<
"' from '"<<source.
getType()<<
"' (source and target type differed)."<<
endlog();
504 bool failure =
false;
508 if ( (*it)->getName() ==
"" )
511 srcprop = source.
find( (*it)->getName() );
518 }
else if (allprops) {
519 log(
Error) <<
"Could not find Property " 521 <<
" in source."<<
endlog();
533 if ( 0 != (target_prop = target.
find( source.
getName() ) ) )
535 return target_prop->
refresh( &source );
567 log(
Error) <<
"Can not populate typed PropertyBag '"<< target.
getType() <<
"' from '"<<source.
getType()<<
"' (source and target type differed)."<<
endlog();
577 PropertyBag::Names::const_iterator endnames = std::unique(allnames.begin(), allnames.end());
578 PropertyBag::Names::const_iterator it( allnames.begin() );
579 while ( it != endnames )
585 if ( mit != mines.end() ) {
586 assert( (*sit)->getName() == (*mit)->getName());
596 Logger::log() <<
"updateProperties: creating Property " 597 << (*sit)->getType() <<
" "<< (*sit)->getName()
609 if (!res )
return false;
635 std::string::size_type start = 0;
636 if ( separator.length() != 0 && name.find(separator) == 0 )
637 start = separator.length();
638 std::string::size_type len = name.find(separator, start);
639 if (len != std::string::npos) {
640 token = name.substr(start,len-start);
641 start = len + separator.length();
642 if ( start >= name.length() )
643 start = std::string::npos;
646 token = name.substr(start);
647 start = std::string::npos;
649 source_walker = source.
find(token);
650 target_walker = target.
find(token);
651 if (source_walker != 0 )
653 if ( target_walker == 0 ) {
655 target_walker = source_walker->
create();
662 if ( source_walker_bag != 0 && start != std::string::npos ) {
663 if ( target_walker_bag == 0 ) {
678 log(
Error) <<
"Property '"<< token <<
"' is not present in the source PropertyBag !"<<
endlog();
692 std::string::size_type start = 0;
693 if ( separator.length() != 0 && name.find(separator) == 0 )
694 start = separator.length();
695 std::string::size_type len = name.find(separator, start);
696 if (len != std::string::npos) {
697 token = name.substr(start,len-start);
698 start = len + separator.length();
699 if ( start >= name.length() )
700 start = std::string::npos;
703 token = name.substr(start);
704 start = std::string::npos;
706 source_walker = source.
find(token);
707 target_walker = target.
find(token);
708 if (source_walker != 0 )
710 if ( target_walker == 0 ) {
718 if ( source_walker_bag != 0 && start != std::string::npos ) {
719 if ( target_walker_bag == 0 ) {
733 log(
Error) <<
"Property '"<< token <<
"' is not present in the source PropertyBag !"<<
endlog();
785 if ( flat_it != result->
value().getProperties().end() )
787 while (flat_it != result->
value().getProperties().end() )
789 (*flat_it)->setName( result->
getName() + separator + (*flat_it)->getName() );
790 target.
add( (*flat_it) );
791 result->
value().remove( *flat_it );
792 flat_it = result->
value().getProperties().begin();
virtual base::DataSourceBase::shared_ptr getDataSource() const
void remove(base::PropertyBase *p)
bool composeType(base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const
bool updateProperty(PropertyBag &target, const PropertyBag &source, const std::string &name, const std::string &separator)
void add(base::PropertyBase *p)
virtual bool refresh(const base::PropertyBase *other)
bool updateOrRefreshProperty(PropertyBase *source, PropertyBase *target, bool update)
bool updateProperties(PropertyBag &target, const PropertyBag &source)
PropertyBag & operator<<(base::PropertyBase *item)
std::istream & operator>>(std::istream &is, BufferPolicy &bp)
const std::string & getType() const
virtual bool copy(const base::PropertyBase *other)
bool refreshProperties(const PropertyBag &target, const PropertyBag &source, bool allprops)
bool copyProperties(PropertyBag &target, const PropertyBag &source)
void setType(const std::string &newtype)
const_reference_t rvalue() const
virtual PropertyBase * create() const =0
void list(Names &names) const
A container for holding references to properties.
void flattenPropertyBag(PropertyBag &target, const std::string &separator)
bool ownProperty(base::PropertyBase *p)
PropertyBase * findProperty(const PropertyBag &bag, const std::string &nameSequence, const std::string &separator)
virtual bool refresh(const PropertyBase *other)=0
void deletePropertyBag(PropertyBag &target)
PropertyBag & operator<<=(const PropertyBag &source)
Property< T > & addProperty(const std::string &name, T &attr)
base::PropertyBase * find(const std::string &name) const
static std::ostream & endl(std::ostream &__os)
virtual std::string getType() const =0
bool removeProperty(base::PropertyBase *p)
PropertyBag & operator=(const PropertyBag &orig)
const std::string & getDescription() const
base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
Properties & getProperties()
TypeInfoRepository::shared_ptr Types()
Properties::const_iterator const_iterator
basic_ostreams & endl(basic_ostreams &s)
bool refreshProperty(const PropertyBag &target, const PropertyBase &source)
base::PropertyBase * getProperty(const std::string &name) const
vector< string > listProperties(const PropertyBag &source, const std::string &separator)
bool storeProperty(PropertyBag &bag, const std::string &path, base::PropertyBase *item, const std::string &separator)
base::PropertyBase * getItem(int i) const
void identify(base::PropertyIntrospection *pi) const
void deleteProperties(PropertyBag &target)
std::vector< std::string > Names
virtual bool update(const base::PropertyBase *other)
const std::string & getName() const
vector< string > listPropertyDescriptions(const PropertyBag &source, const std::string &separator)
Properties::iterator iterator
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual bool copy(const PropertyBase *other)=0
virtual bool update(const PropertyBase *other)=0
bool ownsProperty(base::PropertyBase *p) const
static Logger::LogFunction endlog()
static bool update(TaskContext *tc)
virtual DataSourceBase::shared_ptr getDataSource() const =0
std::vector< base::PropertyBase * > Properties
virtual const types::TypeInfo * getTypeInfo() const =0