opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
component_accessor.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdexcept>
4
5namespace OpenSim { class Component; }
6
7namespace opyn
8{
10 protected:
11 ComponentAccessor() = default;
13 ComponentAccessor(ComponentAccessor&&) noexcept = default;
14 ComponentAccessor& operator=(const ComponentAccessor&) = default;
15 ComponentAccessor& operator=(ComponentAccessor&&) noexcept = default;
16
17 friend bool operator==(const ComponentAccessor&, const ComponentAccessor&) = default;
18 public:
19 virtual ~ComponentAccessor() noexcept = default;
20
21 const OpenSim::Component& getComponent() const { return implGetComponent(); }
22 operator const OpenSim::Component& () const { return getComponent(); }
23
24 bool isReadonly() const { return not implCanUpdComponent(); }
25 bool canUpdComponent() const { return implCanUpdComponent(); }
26 OpenSim::Component& updComponent() { return implUpdComponent(); }
27
28 private:
29 // Implementors should return a const reference to an initialized (finalized properties, etc.) component
30 virtual const OpenSim::Component& implGetComponent() const = 0;
31
32 // Implementors may return whether the component contained by the concrete `ComponentAccessor` implementation
33 // can be modified in-place.
34 //
35 // If the response can be `true`, implementors must also override `implUpdComponent` accordingly.
36 virtual bool implCanUpdComponent() const { return false; }
37
38 // Implementors may return a mutable reference to the contained component. It is up to the caller
39 // of `updComponent` to ensure that the component is still valid + initialized after modification.
40 //
41 // If this is implemented, implementors should override `implCanUpdComponent` accordingly.
42 virtual OpenSim::Component& implUpdComponent()
43 {
44 throw std::runtime_error{"component updating not implemented for this ComponentAccessor"};
45 }
46 };
47}
Definition component_accessor.h:9
virtual bool implCanUpdComponent() const
Definition component_accessor.h:36
virtual const OpenSim::Component & implGetComponent() const =0
const OpenSim::Component & getComponent() const
Definition component_accessor.h:21
OpenSim::Component & updComponent()
Definition component_accessor.h:26
bool isReadonly() const
Definition component_accessor.h:24
ComponentAccessor(ComponentAccessor &&) noexcept=default
bool canUpdComponent() const
Definition component_accessor.h:25
ComponentAccessor(const ComponentAccessor &)=default
virtual OpenSim::Component & implUpdComponent()
Definition component_accessor.h:42
Definition static_component_registries.h:3
Definition component_registry.h:14