EventResponseHdlr Class Reference

Handles responses by using Tk event bindings. More...

#include <visx/eventresponsehdlr.h>

Inheritance diagram for EventResponseHdlr:

Inheritance graph
[legend]
Collaboration diagram for EventResponseHdlr:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~EventResponseHdlr () throw ()
 Virtual destructor.
virtual io::version_id class_version_id () const
virtual void read_from (io::reader &reader)
virtual void write_to (io::writer &writer) const
void setInputResponseMap (const rutz::fstring &responseMap)
 Use responseMap as the current input response map.
bool getUseFeedback () const
 Queries whether feedback will be given.
void setUseFeedback (bool val)
 Changes whether feedback will be given.
const char * getFeedbackMap () const
 Returns the current feedback map.
void setFeedbackMap (const char *feedbackMap)
 Use feedbackMap as the current feedback map.
const rutz::fstringgetEventSequence () const
void setEventSequence (const rutz::fstring &seq)
const rutz::fstringgetBindingSubstitution () const
void setBindingSubstitution (const rutz::fstring &sub)
rutz::fstring getResponseProc () const
void setResponseProc (const rutz::fstring &args, const rutz::fstring &body)
void abortInvalidResponses ()
void ignoreInvalidResponses ()
void setMaxResponses (unsigned int count)
unsigned int getMaxResponses () const
virtual void rhBeginTrial (nub::soft_ref< Toglet > widget, Trial &trial) const
 Called by a Trial at the beginning of a trial.
virtual void rhAbortTrial () const
 Called by a Trial if a trial is aborted.
virtual void rhEndTrial () const
 Called by a Trial when a trial is complete.
virtual void rhHaltExpt () const
 Called by a Trial when the sequence of trials is halted suddenly.
virtual void rhAllowResponses (nub::soft_ref< Toglet > widget, Trial &trial) const
 Subclasses implement this function to attend to responses.
virtual void rhDenyResponses () const
 Subclasses implement this function to stop attending to responses.
nub::uid id () const throw ()
rutz::fstring real_typename () const
 Returns the typename of the full object.
virtual rutz::fstring obj_typename () const
 Returns the (apparent) typename of the full object.
rutz::fstring unique_name () const
 Returns a short string describing the object by its typename and id.
void * operator new (size_t bytes)
void operator delete (void *space, size_t bytes)
void mark_as_volatile () throw ()
 Mark this object as a volatile (unshareable) object.
void incr_ref_count () const throw ()
 Increment the object's reference count.
void decr_ref_count () const throw ()
 Decrement the object's reference count.
void decr_ref_count_no_delete () const throw ()
 Decrement the object's reference count, but don't delete it.
bool is_shared () const throw ()
 Returns true if no external client has sole ownership of the object.
bool is_unshared () const throw ()
 Returns true if there is a sole external owner of the object.
bool is_not_shareable () const throw ()
ref_counts * get_counts () const throw ()
 Returns the object's reference count manager.
int dbg_ref_count () const throw ()
 FOR TEST/DEBUG ONLY! Returns the object's (strong) reference count.
int dbg_weak_ref_count () const throw ()
 FOR TEST/DEBUG ONLY! Returns the object's weak reference count.

Static Public Member Functions

static EventResponseHdlrmake ()
 Default creator.

Static Public Attributes

static rutz::tracer tracer

Protected Member Functions

 EventResponseHdlr ()
 Default constructor.

Classes

class  Impl


Detailed Description

Handles responses by using Tk event bindings.

EventResponseHandler provides a generic way to collect responses and give feedback. It provides several hooks for Tcl code to define how responses are interpreted, and how feedback is given. Clients should select an event sequence of interest (for example, "\<KeyPress\>"), then select an appropriate Tk binding substitution that will extract the relevant event field (for example, "%K" gets the keycode from a KeyPress event).

Then, an input response map can be used to define an association between values of the event field, and arbitrary response values. This map is in the form of a Tcl list, where each item in the list is a pair of 1) a regexp that will be used to try to match the event field when an event occurs, and 2) a response value that will be sent back to the ExptDriver if the regexp matches. For example, the input response map

{ {{^[aA]$} 0} {{^[lL]$} 1} }

defines two possible response types, one which associates a lower- or upper-case 'a' with the repsonse value 0, and another which associates a lower- or upper-case 'l' with the response value 1. If none of the regexps match the event field, trial is aborted.

Finally, feedback can be controlled by setting the feedback map. This map is another Tcl list in which each element contains a boolean expression as well as a Tcl script to evaluate if the expression is true. The boolean expression can evaluate the Tcl variable 'resp_val' to query the value of the current response. Each boolean expression is tested in order, and the only the first expression which evaluates to true will have its associated feedback script executed. This means that a "catch-all" feedback script can be defined by using an unconditionally true value for the last expression. For example, the following feedback map

 { {{ $resp_val == [Block::currentTrialType 0] } { Sound::play $Sound::ok }} \
   {{ 1 } { Sound::play $Sound::err }} }

