12 template <
typename DataType>
17 virtual void setValue(
const DataType& value ) = 0;
18 virtual std::unique_ptr<SetValueInterface<DataType>> clone()
const = 0;
21 template <
typename DataType>
25 using SetterMethodType = std::function<void(
const DataType& )>;
27 SetterMethodCB( SetterMethodType setterMethod ) { m_setterMethod = setterMethod; }
29 void setValue(
const DataType& value )
31 CAFFA_ASSERT( m_setterMethod );
32 m_setterMethod( value );
35 virtual std::unique_ptr<SetValueInterface<DataType>> clone()
const
37 return std::make_unique<SetterMethodCB<DataType>>( m_setterMethod );
41 SetterMethodType m_setterMethod;
44 template <
typename DataType>
49 virtual DataType getValue()
const = 0;
50 virtual std::unique_ptr<GetValueInterface<DataType>> clone()
const = 0;
53 template <
typename DataType>
57 using GetterMethodType = std::function<DataType()>;
59 GetterMethodCB( GetterMethodType setterMethod ) { m_getterMethod = setterMethod; }
61 DataType getValue()
const {
return m_getterMethod(); }
63 virtual std::unique_ptr<GetValueInterface<DataType>> clone()
const
65 return std::make_unique<GetterMethodCB<DataType>>( m_getterMethod );
69 GetterMethodType m_getterMethod;
72 template <
typename DataType>
76 std::unique_ptr<DataFieldAccessor<DataType>>
clone()
const override
78 auto copy = std::make_unique<FieldProxyAccessor>();
79 copy->m_valueSetter = std::move( m_valueSetter->clone() );
80 copy->m_valueGetter = std::move( m_valueGetter->clone() );
86 if ( !m_valueGetter )
throw std::runtime_error(
"No getter for field" );
87 return m_valueGetter->getValue();
92 if ( !m_valueSetter )
throw std::runtime_error(
"No setter for field" );
93 m_valueSetter->setValue(
value );
101 void registerSetMethod(
typename SetterMethodCB<DataType>::SetterMethodType setterMethod )
103 m_valueSetter = std::make_unique<SetterMethodCB<DataType>>( setterMethod );
106 void registerGetMethod(
typename GetterMethodCB<DataType>::GetterMethodType getterMethod )
108 m_valueGetter = std::make_unique<GetterMethodCB<DataType>>( getterMethod );
111 bool hasSetter()
const {
return m_valueSetter !=
nullptr; }
112 bool hasGetter()
const {
return m_valueGetter !=
nullptr; }
115 std::unique_ptr<SetValueInterface<DataType>> m_valueSetter;
116 std::unique_ptr<GetValueInterface<DataType>> m_valueGetter;
Abstract but typed data field accessor. Inherit to create different storage mechanisms.
Definition: cafDataFieldAccessor.h:43
Definition: cafFieldProxyAccessor.h:74
DataType value() override
Get the field value.
Definition: cafFieldProxyAccessor.h:84
void setValue(const DataType &value) override
Set the value with the accessor. Will throw a std::runtime_exception if the accessor has limits and t...
Definition: cafFieldProxyAccessor.h:90
std::unique_ptr< DataFieldAccessor< DataType > > clone() const override
Clone the accessor using polymorphism.
Definition: cafFieldProxyAccessor.h:76
Definition: cafFieldProxyAccessor.h:46
Definition: cafFieldProxyAccessor.h:55
Definition: cafFieldProxyAccessor.h:14
Definition: cafFieldProxyAccessor.h:23
Main Caffa namespace.
Definition: __init__.py:1