cgv
cgv::gui::control< T > Class Template Reference

#include <control.h>

Inheritance diagram for cgv::gui::control< T >:
cgv::gui::abst_control cgv::gui::abst_view cgv::base::node cgv::base::named cgv::base::base cgv::data::ref_counted cgv::reflect::self_reflection_tag

Public Types

typedef cgv::signal::bool_signal< control< T > & > value_check_signal_type
 type of the value check signal
 
typedef cgv::signal::signal< control< T > & > value_change_signal_type
 type of the value change signal
 

Public Member Functions

 control (const std::string &_name, T &_value)
 construct abstract element from reference to value
 
 control (const std::string &_name, T *_value)
 construct abstract element from control_provider
 
 control (const std::string &_name, abst_control_provider *_cp, void *user_data)
 
const T get_value () const
 return a reference to the current value
 
const T & get_new_value () const
 return the new value to the callbacks attached to the check_value signal
 
void set_new_value (const T &nv)
 set a different new value from the callbacks attached to the check_value signal
 
const T & get_old_value () const
 return the old value to the callbacks attached to the change_value signal
 
bool check_and_set_value (const T &nv)
 set new value only if check_value signal succeeds and send value_change signal. Return true if value has been changed.
 
bool controls (const void *ptr) const
 check whether the value represented by this element is pointing to the passed pointer
 
void attach_to_value_change (cgv::signal::functor_base *func)
 attach a functor to the value change signal
 
void attach_to_check_value (cgv::signal::functor_base *bool_func)
 attach a functor to the value change signal
 
bool shows (const void *ptr) const
 add default implementation passing the query to the controls() method
 
void attach_to_reference (const void *ptr)
 links all views to a reference into a doubly linked list in order to allow controls of the reference to update all attached views
 
void detach_from_reference ()
 detach view again More...
 
void update_views ()
 calls the update method of all other attached views
 
node_ptr get_parent () const
 return the parent node
 
base_ptr get_root () const
 return the root node by traversing parents until no more parent is available
 
void set_parent (node_ptr _parent)
 set a new parent node
 
data::ref_ptr< node, true > get_node ()
 cast upward to node
 
std::string get_type_name () const
 overload to return the type name of this object
 
const std::string & get_name () const
 return the parent node
 
void set_name (const std::string &_name)
 set a new parent node
 
data::ref_ptr< named, true > get_named ()
 cast upward to named
 
virtual std::string get_default_options () const
 overload to provide default options for registration
 
virtual void on_register ()
 overload to handle register events that is sent after the instance has been registered More...
 
virtual void unregister ()
 overload to handle unregistration of instances
 
virtual void stream_stats (std::ostream &)
 overload to show the content of this object
 
virtual data::ref_ptr< group, true > get_group ()
 cast upward to group
 
template<class T >
data::ref_ptr< T, true > cast ()
 cast to arbitrary class, but use the casts to named, node and group from the interface
 
template<class T >
T * get_interface ()
 use dynamic type cast to check for the given interface
 
template<class T >
const T * get_const_interface () const
 use dynamic type cast to check for the given interface
 
virtual void update ()
 this virtual update allows for example to ask a view to update the viewed value. The default implementation is empty.
 
virtual void * get_user_data () const
 this virtual method allows to pass application specific data for internal purposes More...
 
int get_ref_count () const
 read access to current count
 

Public Attributes

cgv::signal::bool_signal< control< T > & > check_value
 this signal is sent when the user triggered a change of value in order to check whether the new value is valid. More...
 
cgv::signal::signal< control< T > & > value_change
 this signal is sent after the user triggered a change of value and the check_value succeeded. More...
 

Protected Member Functions

void set_ref_count (int c) const
 write access is also const to allow ref counted pointers to const instances
 

Static Protected Member Functions

template<class T >
static data::ref_ptr< T, true > cast_dynamic (base *b)
 use dynamic cast for upcast to given class
 

Protected Attributes

node_ptr parent
 store a pointer to the parent node
 
std::string name
 store the name as a string
 

property interface

virtual bool self_reflect (cgv::reflect::reflection_handler &)
 used for simple self reflection More...
 
virtual std::string get_property_declarations ()
 return a semicolon separated list of property declarations More...
 
virtual bool set_void (const std::string &property, const std::string &value_type, const void *value_ptr)
 abstract interface for the setter of a dynamic property. More...
 
virtual void on_set (void *member_ptr)
 this callback is called when the set_void method has changed a member and can be overloaded in derived class
 
virtual bool get_void (const std::string &property, const std::string &value_type, void *value_ptr)
 abstract interface for the getter of a dynamic property. More...
 
virtual bool call_void (const std::string &method, const std::vector< std::string > &param_value_types, const std::vector< const void * > &param_value_ptrs, const std::string &result_type="", void *result_value_ptr=0)
 abstract interface to call an action More...
 
void set (const std::string &property, const char *value)
 specialization of set method to support const char* as strings
 
template<typename T >
void set (const std::string &property, const T &value)
 set a property of the element to the given value and perform standard conversions if necessary. More...
 
template<typename T >
get (const std::string &property)
 query a property of the element and perform standard conversions if necessary. More...
 
void multi_set (const std::string &property_assignments, bool report_error=true)
 set several properties More...
 
bool is_property (const std::string &property_name, std::string *type_name=0)
 check if the given name specifies a property. More...
 
void * find_member_ptr (const std::string &property_name, std::string *type_name=0)
 find a member pointer by name. More...
 

Detailed Description

template<typename T>
class cgv::gui::control< T >

gui independent control of a value that has the type of the template argument. The value can either be specified as a reference or through the control_provider that implements a get and a set method.

Before the control changes a value, it emits the signal check_value to test if the new value is valid. The check_value signal has a boolean return value. All attached callbacks must return true in order for the check to be successful. The attached callbacks can also change the new value to a valid value. The check_value callbacks should use the get_new_value(), get_value() and set_new_value() methods of the control to update the new value and to access the current value that has not been changed yet.

If the validity check is successful, the value is changed to the new value and the value_change signal is emitted. The callbacks attached to this signal can not only query the current value with get_value() but also the old value with get_old_value(). Take care that the get_old_value() cannot be used in the callbacks attached to check_value and the get_new_value() method cannot be used in the callbacks attached to the value_change signal.

Constructor & Destructor Documentation

◆ control()

template<typename T >
cgv::gui::control< T >::control ( const std::string &  _name,
abst_control_provider _cp,
void *  user_data 
)
inline

this constructor allows contruction from control_provider with user data or if the pointer to the control_provider is null, interpret the pointer to the user data as the value pointer and act as the previous constructor.

Member Function Documentation

◆ call_void()

bool cgv::base::base::call_void ( const std::string &  method,
const std::vector< std::string > &  param_value_types,
const std::vector< const void * > &  param_value_ptrs,
const std::string &  result_type = "",
void *  result_value_ptr = 0 
)
virtualinherited

abstract interface to call an action

overload to implement the execution of a method based on the method name and the given parameters

, i.e. a class method based on the action name and the given parameters. The default implementation uses the self_reflect() method to dispatch this call. If not found, the get_void method returns false.

◆ detach_from_reference()

void cgv::gui::abst_view::detach_from_reference ( )
inherited

detach view again

links all views to a reference into a doubly linked list in order to allow controls of the reference to update all attached views

◆ find_member_ptr()

void * cgv::base::base::find_member_ptr ( const std::string &  property_name,
std::string *  type_name = 0 
)
inherited

find a member pointer by name.

If not found the null pointer is returned. If the type name string pointer is provided, the type of the property is copied to the referenced string.

◆ get()

template<typename T >
T cgv::base::base::get ( const std::string &  property)
inlineinherited

query a property of the element and perform standard conversions if necessary.

This templated version simply extracts the type of the value from the reference and calls the set_void() method. Note that this only works if the template cgv::type::info::type_name<T> is overloaded for the value type.

◆ get_property_declarations()

std::string cgv::base::base::get_property_declarations ( )
virtualinherited

