Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafChildFieldAccessor.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 3D-Radar 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 #pragma once
20 
21 #include "cafObjectHandle.h"
22 
23 #include <memory>
24 #include <optional>
25 
26 namespace caffa
27 {
28 class FieldHandle;
29 
31 {
32 public:
34  : m_field( field )
35  {
36  }
37  virtual ~ChildFieldAccessor() = default;
38  virtual std::shared_ptr<ObjectHandle> object() = 0;
39  virtual std::shared_ptr<const ObjectHandle> object() const = 0;
40  virtual void setObject( std::shared_ptr<ObjectHandle> object ) = 0;
41  virtual void clear() = 0;
42 
47  virtual bool hasSetter() const = 0;
48 
53  virtual bool hasGetter() const = 0;
54 
55 protected:
56  FieldHandle* m_field;
57 };
58 
60 {
61 public:
63  : ChildFieldAccessor( field )
64  {
65  }
66  ~ChildFieldDirectStorageAccessor() override = default;
67  std::shared_ptr<ObjectHandle> object() override { return m_object; }
68  std::shared_ptr<const ObjectHandle> object() const override { return m_object; }
69  void setObject( std::shared_ptr<ObjectHandle> object ) override { m_object = object; }
70  void clear() override { m_object.reset(); }
71 
72  bool hasGetter() const override { return true; }
73  bool hasSetter() const override { return true; }
74 
75 private:
76  std::shared_ptr<ObjectHandle> m_object;
77 };
78 
79 } // namespace caffa
Definition: cafChildFieldAccessor.h:30
virtual bool hasGetter() const =0
bool hasGetter() const override
Definition: cafChildFieldAccessor.h:72
bool hasSetter() const override
Definition: cafChildFieldAccessor.h:73
Base class for all fields, making it possible to handle them generically.
Definition: cafFieldHandle.h:19
Definition: cafChildFieldAccessor.h:59
virtual bool hasSetter() const =0
Main Caffa namespace.
Definition: cafApplication.h:30