Commit 8b5f9537 authored by schurade's avatar schurade
Browse files

Merge with dd7dfe1ce873d058389c2bb766fecd7608058bbe

parents f1ab77c5 8013822c
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WProperty2.h"
WProperty2::WProperty2( std::string name, std::string description ):
m_name( name ),
m_description( description )
{
// initialize members
}
WProperty2::~WProperty2()
{
// clean up
}
std::string WProperty2::getName() const
{
return m_name;
}
std::string WProperty2::getDescription() const
{
return m_description;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WPROPERTY2_H
#define WPROPERTY2_H
#include <string>
#include "WPropertyTypes.h"
/**
* Class managing a single named property.
*/
class WProperty2
{
public:
/**
* Create an empty instance just containing a name.
*
* \param name the property name
* \param description the property description
*/
WProperty2( std::string name, std::string description );
/**
* Destructor.
*/
virtual ~WProperty2();
/**
* Get the name of the property.
*
* \return the name.
*/
std::string getName() const;
/**
* Get the description of the property.
*
* \return the description.
*/
std::string getDescription() const;
/**
* Returns the actual type of the property. This is needed to identify all subclassed types.
*
* \return the type.
*/
virtual PROPERTY_TYPE getType() const = 0;
protected:
/**
* Name of the property.
*/
std::string m_name;
/**
* Description of the property.
*/
std::string m_description;
private:
};
#endif // WPROPERTY2_H
......@@ -30,13 +30,14 @@
#include <string>
#include <typeinfo>
#include "WProperty2.h"
#include "WFlag.h"
#include "WCondition.h"
/**
* A named property class with a concrete type.
*/
template< typename T >
class WPropertyVariable: public WProperty2
class WPropertyVariable: public WFlag< T >
{
public:
......@@ -47,46 +48,146 @@ public:
* \param description the property description
* \param initial the initial value
*/
WPropertyVariable( std::string name, std::string description, const T& initial ):
WProperty2( name, description )
{
// initialize everything
}
WPropertyVariable( std::string name, std::string description, const T& initial );
/**
* Create an empty instance just containing a name. This constructor allows an external condition to be used for notifiaction.
* This is practical if one would like to share a condition among several properties.
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param condition use this external condition for notification.
*/
WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition );
/**
* Create an empty instance just containing a name. This constructor allows an external callback to be used for notification.
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param notifier use this notifier for change callbacks.
*
* \note: instead of setting another notifier, you should consider using the callbacks the condition offers.
* \note: the notifiers gets connected to the notification callback of the internal condition. So be careful when using the
* condition ( getCondition() ) for other properties, since they would also share the callbacks
*
*/
WPropertyVariable( std::string name, std::string description, const T& initial, WCondition::t_ConditionNotifierType notifier );
/**
* Create an empty instance just containing a name. This constructor allows an external callback and condition to be used for notification.
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param notifier use this notifier for change callbacks.
* \param condition use this external condition for notification
*
* \note: instead of setting another notifier, you should consider using the callbacks the condition offers.
* \note: the notifiers gets connected to the notification callback of the internal condition. So be careful when using the
* condition ( getCondition() ) for other properties, since they would also share the callbacks
*
*/
WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition,
WCondition::t_ConditionNotifierType notifier );
/**
* Destructor.
*/
virtual ~WPropertyVariable()
{
// clean up
}
T& get() const
{
return m_value;
}
void set( T& val )
{
m_value = val;
}
virtual PROPERTY_TYPE getType() const
{
if ( typeid( T ) == typeid( int ) )
return INT;
else
return INT;
}
virtual ~WPropertyVariable();
/**
* Gets the name of the class.
*
* \return the name.
*/
std::string getName();
/**
* Gets the description of the property.
*
* \return the description
*/
std::string getDescription();
protected:
/**
* The actual variable handled by this property.
* Name of the property.
*/
std::string m_name;
/**
* Description of the property.
*/
T m_value;
std::string m_description;
/**
* The connection used for notification.
*/
boost::signals2::connection m_notifierConnection;
private:
};
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial ):
WFlag< T >( new WCondition(), initial ),
m_name( name ),
m_description( description )
{
}
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition ):
WFlag< T >( condition, initial ),
m_name( name ),
m_description( description )
{
}
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial,
WCondition::t_ConditionNotifierType notifier ):
WFlag< T >( new WCondition(), initial ),
m_name( name ),
m_description( description )
{
// set custom notifier
m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier );
}
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition,
WCondition::t_ConditionNotifierType notifier ):
WFlag< T >( condition, initial ),
m_name( name ),
m_description( description )
{
// set custom notifier
m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier );
}
template < typename T >
WPropertyVariable< T >::~WPropertyVariable()
{
// clean up
m_notifierConnection.disconnect();
}
template < typename T >
std::string WPropertyVariable< T >::getName()
{
return m_name;
}
template < typename T >
std::string WPropertyVariable< T >::getDescription()
{
return m_description;
}
#endif // WPROPERTYVARIABLE_H
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