25 #ifndef WPROPERTYSTRUCT_H
26 #define WPROPERTYSTRUCT_H
31 #include <boost/shared_ptr.hpp>
33 #include <boost/tuple/tuple.hpp>
34 #include <boost/mpl/vector.hpp>
35 #include <boost/mpl/copy.hpp>
36 #include <boost/mpl/size.hpp>
37 #include <boost/mpl/at.hpp>
38 #include <boost/preprocessor/repetition/enum_params.hpp>
40 #include "WStringUtils.h"
41 #include "WCondition.h"
42 #include "WPropertyGroupBase.h"
43 #include "WPropertyBase.h"
44 #include "WPropertyTypes.h"
45 #include "exceptions/WPropertyUnknown.h"
50 namespace WPropertyStructHelper
58 template<
typename T,
typename Tuple>
68 template<
typename T, BOOST_PP_ENUM_PARAMS( 10,
typename T )>
74 typedef boost::tuple< T, BOOST_PP_ENUM_PARAMS( 9, T ) >
type;
82 template<
typename Sequence >
88 typedef typename boost::mpl::reverse_copy<
134 typedef boost::mpl::vector< BOOST_PP_ENUM_PARAMS( 10, T ) >
type;
211 typedef typename boost::shared_ptr< WPropertyStructType >
SPtr;
216 typedef typename boost::shared_ptr< const WPropertyStructType >
ConstSPtr;
278 typename boost::mpl::at< TypeVector, boost::mpl::size_t< N > >::type
getProperty()
280 typedef typename boost::mpl::at< TypeVector, boost::mpl::size_t< N > >::type::element_type TargetType;
281 return boost::dynamic_pointer_cast< TargetType >(
getProperty( N ) );
292 typename boost::mpl::at< TypeVector, boost::mpl::size_t< N > >::type::element_type::ConstSPtr
getProperty()
const
294 typedef typename boost::mpl::at< TypeVector, boost::mpl::size_t< N > >::type::element_type TargetType;
295 return boost::dynamic_pointer_cast<
const TargetType >(
getProperty( N ) );
310 return l->get()[ n ];
325 return l->get()[ n ];
379 if(
size() != propsAsString.size() )
387 size_t curPropNb = 0;
389 for( std::vector< std::string >::const_iterator iter = propsAsString.begin(); iter != propsAsString.end(); ++iter )
391 success = success && l->get()[ curPropNb ]->setAsString( *iter );
409 std::string result =
"";
410 for(
size_t i = 0; i <
size(); ++i )
412 result += l->get()[ i ]->getAsString() +
"|";
415 result.erase( result.length() - 1, 1 );
428 virtual bool set( boost::shared_ptr< WPropertyBase > value,
bool recommendedOnly =
false )
443 for(
size_t curPropNb = 0; curPropNb <
size(); ++curPropNb )
445 success = success && l->get()[ curPropNb ]->set( lother->get()[ curPropNb ], recommendedOnly );
456 static const size_t m_size = boost::mpl::size< TypeVector >::value;
459 #endif // WPROPERTYSTRUCT_H
boost::shared_ptr< const WPropertyStructType > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WPropertyStructType >
WPropertyStruct< BOOST_PP_ENUM_PARAMS(10, T) > WPropertyStructType
The type of this template instantiation.
WPropertyBase::SPtr getProperty(size_t n)
Returns the property with the given number, but only as base type.
std::vector< std::string > tokenize(const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
Splits the given string into a vector of strings (so called tokens).
virtual ~WPropertyStruct()
Destructor.
Convert a list of template parameters to a boost::mpl::vector.
static void createAndAdd(WPropertyGroupBase *group, std::string name, std::string description, const ValueType &initial=ValueType())
Actually does the work and adds a new property with the given name, description and other parameters ...
WPropertyStruct(std::string name, std::string description)
Create an empty named property.
virtual bool set(boost::shared_ptr< WPropertyBase > value, bool recommendedOnly=false)
Sets the value from the specified property to this one.
WPropertyStructHelper::NOTYPE ValueType
The type of the initial value.
boost::tuple< T, BOOST_PP_ENUM_PARAMS(9, T) > type
The resulting tuple type.
PropertySharedContainerType m_properties
The set of proerties.
static void createAndAdd(WPropertyGroupBase *, std::string, std::string, const ValueType &)
Dummy method which does nothing for NOTYPE types.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
WPropertyStructHelper::AsVector< BOOST_PP_ENUM_PARAMS(10, T) >::type TypeVector
The boost mpl vector for all the types specified.
WPropertyStructHelper::SequenceToTuple< TypeVector >::type TupleType
The type vector as a boost tuple.
static const size_t m_size
How many elements are in this WPropertyStruct?
This is the base class and interface for property groups.
Comfortable template to create a property instance and add it to the group.
virtual bool setAsString(std::string value)
This methods allows properties to be set by a string value.
boost::mpl::at< TypeVector, boost::mpl::size_t< N > >::type getProperty()
Get the N'th property in the struct.
boost::mpl::reverse_copy< Sequence, boost::mpl::inserter< boost::tuple<>, PushTypeToTupleFront< boost::mpl::_2, boost::mpl::_1 > > >::type type
This is the tuple type for the sequence.
boost::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a boost::shared_ptr< WPropertyBase >
Converts a boost mpl sequence to a boost tuple.
size_t size() const
The size of the WPropertyStruct.
boost::mpl::na NOTYPE
Alias for default type to emulate variadic templates.
boost::shared_ptr< WPropertyStructType > SPtr
Convenience typedef for a boost::shared_ptr< WPropertyStructType >
boost::mpl::vector< BOOST_PP_ENUM_PARAMS(10, T) > type
The template types as mpl vector.
WPropertyStruct(const WPropertyStructType &from)
Copy constructor.
virtual PROPERTY_TYPE getType() const
Gets the real WPropertyVariable type of this instance.
Class to push a type from a sequence to the front of a tuple type.
This is a property which encapsulates a given, fixed number of other properties.
virtual WPropertyBase::SPtr clone()
This method clones a property and returns the clone.
virtual std::string getAsString()
Returns the current value as a string.
boost::mpl::at< TypeVector, boost::mpl::size_t< N > >::type::element_type::ConstSPtr getProperty() const
Get the N'th property in the struct.
boost::shared_ptr< WSharedObjectTicketRead< PropertyContainerType > > ReadTicket
Type for read tickets.
static void createAndAdd(WPropertyGroupBase *, std::string, std::string)
Dummy method which does nothing for NOTYPE types.
const WPropertyBase::SPtr & getProperty(size_t n) const
Returns the property with the given number, but only as base type.