will play the Sound::ok sound if the current response matches the current trial type. Otherwise, it will play the Sound::err sound.

Definition at line 95 of file eventresponsehdlr.h.


Member Function Documentation

io::version_id EventResponseHdlr::class_version_id (  )  const [virtual]

Returns a serialization version id for the class. The default implementation returns zero. Classes should override this when they make a change that requires a change to their serialization protocol. Overriding versions of this function should follow the convention that a higher id refers to a later version of the class. Implementations of io::reader and io::writer will provide a way for a class to store and retrieve the serialization version of an object.

Reimplemented from io::serializable.

Definition at line 309 of file eventresponsehdlr.cc.

void EventResponseHdlr::read_from ( io::reader reader  )  [virtual]

Subclasses implement this method to save the object's state via the generic interface provided by io::reader. Parsing the format of the input is handled by the io::reader, so implementors of read_from() of don't need to deal with formatting.

Implements ResponseHandler.

Definition at line 312 of file eventresponsehdlr.cc.

References io::reader::ensure_version_id(), io::reader::read_owned_object(), io::reader::read_value(), and SRC_POS.

void EventResponseHdlr::write_to ( io::writer writer  )  const [virtual]

Subclasses implement this method to restore the object's state via the generic interface provided by io::writer. Formatting the output is handled by the io::writer, so implementors of write_to() of don't need to deal with formatting.

Implements ResponseHandler.

Definition at line 333 of file eventresponsehdlr.cc.

References io::writer::ensure_output_version_id(), SRC_POS, io::writer::write_owned_object(), and io::writer::write_value().

const fstring & EventResponseHdlr::getEventSequence (  )  const

Returns the event sequence which is currently attended for responses. The event sequence is specified in the format used in a Tk bind command.

Definition at line 392 of file eventresponsehdlr.cc.

void EventResponseHdlr::setEventSequence ( const rutz::fstring seq  ) 

Use seq as the binding sequence to be attended for responses. The event sequence should be specified in the format used in a Tk bind command.

Definition at line 395 of file eventresponsehdlr.cc.

const fstring & EventResponseHdlr::getBindingSubstitution (  )  const

Returns the current binding substitution. This will be in the format used in a Tk binding script (i.e. a percent sign followed by the appropriate character).

Definition at line 398 of file eventresponsehdlr.cc.

void EventResponseHdlr::setBindingSubstitution ( const rutz::fstring sub  ) 

Use sub as the current binding substitution. This must be in the format used in a Tk binding script (i.e. a percent sign followed by the appropriate character). When a response matching the event sequence specified by setEventSequence() is seen, the binding substitution will be evaluated, and checked for matches in the input response map to determine the integer response value.

Definition at line 401 of file eventresponsehdlr.cc.

fstring EventResponseHdlr::getResponseProc (  )  const

Returns the args and body of the Tcl code chunk that will be used to decode responses.

Definition at line 404 of file eventresponsehdlr.cc.

void EventResponseHdlr::setResponseProc ( const rutz::fstring args,
const rutz::fstring body 
)

Specify a Tcl proc-style code chunk that will translate its args (which are the results of the binding substitution(s)) into an integer result that can be stored in a Response.

Definition at line 409 of file eventresponsehdlr.cc.

Referenced by setInputResponseMap().

void EventResponseHdlr::abortInvalidResponses (  ) 

Causes the response handler to abort the trial if an invalid responses is seen. This is the default behavior.

Definition at line 415 of file eventresponsehdlr.cc.

void EventResponseHdlr::ignoreInvalidResponses (  ) 

Causes the response handler to ignore invalid responses as if they did not happen.

Definition at line 418 of file eventresponsehdlr.cc.

void EventResponseHdlr::setMaxResponses ( unsigned int  count  ) 

Set the maximum number of responses that will be allowed per activation cycle (the default is 1). After that number of responses has been recorded, the response handler will become inactive until explicitly reactivated.

Definition at line 421 of file eventresponsehdlr.cc.

unsigned int EventResponseHdlr::getMaxResponses (  )  const

Query the maximum number of responses allowed per activation cycle.

Definition at line 424 of file eventresponsehdlr.cc.

void EventResponseHdlr::rhBeginTrial ( nub::soft_ref< Toglet widget,
Trial trial 
) const [virtual]

Called by a Trial at the beginning of a trial.

ResponseHandler subclasses implement this function to prepare listening for responses, etc.

Implements ResponseHandler.

Definition at line 427 of file eventresponsehdlr.cc.

void EventResponseHdlr::rhAbortTrial (  )  const [virtual]

Called by a Trial if a trial is aborted.

ResponseHandler subclasses implement this function to quit listening for responses, etc.

