Commit 2d2204b4 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - some fine tuning in properties.

[ADD] - simple value copy function which works correctly with dynamic types
parent ccbdc8c8
......@@ -88,6 +88,11 @@ std::string WProperties::getAsString()
return "";
}
bool WProperties::set( boost::shared_ptr< WPropertyBase > /*value*/ )
{
return true;
}
bool WProperties::propNamePredicate( boost::shared_ptr< WPropertyBase > prop1, boost::shared_ptr< WPropertyBase > prop2 ) const
{
return ( prop1->getName() == prop2->getName() );
......
......@@ -263,6 +263,18 @@ public:
*/
virtual std::string getAsString();
/**
* Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
* dynamic type of the property.
*
* \note for WProperties, this actually does nothing an.
*
* \param value the new value.
*
* \return true, always.
*/
virtual bool set( boost::shared_ptr< WPropertyBase > value );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Convenience methods to create and add properties
// NOTE: these methods use the type of the initial parameter to automatically use the proper type.
......
......@@ -166,6 +166,16 @@ public:
*/
virtual boost::shared_ptr< WCondition > getUpdateCondition() const;
/**
* Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
* dynamic type of the property.
*
* \param value the new value.
*
* \return true if the value has been accepted.
*/
virtual bool set( boost::shared_ptr< WPropertyBase > value ) = 0;
/////////////////////////////////////////////////////////////////////////////////////////////
// Helpers for easy conversion to the possible types
/////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -374,6 +374,29 @@ public:
*/
virtual std::string getAsString();
/**
* Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
* dynamic type of the property.
*
* \param value the new value.
*
* \return true if the value has been accepted.
*/
virtual bool set( boost::shared_ptr< WPropertyBase > value );
/**
* Sets the new value for this flag. Also notifies waiting threads. After setting a value, changed() will be true.
*
* \param value the new value
* \param suppressNotification true to avoid a firing condition. This is useful for resetting values.
*
* \return true if the value has been set successfully.
*
* \note set( get() ) == true
* \note this is defined here to help the compiler to disambiguate between WFlag::set and the WPropertyBase::set.
*/
virtual bool set( T value, bool suppressNotification = false );
protected:
/**
......@@ -558,7 +581,7 @@ bool WPropertyVariable< T >::setAsString( std::string value )
{
// use the helper class which can handle different kinds of properties for us
PROPERTY_TYPE_HELPER::WCreateFromString< T > h = PROPERTY_TYPE_HELPER::WCreateFromString< T >();
set( h.create( WFlag< T >::get(), value ) );
WFlag< T >::set( h.create( WFlag< T >::get(), value ) );
}
catch( const boost::bad_lexical_cast &e )
{
......@@ -578,6 +601,27 @@ std::string WPropertyVariable< T >::getAsString()
return val;
}
template < typename T >
bool WPropertyVariable< T >::set( boost::shared_ptr< WPropertyBase > value )
{
// try to cast the given property to a WPropertyVariable of right type:
boost::shared_ptr< WPropertyVariable< T > > v = boost::shared_dynamic_cast< WPropertyVariable< T > >( value );
if ( v )
{
return WFlag< T >::set( v->get() );
}
else
{
return false;
}
}
template < typename T >
bool WPropertyVariable< T >::set( T value, bool suppressNotification )
{
return WFlag< T >::set( value, suppressNotification );
}
template < typename T >
bool WPropertyVariable< T >::ensureValidity( T newValidValue, bool suppressNotification )
{
......
......@@ -297,7 +297,7 @@ void WMTemplate::properties()
// In more detail, the purpose type of the property gets set to PV_PURPOSE_INFORMATION automatically by m_infoProperties. You can, of course,
// add information properties to your custom groups or m_properties too. There, you need to set the purpose flag of the property manually:
std::string message = std::string( "Hey you! Besides all these parameters, you also can print values, html formatted strings, colors and " ) +
std::string( "so on using <font color=\"#f00\">properties</font>! Isn't it <b>amazing</b>?" );
std::string( "so on using <font color=\"#ff0000\">properties</font>! Isn't it <b>amazing</b>?" );
m_aStringOutput = m_group1a->addProperty( "A Message", "A message to the user.", message );
m_aStringOutput->setPurpose( PV_PURPOSE_INFORMATION );
// This adds the property m_aStringOutput to your group and sets its purpose. The default purpose for all properties is always
......@@ -305,13 +305,12 @@ void WMTemplate::properties()
// parameter.
//
// Some more examples. Please note: Although every property type can be used as information property, not everything is really useful.
m_infoProperties->addProperty( m_aStringOutput ); // we can also re-add properties
m_aTriggerOutput = m_infoProperties->addProperty( "A Trigger", "Trigger As String", WPVBaseTypes::PV_TRIGGER_READY );
m_aDoubleOutput = m_infoProperties->addProperty( "Some Double", "a Double. Nice isn't it?", 3.1415 );
m_aColorOutput = m_infoProperties->addProperty( "A Color", "Some Color. Nice isn't it?", WColor( 0.5, 0.5, 1.0, 1.0 ) );
m_aFilenameOutput = m_infoProperties->addProperty( "Nice File", "a Double. Nice isn't it?", WKernel::getAppPathObject() );
m_aSelectionOutput = m_infoProperties->addProperty( "A Selection", "Selection As String", m_possibleSelections->getSelectorFirst() );
// We can add info another property here too:
m_infoProperties->addProperty( m_aStringOutput );
}
void WMTemplate::moduleMain()
......@@ -329,7 +328,7 @@ void WMTemplate::moduleMain()
// useful whenever your module needs to do long operations to initialize. No other module can connect to your module before it signals its
// ready state. You can assume the code before ready() to be some kind of initialization code.
debugLog() << "Doing time consuming operations";
sleep( 0 );
sleep( 2 );
// Your module can use an moduleState variable to wait for certain events. Most commonly, these events are new data on input connectors or
// changed properties. You can decide which events the moduleState should handle. Therefore, use m_moduleState.add( ... ) to insert every
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment