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();
90 void setValue(
const DataType& value )
override 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 override {
return m_valueSetter !=
nullptr; }
112 bool hasGetter()
const override {
return m_valueGetter !=
nullptr; }
115 std::unique_ptr<SetValueInterface<DataType>> m_valueSetter;
116 std::unique_ptr<GetValueInterface<DataType>> m_valueGetter;
Definition: cafFieldProxyAccessor.h:22
Definition: cafFieldProxyAccessor.h:13
bool hasSetter() const override
Definition: cafFieldProxyAccessor.h:111
Abstract but typed data field accessor. Inherit to create different storage mechanisms.
Definition: cafDataFieldAccessor.h:42
Definition: cafFieldProxyAccessor.h:45
Definition: cafFieldProxyAccessor.h:54
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
Definition: cafFieldProxyAccessor.h:73
bool hasGetter() const override
Definition: cafFieldProxyAccessor.h:112
std::unique_ptr< DataFieldAccessor< DataType > > clone() const override
Clone the accessor using polymorphism.
Definition: cafFieldProxyAccessor.h:76
DataType value() override
Get the field value.
Definition: cafFieldProxyAccessor.h:84
Main Caffa namespace.
Definition: cafApplication.h:30