Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafDataField.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 2024- Kontur AS
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 // ##################################################################################################
20 #pragma once
21 
22 #include "cafDataFieldAccessor.h"
23 #include "cafFieldHandle.h"
24 #include "cafPortableDataType.h"
25 #include "cafVisitor.h"
26 
27 namespace caffa
28 {
29 
30 class DataField : public FieldHandle
31 {
32 public:
33  virtual void setUntypedAccessor( std::unique_ptr<DataFieldAccessorInterface> accessor ) = 0;
34 
35  void accept( Inspector* visitor ) const override { visitor->visit( this ); }
36  void accept( Editor* editor ) override { editor->visit( this ); }
37 };
38 
39 template <typename DataType>
40 class TypedField : public DataField
41 {
42 public:
43  using FieldDataType = DataType;
44 
45 public:
46  virtual DataType value() const = 0;
47  virtual void setValue( const DataType& fieldValue ) = 0;
48 
49  std::string dataType() const override { return PortableDataType<DataType>::name(); }
50 };
51 
52 } // namespace caffa
void accept(Editor *editor) override
Definition: cafDataField.h:36
Definition: cafVisitor.h:49
Base class for all fields, making it possible to handle them generically.
Definition: cafFieldHandle.h:19
Definition: cafDataField.h:40
Definition: cafDataField.h:30
Definition: cafPortableDataType.h:35
void accept(Inspector *visitor) const override
Definition: cafDataField.h:35
Definition: cafVisitor.h:32
Main Caffa namespace.
Definition: cafApplication.h:30