VISR  0.11.1
Versatile Interactive Scene Renderer
typed_parameter_base.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_TYPED_PARAMETER_BASE_HPP_INCLUDED
4 #define VISR_TYPED_PARAMETER_BASE_HPP_INCLUDED
5 
6 #include "parameter_base.hpp"
7 #include "parameter_type.hpp"
8 
9 #include <ciso646>
10 #include <exception>
11 
12 namespace visr
13 {
14 
20 template< typename ConcreteParameterType,
21  class ParameterConfigT,
22  ParameterType typeId >
23 class TypedParameterBase: public ParameterBase
24 {
25 public:
26  using ParameterConfigType = ParameterConfigT;
27 
31  TypedParameterBase() = default;
32 
36  virtual ~TypedParameterBase() = default;
37 
41  static const constexpr ParameterType staticType()
42  {
43  return typeId;
44  }
45 
49  /*virtual*/ ParameterType type() final
50  {
51  return staticType();
52  }
53 
57  /*virtual*/ std::unique_ptr<ParameterBase> clone() const final
58  {
59  return std::unique_ptr<ParameterBase>(
60  new ConcreteParameterType(static_cast<ConcreteParameterType const &>(*this) ) );
61  }
62 
68  void assign( ParameterBase const & rhs ) override
69  {
70  ConcreteParameterType const * rhsTyped = dynamic_cast<ConcreteParameterType const *>(&rhs);
71  if( not rhsTyped )
72  {
73  throw std::invalid_argument( "Assign: Types are not compatible.");
74  }
75  *this = *rhsTyped;
76  }
77 };
78 
79 } // namespace visr
80 
81 // TODO: Check whether we can provide the lookup template specializations
82 // ParameterToId, IdToParameter, and ParameterToConfigType for all types here.
83 // Problem: We do not see the derived type here, only the base of the actual parameter type.
84 
85 #endif // #ifndef VISR_TYPED_PARAMETER_BASE_HPP_INCLUDED
uint64_t ParameterType
Definition: parameter_type.hpp:13
ParameterType type() final
Definition: typed_parameter_base.hpp:49
std::unique_ptr< ParameterBase > clone() const final
Definition: typed_parameter_base.hpp:57
static const constexpr ParameterType staticType()
Definition: typed_parameter_base.hpp:41
Definition: interpolation_parameter.hpp:30
Definition: options.cpp:10
void assign(ParameterBase const &rhs) override
Definition: typed_parameter_base.hpp:68
virtual ~TypedParameterBase()=default
Definition: parameter_base.hpp:18