From 6b83db4584e266e11d8ac89a7d55f8a750484aa3 Mon Sep 17 00:00:00 2001 From: Alex Link Date: Fri, 1 Nov 2024 10:44:12 +0100 Subject: [PATCH 1/2] :coffin: removed update strat for sub vars --- wire/variable.hpp | 24 --------------------- wire/variables/trafo_variables.hpp | 31 +++------------------------ wire/variables/vector_variables.hpp | 33 ----------------------------- 3 files changed, 3 insertions(+), 85 deletions(-) diff --git a/wire/variable.hpp b/wire/variable.hpp index 9e694e1..bbfc201 100644 --- a/wire/variable.hpp +++ b/wire/variable.hpp @@ -11,12 +11,6 @@ namespace motor { namespace wire { - enum sub_update_strategy - { - never, - always - }; - class any { motor_this_typedefs( any ) ; @@ -28,9 +22,6 @@ namespace motor motor::wire::iinput_slot_ptr_t _in = nullptr ; motor::wire::ioutput_slot_ptr_t _out = nullptr ; - // how to automatically update sub member variables - sub_update_strategy _strat = sub_update_strategy::never ; - public: struct member_info @@ -47,9 +38,6 @@ namespace motor any( char const * name, motor::wire::iinput_slot_ptr_t in_, motor::wire::ioutput_slot_ptr_t out_ ) noexcept : _name( name ), _in( in_ ), _out( out_ ) {} - any( char const * name, motor::wire::iinput_slot_ptr_t in_, motor::wire::ioutput_slot_ptr_t out_, sub_update_strategy const us ) noexcept : - _name( name ), _in( in_ ), _out( out_ ), _strat( us ) {} - any( this_cref_t ) = delete ; any( this_rref_t rhv ) noexcept : _name( motor::move( rhv._name ) ), _in( motor::move( rhv._in ) ), _out( motor::move( rhv._out ) ){ } @@ -79,7 +67,6 @@ namespace motor // return bool if anything changed. virtual bool_t update( void_t ) noexcept = 0 ; - virtual void_t update_strat_changed( motor::wire::sub_update_strategy const ) noexcept {} public: @@ -93,17 +80,6 @@ namespace motor return motor::share( _out ) ; } - motor::wire::sub_update_strategy get_update_strategy( void_t ) const noexcept - { - return _strat ; - } - - void_t set_update_strategy( motor::wire::sub_update_strategy const s ) noexcept - { - _strat = s ; - this->update_strat_changed( s ) ; - } - protected: template< typename T > diff --git a/wire/variables/trafo_variables.hpp b/wire/variables/trafo_variables.hpp index 24fffc3..6e7ec7c 100644 --- a/wire/variables/trafo_variables.hpp +++ b/wire/variables/trafo_variables.hpp @@ -31,9 +31,9 @@ namespace motor private: - pos_t _pos = pos_t( "position", base_t::get_update_strategy() ) ; - scale_t _scale = scale_t( "scale", base_t::get_update_strategy() ) ; - axis_t _axis = axis_t( "axis", base_t::get_update_strategy() ) ; + pos_t _pos = pos_t( "position" ) ; + scale_t _scale = scale_t( "scale" ) ; + axis_t _axis = axis_t( "axis" ) ; angle_t _angle = angle_t( "angle" ) ; public: @@ -46,12 +46,6 @@ namespace motor this_t::set_value( v ) ; } - variable( char const * name, value_cref_t v, motor::wire::sub_update_strategy const us ) noexcept : - base_t( name, motor::shared( in_t() ), motor::shared( out_t() ), us ) - { - this_t::set_value( v ) ; - } - variable( this_cref_t ) = delete ; variable( this_rref_t rhv ) noexcept : base_t( std::move( rhv ) ), @@ -95,20 +89,6 @@ namespace motor return false ; } - virtual void_t update_strat_changed( motor::wire::sub_update_strategy const us ) noexcept - { - base_t::set_update_strategy( us ) ; - _pos.set_update_strategy( us ) ; - _scale.set_update_strategy( us ) ; - _axis.set_update_strategy( us ) ; - _angle.set_update_strategy( us ) ; - } - - bool_t update( motor::wire::sub_update_strategy const us ) noexcept - { - - } - value_cref_t get_value( void_t ) const noexcept { return base_t::borrow_os()->get_value() ; @@ -130,11 +110,6 @@ namespace motor void_t propagate_value_to_sub( value_cref_t v ) noexcept { - auto const strat = base_t::get_update_strategy() ; - - if ( strat == motor::wire::sub_update_strategy::never ) - return ; - _pos.set_value( v.get_translation() ) ; // some cost involved! diff --git a/wire/variables/vector_variables.hpp b/wire/variables/vector_variables.hpp index 2fea5e5..77bddae 100644 --- a/wire/variables/vector_variables.hpp +++ b/wire/variables/vector_variables.hpp @@ -36,9 +36,6 @@ namespace motor variable( char const * const name ) noexcept : base_t( name, motor::shared( in_t() ), motor::shared( out_t() ) ) {} - variable( char const * const name, motor::wire::sub_update_strategy const us ) noexcept : - base_t( name, motor::shared( in_t() ), motor::shared( out_t() ), us ) {} - variable( this_cref_t ) = delete ; variable( this_rref_t rhv ) noexcept : base_t( std::move( rhv ) ), @@ -75,13 +72,6 @@ namespace motor return false ; } - virtual void_t update_strat_changed( motor::wire::sub_update_strategy const us ) noexcept - { - base_t::set_update_strategy( us ) ; - _x.set_update_strategy( us ) ; - _y.set_update_strategy( us ) ; - } - value_cref_t get_value( void_t ) const noexcept { return base_t::borrow_os()->get_value() ; @@ -139,9 +129,6 @@ namespace motor variable( char const * const name ) noexcept : base_t( name, motor::shared( in_t() ), motor::shared( out_t() ) ) {} - variable( char const * const name, motor::wire::sub_update_strategy const us ) noexcept : - base_t( name, motor::shared( in_t() ), motor::shared( out_t() ), us ) {} - variable( this_cref_t ) = delete ; variable( this_rref_t rhv ) noexcept : base_t( std::move( rhv ) ), @@ -179,14 +166,6 @@ namespace motor return false ; } - virtual void_t update_strat_changed( motor::wire::sub_update_strategy const us ) noexcept - { - base_t::set_update_strategy( us ) ; - _x.set_update_strategy( us ) ; - _y.set_update_strategy( us ) ; - _z.set_update_strategy( us ) ; - } - value_cref_t get_value( void_t ) const noexcept { return base_t::borrow_os()->get_value() ; @@ -248,9 +227,6 @@ namespace motor variable( char const * const name ) noexcept : base_t( name, motor::shared( in_t() ), motor::shared( out_t() ) ) {} - variable( char const * const name, motor::wire::sub_update_strategy const us ) noexcept : - base_t( name, motor::shared( in_t() ), motor::shared( out_t() ), us ) {} - variable( this_cref_t ) = delete ; variable( this_rref_t rhv ) noexcept : base_t( std::move( rhv ) ), @@ -288,15 +264,6 @@ namespace motor return false ; } - virtual void_t update_strat_changed( motor::wire::sub_update_strategy const us ) noexcept - { - base_t::set_update_strategy( us ) ; - _x.set_update_strategy( us ) ; - _y.set_update_strategy( us ) ; - _z.set_update_strategy( us ) ; - _w.set_update_strategy( us ) ; - } - value_cref_t get_value( void_t ) const noexcept { return base_t::borrow_os()->get_value() ; From 64b0b87a5f35afd08f46a6c2e32fc2989e50a7ef Mon Sep 17 00:00:00 2001 From: Alex Link Date: Fri, 1 Nov 2024 15:56:26 +0100 Subject: [PATCH 2/2] [#109] - :tada: decided to split the variables into detailed and simple variable types --- base/macros/typedef.h | 2 + wire/variable.hpp | 45 ++++++++++++++--- wire/variables/trafo_variables.hpp | 19 ++++--- wire/variables/vector_variables.hpp | 77 ++++++++++++++++++----------- 4 files changed, 98 insertions(+), 45 deletions(-) diff --git a/base/macros/typedef.h b/base/macros/typedef.h index 06b19d1..411240a 100644 --- a/base/macros/typedef.h +++ b/base/macros/typedef.h @@ -3,6 +3,8 @@ #include "../mtr_ownership.hpp" +#define motor_comma , + #define motor_typedefs_extend( from_, to_ ) \ typedef to_ ## _t * to_ ## _ptr_t ; \ typedef to_ ## _t * to_ ## _mtr_t ; \ diff --git a/wire/variable.hpp b/wire/variable.hpp index bbfc201..c381cf8 100644 --- a/wire/variable.hpp +++ b/wire/variable.hpp @@ -11,6 +11,9 @@ namespace motor { namespace wire { + class simple_trait { /*public: virtual ~simple_trait( void_t ) {}*/ } ; + class detailed_trait {} ; + class any { motor_this_typedefs( any ) ; @@ -117,6 +120,13 @@ namespace motor { return reinterpret_cast( _out ) ; } + + public: + + motor::wire::ioutput_slot_ptr_t borrow_os( void_t ) noexcept + { + return _out ; + } public: @@ -152,12 +162,23 @@ namespace motor }; motor_typedef( any ) ; + static bool_t is_simple( motor::wire::any_ptr_t p ) noexcept + { + return dynamic_cast< motor::wire::simple_trait * >( p ) != nullptr ; + } - template< typename T > - class variable : public any + static bool_t is_detailed( motor::wire::any_ptr_t p ) noexcept + { + return dynamic_cast( p ) != nullptr ; + } + + template< typename T, typename trait_t > + class variable : public any, public trait_t { using base_t = any ; - motor_this_typedefs( variable< T > ) ; + motor_this_typedefs( variable< T motor_comma trait_t > ) ; + + public: using in_t = motor::wire::input_slot< T > ; using out_t = motor::wire::output_slot< T > ; @@ -199,10 +220,18 @@ namespace motor } }; - motor_typedefs( variable< bool_t >, boolv ) ; - motor_typedefs( variable< int_t >, intv ) ; - motor_typedefs( variable< uint_t >, uintv ) ; - motor_typedefs( variable< float_t >, floatv ) ; - motor_typedefs( variable< double_t >, doublev ) ; + motor_typedefs( variable< bool_t motor_comma motor::wire::simple_trait >, boolv ) ; + motor_typedefs( variable< int_t motor_comma motor::wire::simple_trait >, intv ) ; + motor_typedefs( variable< uint_t motor_comma motor::wire::simple_trait >, uintv ) ; + motor_typedefs( variable< float_t motor_comma motor::wire::simple_trait >, floatv ) ; + motor_typedefs( variable< double_t motor_comma motor::wire::simple_trait >, doublev ) ; + + + template< typename T > + bool_t is_type_compatible( motor::wire::any_ptr_t ptr ) noexcept + { + using target_type = motor::wire::variable< T, motor::wire::simple_trait >::out_t ; + return dynamic_cast< target_type *>( ptr->borrow_os() ) != nullptr ; + } } } \ No newline at end of file diff --git a/wire/variables/trafo_variables.hpp b/wire/variables/trafo_variables.hpp index 6e7ec7c..3923cf2 100644 --- a/wire/variables/trafo_variables.hpp +++ b/wire/variables/trafo_variables.hpp @@ -9,11 +9,15 @@ namespace motor namespace wire { template< typename T > - class variable< motor::math::m3d::transformation< T > > : public motor::wire::any + class variable< motor::math::m3d::transformation< T >, motor::wire::detailed_trait > : public motor::wire::any, public motor::wire::detailed_trait { using base_t = motor::wire::any ; - motor_this_typedefs( variable< motor::math::m3d::transformation< T > > ) ; + using trait_t = motor::wire::detailed_trait ; + + motor_this_typedefs( variable< motor::math::m3d::transformation< T > motor_comma trait_t > ) ; + + public: @@ -21,10 +25,10 @@ namespace motor private: - using pos_t = motor::wire::vec3v< T > ; - using scale_t = motor::wire::vec3v< T > ; - using axis_t = motor::wire::vec3v< T > ; - using angle_t = motor::wire::variable< T > ; + using pos_t = motor::wire::vec3v< T, trait_t > ; + using scale_t = motor::wire::vec3v< T, trait_t > ; + using axis_t = motor::wire::vec3v< T, trait_t > ; + using angle_t = motor::wire::variable< T, trait_t > ; using in_t = motor::wire::input_slot< value_t > ; using out_t = motor::wire::output_slot< value_t > ; @@ -153,6 +157,7 @@ namespace motor } } ; - motor_typedefs( variable< motor::math::m3d::transformation< float_t > >, trafo3fv ) ; + motor_typedefs( variable< motor::math::m3d::transformation< float_t > motor_comma motor::wire::simple_trait >, trafo3fv ) ; + motor_typedefs( variable< motor::math::m3d::transformation< float_t > motor_comma motor::wire::detailed_trait >, trafo3fvd ) ; } } \ No newline at end of file diff --git a/wire/variables/vector_variables.hpp b/wire/variables/vector_variables.hpp index 77bddae..7e94b68 100644 --- a/wire/variables/vector_variables.hpp +++ b/wire/variables/vector_variables.hpp @@ -13,20 +13,21 @@ namespace motor namespace wire { template< typename T > - class variable< motor::math::vector2< T > > : public motor::wire::any + class variable< motor::math::vector2< T >, motor::wire::detailed_trait > : public motor::wire::any, public motor::wire::detailed_trait { using base_t = motor::wire::any ; - motor_this_typedefs( variable< motor::math::vector2< T > > ) ; + motor_this_typedefs( variable< motor::math::vector2< T > motor_comma motor::wire::detailed_trait > ) ; motor_typedefs( motor::math::vector2< T >, value ) ; + using trait_t = motor::wire::detailed_trait ; private: using in_t = motor::wire::input_slot< value_t > ; using out_t = motor::wire::output_slot< value_t > ; - using x_t = motor::wire::variable< T > ; - using y_t = motor::wire::variable< T > ; + using x_t = motor::wire::variable< T, trait_t > ; + using y_t = motor::wire::variable< T, trait_t > ; x_t _x = x_t( "x" ) ; y_t _y = y_t( "y" ) ; @@ -104,21 +105,23 @@ namespace motor }; template< typename T > - class variable< motor::math::vector3< T > > : public motor::wire::any + class variable< motor::math::vector3< T >, motor::wire::detailed_trait > : public motor::wire::any, public motor::wire::detailed_trait { using base_t = motor::wire::any ; - motor_this_typedefs( variable< motor::math::vector3< T > > ) ; + motor_this_typedefs( variable< motor::math::vector3< T > motor_comma motor::wire::detailed_trait > ) ; motor_typedefs( motor::math::vector3< T >, value ) ; + using trait_t = motor::wire::detailed_trait ; + private: using in_t = motor::wire::input_slot< value_t > ; using out_t = motor::wire::output_slot< value_t > ; - using x_t = motor::wire::variable< T > ; - using y_t = motor::wire::variable< T > ; - using z_t = motor::wire::variable< T > ; + using x_t = motor::wire::variable< T, trait_t> ; + using y_t = motor::wire::variable< T, trait_t > ; + using z_t = motor::wire::variable< T, trait_t > ; x_t _x = x_t( "x" ) ; y_t _y = y_t( "y" ) ; @@ -200,22 +203,24 @@ namespace motor }; template< typename T > - class variable< motor::math::vector4< T > > : public motor::wire::any + class variable< motor::math::vector4< T >, motor::wire::detailed_trait > : public motor::wire::any, public motor::wire::detailed_trait { using base_t = motor::wire::any ; - motor_this_typedefs( variable< motor::math::vector4< T > > ) ; + motor_this_typedefs( variable< motor::math::vector4< T > motor_comma motor::wire::detailed_trait > ) ; motor_typedefs( motor::math::vector4< T >, value ) ; + using trait_t = motor::wire::detailed_trait ; + private: using in_t = motor::wire::input_slot< value_t > ; using out_t = motor::wire::output_slot< value_t > ; - using x_t = motor::wire::variable< T > ; - using y_t = motor::wire::variable< T > ; - using z_t = motor::wire::variable< T > ; - using w_t = motor::wire::variable< T > ; + using x_t = motor::wire::variable< T, trait_t > ; + using y_t = motor::wire::variable< T, trait_t > ; + using z_t = motor::wire::variable< T, trait_t > ; + using w_t = motor::wire::variable< T, trait_t > ; x_t _x = x_t( "x" ) ; y_t _y = y_t( "y" ) ; @@ -298,26 +303,38 @@ namespace motor f( _w, { ifo.level + 1, ifo.full_name + "." + _w.name() } ) ; } }; + + template< typename T, typename trait_t > + using vec2v = motor::wire::variable< motor::math::vector2< T >, trait_t > ; - template< typename T > - using vec2v = motor::wire::variable< motor::math::vector2< T > > ; + template< typename T, typename trait_t > + using vec3v = motor::wire::variable< motor::math::vector3< T >, trait_t > ; - template< typename T > - using vec3v = motor::wire::variable< motor::math::vector3< T > > ; + template< typename T, typename trait_t> + using vec4v = motor::wire::variable< motor::math::vector4< T >, trait_t > ; - template< typename T > - using vec4v = motor::wire::variable< motor::math::vector4< T > > ; + motor_typedefs( variable< motor::math::vector2< float_t > motor_comma motor::wire::detailed_trait >, vec2fvd ) ; + motor_typedefs( variable< motor::math::vector3< float_t > motor_comma motor::wire::detailed_trait >, vec3fvd ) ; + motor_typedefs( variable< motor::math::vector4< float_t > motor_comma motor::wire::detailed_trait >, vec4fvd ) ; + + motor_typedefs( variable< motor::math::vector2< int_t > motor_comma motor::wire::detailed_trait >, vec2ivd ) ; + motor_typedefs( variable< motor::math::vector3< int_t > motor_comma motor::wire::detailed_trait >, vec3ivd ) ; + motor_typedefs( variable< motor::math::vector4< int_t > motor_comma motor::wire::detailed_trait >, vec4ivd ) ; + + motor_typedefs( variable< motor::math::vector2< uint_t > motor_comma motor::wire::detailed_trait >, vec2uivd ) ; + motor_typedefs( variable< motor::math::vector3< uint_t > motor_comma motor::wire::detailed_trait >, vec3uivd ) ; + motor_typedefs( variable< motor::math::vector4< uint_t > motor_comma motor::wire::detailed_trait >, vec4uivd ) ; - motor_typedefs( variable< motor::math::vector2< float_t > >, vec2fv ) ; - motor_typedefs( variable< motor::math::vector3< float_t > >, vec3fv ) ; - motor_typedefs( variable< motor::math::vector4< float_t > >, vec4fv ) ; + motor_typedefs( variable< motor::math::vector2< float_t > motor_comma motor::wire::simple_trait >, vec2fv ) ; + motor_typedefs( variable< motor::math::vector3< float_t > motor_comma motor::wire::simple_trait >, vec3fv ) ; + motor_typedefs( variable< motor::math::vector4< float_t > motor_comma motor::wire::simple_trait >, vec4fv ) ; - motor_typedefs( variable< motor::math::vector2< int_t > >, vec2iv ) ; - motor_typedefs( variable< motor::math::vector3< int_t > >, vec3iv ) ; - motor_typedefs( variable< motor::math::vector4< int_t > >, vec4iv ) ; + motor_typedefs( variable< motor::math::vector2< int_t > motor_comma motor::wire::simple_trait >, vec2iv ) ; + motor_typedefs( variable< motor::math::vector3< int_t > motor_comma motor::wire::simple_trait >, vec3iv ) ; + motor_typedefs( variable< motor::math::vector4< int_t > motor_comma motor::wire::simple_trait >, vec4iv ) ; - motor_typedefs( variable< motor::math::vector2< uint_t > >, vec2uiv ) ; - motor_typedefs( variable< motor::math::vector3< uint_t > >, vec3uiv ) ; - motor_typedefs( variable< motor::math::vector4< uint_t > >, vec4uiv ) ; + motor_typedefs( variable< motor::math::vector2< uint_t > motor_comma motor::wire::simple_trait >, vec2uiv ) ; + motor_typedefs( variable< motor::math::vector3< uint_t > motor_comma motor::wire::simple_trait >, vec3uiv ) ; + motor_typedefs( variable< motor::math::vector4< uint_t > motor_comma motor::wire::simple_trait >, vec4uiv ) ; } } \ No newline at end of file