return a semicolon separated list of property declarations

return a semicolon separated list of property declarations of the form "name:type", by default an empty list is returned

of the form "name1:type1;name2:type2;...", by default an empty list is returned. The types should by consistent with the names returned by cgv::type::info::type_name::get_name. The default implementation extracts names and types from the self_reflect() method and the meta type information provided by the get_type() method.

Reimplemented in cgv::base::factory, cgv::base::base_generator, cgv::media::image::image_reader, cgv::media::video::video_writer, cgv::media::image::image_writer, cgv::media::video::video_reader, and cgv::base::console.

◆ get_user_data()

void * cgv::base::base::get_user_data ( ) const
virtualinherited

this virtual method allows to pass application specific data for internal purposes

this virtual method allows derived classes to pass application specific data

◆ get_void()

bool cgv::base::base::get_void ( const std::string &  property,
const std::string &  value_type,
void *  value_ptr 
)
virtualinherited

abstract interface for the getter of a dynamic property.

abstract interface for the getter, by default it simply returns false

The default implementation uses the self_reflect() method to find a member with the given property as name. If not found, the get_void method returns false.

Reimplemented in cgv::base::factory, cgv::base::base_generator, cgv::base::console, cgv::media::image::image_reader, cgv::media::image::image_writer, cgv::media::video::video_reader, and cgv::media::video::video_writer.

◆ is_property()

bool cgv::base::base::is_property ( const std::string &  property_name,
std::string *  type_name = 0 
)
inherited

check if the given name specifies a property.

If the type name string pointer is provided, the type of the property is copied to the referenced string.

◆ multi_set()

void cgv::base::base::multi_set ( const std::string &  property_assignments,
bool  report_error = true 
)
inherited

set several properties

set several properties, which are defined as colon separated assignments, where the types are derived automatically

, which are defined as colon separated assignments, where the types are derived automatically to bool, int, double or std::string.

◆ on_register()

void cgv::base::base::on_register ( )
virtualinherited

overload to handle register events that is sent after the instance has been registered

overload to return a type info structure. By default an empty pointer is returned.

◆ self_reflect()

bool cgv::base::base::self_reflect ( cgv::reflect::reflection_handler )
virtualinherited

used for simple self reflection

is used by default implementation of set_void, get_void and get_property_declarations

The overloaded implementation is used by the default implementations of set_void, get_void and get_property_declarations with corresponding reflection handlers. The default implementation of self_reflect is empty.

Reimplemented in cgv::render::render_config, and cgv::render::shader_config.

◆ set()

template<typename T >
void cgv::base::base::set ( const std::string &  property,
const T &  value 
)
inlineinherited

set a property of the element to the given value and perform standard conversions if necessary.

This templated version simply extracts the type of the value from the reference and calls the set_void() method. Note that this only works if the template cgv::type::info::type_name<T> is overloaded for the value type.

◆ set_void()

bool cgv::base::base::set_void ( const std::string &  property,
const std::string &  value_type,
const void *  value_ptr 
)
virtualinherited

abstract interface for the setter of a dynamic property.

abstract interface for the setter, by default it simply returns false

The default implementation uses the self_reflect() method to find a member with the given property as name. If not found, the set_void method returns false.

Reimplemented in cgv::base::factory, cgv::base::base_generator, cgv::base::console, cgv::media::image::image_reader, cgv::media::image::image_writer, cgv::media::video::video_reader, and cgv::media::video::video_writer.

Member Data Documentation

◆ check_value

template<typename T >
cgv::signal::bool_signal<control<T>&> cgv::gui::control< T >::check_value

this signal is sent when the user triggered a change of value in order to check whether the new value is valid.

Use get_new_value() and set_new_value() to get and correct the new value. Return true if the new value is ok or could be corrected, false otherwise.

◆ value_change

template<typename T >
cgv::signal::signal<control<T>&> cgv::gui::control< T >::value_change

this signal is sent after the user triggered a change of value and the check_value succeeded.

You can access the old value with get_old_value() method.


The documentation for this class was generated from the following file: