Commit a3b86f3e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #174] further minor improvements.

parent 102bd5c6
......@@ -46,8 +46,8 @@ class WItemSelector;
* not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid
* automatically using the change condition of the inherited WSharedSequenceContainer.
*/
class WItemSelection: public boost::enable_shared_from_this< WItemSelection >, public WSharedSequenceContainer<
std::vector< boost::shared_ptr< WItemSelectionItem > > >
class WItemSelection: public boost::enable_shared_from_this< WItemSelection >,
public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >
{
friend class WItemSelector; // for proper locking and unlocking
public:
......@@ -117,8 +117,7 @@ public:
*
* \return the Item.
*/
static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "",
const char** icon = NULL )
static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL )
{
return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) );
}
......@@ -144,3 +143,4 @@ private:
};
#endif // WITEMSELECTION_H
......@@ -73,7 +73,19 @@ public:
*
* \return Returns the converted item of new type T or 0 if a conversion is not possible.
*/
template< typename T > T* getAs()
template< typename T >
T* getAs()
{
return dynamic_cast< T* >( this );
}
/**
* Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection.
*
* \return Returns the converted item of new type T or 0 if a conversion is not possible.
*/
template< typename T >
const T* getAs() const
{
return dynamic_cast< T* >( this );
}
......
......@@ -32,8 +32,13 @@
/**
* A derivation of WItemSelection which can store a value of any type.
*
* \note you can specify a reference type too. When using MyType& as type in this class, you can avoid unnecessary copy operations.
*
* \tparam the type to encapsulate
*/
template< typename T > class WItemSelectionItemTyped: public WItemSelectionItem // NOLINT
template< typename T >
class WItemSelectionItemTyped: public WItemSelectionItem // NOLINT
{
public:
/**
......@@ -45,7 +50,8 @@ public:
* \param icon Icon, can be NULL.
*/
WItemSelectionItemTyped( T value, std::string name, std::string description = "", const char** icon = NULL ) :
WItemSelectionItem( name, description, icon ), m_value( value )
WItemSelectionItem( name, description, icon ),
m_value( value )
{
}
......@@ -56,12 +62,22 @@ public:
{
}
/**
* Returns the value. This const version is especially useful when using reference types for T.
*
* \return Value which is stored.
*/
const T getValue() const
{
return m_value;
}
/**
* Returns the value.
*
* \return Value which is stored.
*/
T getValue() const
T getValue()
{
return m_value;
}
......
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