Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafDataFieldAccessor.h
1 //##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) Gaute Lindkvist
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 #pragma once
20 
21 #include <memory>
22 #include <optional>
23 
24 namespace caffa
25 {
31 {
32 public:
33  virtual ~DataFieldAccessorInterface() = default;
34 };
35 
41 template <class DataType>
43 {
44 public:
50  virtual std::unique_ptr<DataFieldAccessor<DataType>> clone() const = 0;
51 
57  virtual DataType value() = 0;
58 
65  virtual void setValue( const DataType& value ) = 0;
66 };
67 
73 template <class DataType>
75 {
76 public:
82 
89  : m_value( value )
90 
91  {
92  }
93 
94  std::unique_ptr<DataFieldAccessor<DataType>> clone() const override
95  {
96  return std::make_unique<DataFieldDirectStorageAccessor<DataType>>( m_value );
97  }
98 
99  DataType value() override { return m_value; };
100 
101  void setValue( const DataType& value ) override { m_value = value; }
102 
103 private:
104  DataType m_value;
105 };
106 
107 } // namespace caffa
Basic non-typed interface which exists only to allow non-typed pointers.
Definition: cafDataFieldAccessor.h:31
Abstract but typed data field accessor. Inherit to create different storage mechanisms.
Definition: cafDataFieldAccessor.h:43
virtual std::unique_ptr< DataFieldAccessor< DataType > > clone() const =0
Clone the accessor using polymorphism.
virtual void setValue(const DataType &value)=0
Set the value with the accessor. Will throw a std::runtime_exception if the accessor has limits and t...
virtual DataType value()=0
Get the field value.
Direct storage accessor, which stores data values in local memory.
Definition: cafDataFieldAccessor.h:75
std::unique_ptr< DataFieldAccessor< DataType > > clone() const override
Clone the accessor using polymorphism.
Definition: cafDataFieldAccessor.h:94
DataType value() override
Get the field value.
Definition: cafDataFieldAccessor.h:99
DataFieldDirectStorageAccessor(const DataType &value)
Construct a new Data Field Direct Storage Accessor object with a default value.
Definition: cafDataFieldAccessor.h:88
DataFieldDirectStorageAccessor()=default
Construct a new Data Field Direct Storage Accessor object.
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: cafDataFieldAccessor.h:101
Main Caffa namespace.
Definition: __init__.py:1