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 9e694e1..c381cf8 100644 --- a/wire/variable.hpp +++ b/wire/variable.hpp @@ -11,11 +11,8 @@ namespace motor { namespace wire { - enum sub_update_strategy - { - never, - always - }; + class simple_trait { /*public: virtual ~simple_trait( void_t ) {}*/ } ; + class detailed_trait {} ; class any { @@ -28,9 +25,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 +41,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 +70,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 +83,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 > @@ -141,6 +120,13 @@ namespace motor { return reinterpret_cast( _out ) ; } + + public: + + motor::wire::ioutput_slot_ptr_t borrow_os( void_t ) noexcept + { + return _out ; + } public: @@ -176,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 ; + } + + static bool_t is_detailed( motor::wire::any_ptr_t p ) noexcept + { + return dynamic_cast( p ) != nullptr ; + } - template< typename T > - class variable : public any + 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 > ; @@ -223,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 24fffc3..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,19 +25,19 @@ 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 > ; 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 +50,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 +93,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 +114,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! @@ -178,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 2fea5e5..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" ) ; @@ -36,9 +37,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 +73,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() ; @@ -114,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" ) ; @@ -139,9 +132,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 +169,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() ; @@ -221,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" ) ; @@ -248,9 +232,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 +269,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() ; @@ -331,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