38 #ifdef ORO_PRAGMA_INTERFACE 39 #pragma implementation 51 using namespace detail;
55 : mproperties(), type(
"PropertyBag")
150 names.push_back( (*i)->getName() );
156 std::vector<std::string> names;
161 names.push_back( (*i)->getName() );
173 if ( (*i)->getName() == name )
174 names.push_back( (*i) );
204 struct FindProp :
public std::binary_function<const base::PropertyBase*,const std::string, bool>
268 if ( _description.empty() )
294 for(
int i=0; i !=
size; ++i) {
310 std::string::size_type start = 0;
311 if ( separator.length() != 0 && nameSequence.find(separator) == 0 )
312 start = separator.length();
313 std::string::size_type len = nameSequence.find(separator, start);
314 if (len != std::string::npos) {
315 token = nameSequence.substr(start,len-start);
316 start = len + separator.length();
317 if ( start >= nameSequence.length() )
318 start = std::string::npos;
321 token = nameSequence.substr(start);
322 start = std::string::npos;
324 result = bag.
find(token);
328 if ( result_bag != 0 && start != std::string::npos ) {
340 void listPropertiesHelper(
const PropertyBag& source,
const std::string& separator,
const string& prefix, vector<string>& result)
345 string itemname = prefix.empty() ? (*it)->
getName() : prefix + separator + (*it)->getName();
346 result.push_back( itemname );
347 if ( sub && sub->
ready() ) {
348 listPropertiesHelper( sub->
value(), separator, itemname, result );
356 void listDescriptionsHelper(
const PropertyBag& source,
const std::string& separator, vector<string>& result)
361 result.push_back( (*it)->getDescription() );
362 if ( sub && sub->
ready() ) {
363 listDescriptionsHelper( sub->
value(), separator, result );
372 vector<string> result;
373 listPropertiesHelper( source, separator,
"", result);
379 vector<string> result;
380 listDescriptionsHelper( source, separator, result);
387 if ( path.empty() || path == separator )
391 if ( path.find(separator) != string::npos ) {
392 pname = path.substr( 0, path.find(separator));
393 rest = path.substr( path.find(separator) + separator.length() );
398 if ( pname.empty() && !rest.empty() )
405 parent = bag.
find(pname);
409 log(
Error) <<
"Path component '" << pname <<
"' in path '"<<path<<
"' does not point to a PropertyBag."<<endlog();
419 if ( path.empty() || path == separator )
422 if ( path.find( separator ) == string::npos)
425 string prefix = path.substr( 0, path.rfind(separator));
426 string pname = path.substr( path.rfind(separator) + separator.length() );
428 if ( prefix.empty() )
432 if ( !parent.
ready() )
434 return parent.
value().removeProperty( parent.
value().find( pname ) );
441 log(
Debug) <<
"updateProperties: updating Property " 445 log(
Debug) <<
"refreshProperties: refreshing Property " 450 if ( (update && target->
update( source ) == false ) || (!update && target->
refresh( source ) == false ) ) {
458 log(
Debug) <<
"Composed Property " 460 <<
" from type " << source->
getType() << endlog();
464 log(
Error) << (update ?
"updateProperties: " :
"refreshProperties: ") <<
" Could not update, nor convert Property " 466 <<
": type mismatch, can not update with " 476 assert(dummy->
getTypeInfo() == converted->getTypeInfo() );
482 log(
Debug) <<
"Converted Property " 484 <<
" from type " << source->
getType() << endlog();
496 log(
Error) <<
"Can not populate typed PropertyBag '"<< target.
getType() <<
"' from '"<<source.
getType()<<
"' (source and target type differed)."<<endlog();
502 bool failure =
false;
506 if ( (*it)->getName() ==
"" )
509 srcprop = source.
find( (*it)->getName() );
516 }
else if (allprops) {
517 log(
Error) <<
"Could not find Property " 519 <<
" in source."<< endlog();
531 if ( 0 != (target_prop = target.
find( source.
getName() ) ) )
533 return target_prop->
refresh( &source );
565 log(
Error) <<
"Can not populate typed PropertyBag '"<< target.
getType() <<
"' from '"<<source.
getType()<<
"' (source and target type differed)."<<endlog();
575 PropertyBag::Names::const_iterator endnames = std::unique(allnames.begin(), allnames.end());
576 PropertyBag::Names::const_iterator it( allnames.begin() );
577 while ( it != endnames )
583 if ( mit != mines.end() ) {
584 assert( (*sit)->getName() == (*mit)->getName());
594 Logger::log() <<
"updateProperties: creating Property " 595 << (*sit)->getType() <<
" "<< (*sit)->getName()
607 if (!res )
return false;
633 std::string::size_type start = 0;
634 if ( separator.length() != 0 && name.find(separator) == 0 )
635 start = separator.length();
636 std::string::size_type len = name.find(separator, start);
637 if (len != std::string::npos) {
638 token = name.substr(start,len-start);
639 start = len + separator.length();
640 if ( start >= name.length() )
641 start = std::string::npos;
644 token = name.substr(start);
645 start = std::string::npos;
647 source_walker = source.
find(token);
648 target_walker = target.
find(token);
649 if (source_walker != 0 )
651 if ( target_walker == 0 ) {
653 target_walker = source_walker->
create();
660 if ( source_walker_bag != 0 && start != std::string::npos ) {
661 if ( target_walker_bag == 0 ) {
662 log(
Error) <<
"Property '"<<target_walker->
getName()<<
"' is not a PropertyBag !"<<endlog();
671 log(
Debug) <<
"Found Property '"<<target_walker->
getName() <<
"': update done." << endlog();
676 log(
Error) <<
"Property '"<< token <<
"' is not present in the source PropertyBag !"<<endlog();
690 std::string::size_type start = 0;
691 if ( separator.length() != 0 && name.find(separator) == 0 )
692 start = separator.length();
693 std::string::size_type len = name.find(separator, start);
694 if (len != std::string::npos) {
695 token = name.substr(start,len-start);
696 start = len + separator.length();
697 if ( start >= name.length() )
698 start = std::string::npos;
701 token = name.substr(start);
702 start = std::string::npos;
704 source_walker = source.
find(token);
705 target_walker = target.
find(token);
706 if (source_walker != 0 )
708 if ( target_walker == 0 ) {
709 log(
Error) <<
"Property '"<<source_walker->
getName()<<
"' was not found in target !"<<endlog();
716 if ( source_walker_bag != 0 && start != std::string::npos ) {
717 if ( target_walker_bag == 0 ) {
718 log(
Error) <<
"Property '"<<target_walker->
getName()<<
"' is not a PropertyBag !"<<endlog();
726 log(
Debug) <<
"Found Property '"<<target_walker->
getName() <<
"': refresh done." << endlog();
731 log(
Error) <<
"Property '"<< token <<
"' is not present in the source PropertyBag !"<<endlog();
783 if ( flat_it != result->
value().getProperties().end() )
785 while (flat_it != result->
value().getProperties().end() )
787 (*flat_it)->setName( result->
getName() + separator + (*flat_it)->getName() );
788 target.
add( (*flat_it) );
789 result->
value().remove( *flat_it );
790 flat_it = result->
value().getProperties().begin();
virtual base::DataSourceBase::shared_ptr getDataSource() const
Get an assignable base::DataSource through which this PropertyBase can be manipulated.
Names list() const
List the names of all properties.
bool updateProperty(PropertyBag &target, const PropertyBag &source, const std::string &name, const std::string &separator)
This function updates (recursively) the values of a single Property object of one Bag with the proper...
void remove(base::PropertyBase *p)
Remove a property from the container.
bool composeType(base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
Compose a type (target) from a DataSourceBase (source) containing its members.
base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const
Automatic conversion: convert a internal::DataSource to this type.
void add(base::PropertyBase *p)
Add a valid property to the container.
virtual bool refresh(const base::PropertyBase *other)
Refresh the value of this Property with the value of an other Property.
bool updateOrRefreshProperty(PropertyBase *source, PropertyBase *target, bool update)
bool updateProperties(PropertyBag &target, const PropertyBag &source)
This function updates (recursively) the values of Property objects of one Bag with the values of Prop...
bool ready() const
Inspect if this Property is correctly initialised and ready for usage.
bool storeProperty(PropertyBag &bag, const std::string &path, base::PropertyBase *item, const std::string &separator)
Stores a property in a bag given a certain path with transfer of ownership.
vector< string > listProperties(const PropertyBag &source, const std::string &separator)
List all properties in a PropertyBag in a single list.
PropertyBag & operator<<(base::PropertyBase *item)
The 'add' operator.
std::istream & operator>>(std::istream &is, BufferPolicy &bp)
const std::string & getType() const
virtual bool copy(const base::PropertyBase *other)
Copy an other Property onto this property.
Base class for all properties.
bool copyProperties(PropertyBag &target, const PropertyBag &source)
This function copies (recursively) the Properties of one Bag into another Bag.
void setType(const std::string &newtype)
const_reference_t rvalue() const
Read-only (const&) access to the value of the Property.
virtual PropertyBase * create() const =0
Create a new default instance of the PropertyBase.
void list(Names &names) const
List the names of all properties.
A container for holding references to properties.
basic_ostreams & endl(basic_ostreams &s)
Flush and newline.
reference_t value()
Access to the value of the Property.
bool ownProperty(base::PropertyBase *p)
Set a property to be owned by this bag.
virtual bool refresh(const PropertyBase *other)=0
Refresh the value of this Property with the value of an other Property.
PropertyBase * findProperty(const PropertyBag &bag, const std::string &nameSequence, const std::string &separator)
This function locates a Property in nested PropertyBags.
void deletePropertyBag(PropertyBag &target)
This function iterates over a PropertyBag and recursively deletes all Property objects.
PropertyBag & operator<<=(const PropertyBag &source)
The update operator.
Property< T > & addProperty(const std::string &name, T &attr)
Adds a variable of any type as a property to this bag.
base::PropertyBase * find(const std::string &name) const
Find the base::PropertyBase with name name.
A simple introspection interface to visit PropertyBags.
vector< string > listPropertyDescriptions(const PropertyBag &source, const std::string &separator)
List all descriptions of properties in a PropertyBag in a single list.
A property represents a named value of any type with a description.
static std::ostream & endl(std::ostream &__os)
~PropertyBag()
Destroy this object and destroy all owned properties.
virtual std::string getType() const =0
Returns the type of this PropertyBase.
bool removeProperty(base::PropertyBase *p)
Remove a property from the container.
PropertyBag & operator=(const PropertyBag &orig)
This assignment assigns all PropertyBases of another bag in this bag, making an exact copy or the ori...
A class for representing a user type, and which can build instances of that type. ...
const std::string & getDescription() const
Get a description of the property.
bool refreshProperty(const PropertyBag &target, const PropertyBase &source)
Refresh one Property in the target bag with the new value.
base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
Build a Property of this type.
Properties & getProperties()
Returns a list of all the property objects in this bag.
TypeInfoRepository::shared_ptr Types()
Obtain a pointer to the global type system.
Properties::const_iterator const_iterator
A const iterator over the Properties.
void flattenPropertyBag(PropertyBag &target, const std::string &separator)
This function flattens a PropertyBag recursively.
An interface which all classes which wish to visit a Property should implement.
base::PropertyBase * getProperty(const std::string &name) const
Get a Property with name name.
base::PropertyBase * getItem(int i) const
Returns the i'th Property, starting from 0.
void identify(base::PropertyIntrospection *pi) const
Identify the contents of this bag through introspection.
void deleteProperties(PropertyBag &target)
This function iterates over a PropertyBag and deletes all Property objects in it without recursion...
Notify the Logger in which 'module' the message occured.
std::vector< std::string > Names
The container to hold names of Properties.
static Logger & log()
As Instance(), but more userfriendly.
virtual bool update(const base::PropertyBase *other)
Update the value of this Property with the value of an other Property.
const std::string & getName() const
Get the name of the property.
Properties::iterator iterator
An iterator over the Properties.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
size_t size() const
Get the number of Properties in this bag.
virtual bool copy(const PropertyBase *other)=0
Copy an other Property onto this property.
PropertyBag()
The default constructor.
bool refreshProperties(const PropertyBag &target, const PropertyBag &source, bool allprops)
This function refreshes the values of the properties in one PropertyBag with the values of the proper...
virtual bool update(const PropertyBase *other)=0
Update the value of this Property with the value of an other Property.
bool ownsProperty(base::PropertyBase *p) const
Returns true if this property is owned by this Bag.
void clear()
Removes all PropertyBases from this bag, without deleting them.
virtual DataSourceBase::shared_ptr getDataSource() const =0
Get an assignable base::DataSource through which this PropertyBase can be manipulated.
std::vector< base::PropertyBase * > Properties
The container in which the properties are stored.
virtual const types::TypeInfo * getTypeInfo() const =0
Returns the types::TypeInfo object of this Property.