Implements ResponseHandler.

Definition at line 439 of file eventresponsehdlr.cc.

void EventResponseHdlr::rhEndTrial (  )  const [virtual]

Called by a Trial when a trial is complete.

ResponseHandler subclasses implement this function to quit listening for responses, etc.

Implements ResponseHandler.

Definition at line 445 of file eventresponsehdlr.cc.

void EventResponseHdlr::rhHaltExpt (  )  const [virtual]

Called by a Trial when the sequence of trials is halted suddenly.

ResponseHandler subclasses implement this function to quit listening for responses, etc.

Implements ResponseHandler.

Definition at line 456 of file eventresponsehdlr.cc.

nub::uid nub::object::id (  )  const throw () [inherited]

Returns the unique id for this object. The unique id will always be strictly positive; zero is always an invalid unique id.

Definition at line 62 of file object.cc.

rutz::fstring nub::object::real_typename (  )  const [inherited]

Returns the typename of the full object.

The result is a demangled version of typeid(*this).name(), which should very closely resemble the way the object was declared in source code.

Definition at line 67 of file object.cc.

References rutz::demangled_name().

Referenced by nub::object::obj_typename().

rutz::fstring nub::object::obj_typename (  )  const [virtual, inherited]

Returns the (apparent) typename of the full object.

The default implementation just returns real_typename(). However, certain kinds of objects -- e.g., proxy objects -- might usefully choose to have obj_typename() return something besides the real_typename(), in order to masquerade as a different type of object.

Reimplemented in io::proxy< C >, io::const_proxy< C >, MtxObj, and TrialMemFuncEvent.

Definition at line 73 of file object.cc.

References nub::object::real_typename().

Referenced by io::legacy_reader::read_root(), and nub::object::unique_name().

void * nub::ref_counted::operator new ( size_t  bytes  )  [inherited]

Class-specific operator new; protected to ensure that clients use factory functions.

Definition at line 157 of file refcounted.cc.

void nub::ref_counted::operator delete ( void *  space,
size_t  bytes 
) [inherited]

Class-specific operator delete; private since deletion should only happen in ref_counted::decr_ref_count.

Definition at line 163 of file refcounted.cc.

void nub::ref_counted::incr_ref_count (  )  const throw () [inherited]

Increment the object's reference count.

This operation (on the strong reference count) is not permitted if the object is unshareable. Unshareable objects can only have their weak reference counts manipulated.

Definition at line 207 of file refcounted.cc.

References nub::ref_counts::acquire_strong().

Referenced by GxEmptyNode::make().

void nub::ref_counted::decr_ref_count (  )  const throw () [inherited]

Decrement the object's reference count.

If this causes the reference count to fall to zero or below, the pointee and the pointer will be destroyed by a call to 'delete this'. This operation (on the strong reference count) is not permitted if the object is unshareable. Unshareable objects can only have their weak reference counts manipulated.

Definition at line 212 of file refcounted.cc.

References nub::ref_counts::release_strong().

void nub::ref_counted::decr_ref_count_no_delete (  )  const throw () [inherited]

Decrement the object's reference count, but don't delete it.

Unlike decr_ref_count(), the object will NOT be delete'd if the reference count falls to zero. This operation (on the strong reference count) is not permitted if the object is unshareable. Unshareable objects can only have their weak reference counts manipulated.

Definition at line 221 of file refcounted.cc.

References nub::ref_counts::release_strong_no_delete().

bool nub::ref_counted::is_shared (  )  const throw () [inherited]

Returns true if no external client has sole ownership of the object.

This may occur if either (1) the reference count is greater than one, or (2) the object is_not_shareable(), meaning that the object itself is the only "owner".

Definition at line 226 of file refcounted.cc.

References rutz::mutex_atomic_int::atomic_get(), nub::ref_counted::is_not_shareable(), and nub::ref_counts::m_strong.

Referenced by nub::ref_counted::is_unshared().

bool nub::ref_counted::is_unshared (  )  const throw () [inherited]

Returns true if there is a sole external owner of the object.

This occurs if the reference count is one or less and the object is shareable.

Definition at line 236 of file refcounted.cc.

References nub::ref_counted::is_shared().

bool nub::ref_counted::is_not_shareable (  )  const throw () [inherited]

Returns true if the object is not shareable for any reason. This could be because its lifespan is volatile (such as objects representing on-screen windows that can be dismissed by the user). The default is for objects to be shareable; objects can declare themselves as unshareable by calling mark_as_volatile().

Definition at line 242 of file refcounted.cc.

References nub::ref_counts::m_volatile.

Referenced by nub::ref_counted::is_shared().


Member Data Documentation

This tracer dynamically controls the tracing of EventResponseHdlr member functions.

Definition at line 100 of file eventresponsehdlr.h.


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

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:54:03 2008 by Doxygen version 1.5.5.