tcl::pkg Class Reference

#include <tcl/pkg.h>

Collaboration diagram for tcl::pkg:
Collaboration graph
[legend]

List of all members.

Classes

struct  impl

Public Types

typedef void( exit_callback )()

Public Member Functions

void on_exit (exit_callback *callback)
 Specify a function to be called when the package is destroyed.
int init_status () const throw ()
void set_init_status_error () throw ()
 Mark the package as having failed its initialization.
tcl::interpreterinterp () throw ()
 Returns the Tcl interpreter that was passed to the constructor.
void handle_live_exception (const rutz::file_pos &pos) throw ()
 Trap a live exception, and leave a message in the Tcl_Interp's result.
const char * namesp_name () throw ()
 Returns the package's "namespace name".
const char * pkg_name () const throw ()
 Return the package's "package name".
const char * version () const throw ()
 Returns the package version string.
void namesp_alias (const char *namesp, const char *pattern="*")
 Export commands into a different namespace.
void inherit_namesp (const char *namesp, const char *pattern="*")
 Import commands from a different namespace.
void inherit_pkg (const char *name, const char *version=0)
 Import all commands and procedures defined in the named pkg.
void eval (const char *script)
 Evaluates script using the package's Tcl_Interp.
void link_var (const char *var_name, int &var)
 Links the var with the Tcl variable var_name.
void link_var (const char *var_name, double &var)
 Links var with the Tcl variable var_name.
void link_var_copy (const char *var_name, int var)
 Links a copy of var with the Tcl variable var_name.
void link_var_copy (const char *var_name, double var)
 Links a copy of var with the Tcl variable var_name.
void link_var_const (const char *var_name, int &var)
 Links var with the Tcl variable var_name.
void link_var_const (const char *var_name, double &var)
 Links var with the Tcl variable var_name.
template<class Func >
void def (const char *cmd_name, const char *usage, Func f, const rutz::file_pos &src_pos, int flags=0)
template<class Func >
void def_vec (const char *cmd_name, const char *usage, Func f, unsigned int keyarg, const rutz::file_pos &src_pos, int flags=0)
template<class Func >
void def_raw (const char *cmd_name, const arg_spec &spec, const char *usage, Func f, const rutz::file_pos &src_pos, int flags=0)
template<class Func >
void def_vec_raw (const char *cmd_name, const arg_spec &spec, const char *usage, Func f, unsigned int keyarg, const rutz::file_pos &src_pos, int flags=0)
template<class C >
void def_action (const char *cmd_name, void(C::*action_func)(), const rutz::file_pos &src_pos, int flags=0)
template<class C >
void def_action (const char *cmd_name, void(C::*action_func)() const, const rutz::file_pos &src_pos, int flags=0)
template<class C , class T >
void def_getter (const char *cmd_name, T(C::*getter_func)() const, const rutz::file_pos &src_pos, int flags=0)
template<class C , class T >
void def_setter (const char *cmd_name, void(C::*setter_func)(T), const rutz::file_pos &src_pos, int flags=0)
template<class C , class T >
void def_get_set (const char *cmd_name, T(C::*getter_func)() const, void(C::*setter_func)(T), const rutz::file_pos &src_pos, int flags=0)
int finish_init () throw ()
 Called just prior to returning from the *_Init function.

Static Public Member Functions

static pkgcreate_in_macro (Tcl_Interp *interp, const char *name, const char *version)
 Don't call this directly! Use the PKG_CREATE macro instead.
static int destroy_on_unload (Tcl_Interp *interp, const char *pkgname)
 Looks up the tcl::pkg associated with pkgname, and destroys it.
static pkglookup (tcl::interpreter &interp, const char *name, const char *version=0) throw ()
 Find a package given its name and version.
static void verbose_init (bool verbose) throw ()
 Control whether packages should be verbose as they start up.

Static Public Attributes

static const int STATUS_OK = TCL_OK
static const int STATUS_ERR = TCL_ERROR

Friends

struct impl

Detailed Description

tcl::pkg is a class more managing groups of related tcl::command's. It provides several facilities:

-- stores a list of tcl::command's, and ensures that these are properly destroyed upon exit from Tcl

-- ensures that the package is provided to Tcl so that other packages can query for its presence

-- provides a set of functions to define Tcl commands from C++ functors

Definition at line 82 of file pkg.h.


Member Function Documentation

static pkg* tcl::pkg::create_in_macro ( Tcl_Interp *  interp,
const char *  name,
const char *  version 
) [inline, static]

Don't call this directly! Use the PKG_CREATE macro instead.

Definition at line 97 of file pkg.h.

int tcl::pkg::destroy_on_unload ( Tcl_Interp *  interp,
const char *  pkgname 
) [static]

Looks up the tcl::pkg associated with pkgname, and destroys it.

This is intended to be called from pkg_Unload procedures called by Tcl when a dynamic library is unloaded. The return value can be returned as the return value of the pkg_Unload procedure; it will be TCL_OK (1) if the tcl::pkg was successfully found and destroyed and TCL_ERROR (0) otherwise.

Definition at line 272 of file pkg.cc.

References interp(), and lookup().

void tcl::pkg::eval ( const char *  script  ) 

Evaluates script using the package's Tcl_Interp.

Definition at line 425 of file pkg.cc.

References tcl::interpreter::eval().

int tcl::pkg::finish_init (  )  throw ()

Called just prior to returning from the *_Init function.

If the package's status is OK, then this does the relevant Tcl_PkgProvide and returns TCL_OK. Otherwise, it returns TCL_ERROR.

Definition at line 484 of file pkg.cc.

References tcl::interpreter::intp(), and pkg_name().

void tcl::pkg::handle_live_exception ( const rutz::file_pos pos  )  throw ()

Trap a live exception, and leave a message in the Tcl_Interp's result.

Definition at line 331 of file pkg.cc.

void tcl::pkg::inherit_namesp ( const char *  namesp,
const char *  pattern = "*" 
)

Import commands from a different namespace.

Import all of the commands and procedures defined in the specified namespace into our own package namespace. If pattern is different from the default value of "*", then only commands whose names match pattern according to glob rules will be imported into our own package namespace.

Definition at line 345 of file pkg.cc.

References lookup().

Referenced by inherit_pkg().

void tcl::pkg::inherit_pkg ( const char *  name,
const char *  version = 0 
)

Import all commands and procedures defined in the named pkg.

If the named pkg has not yet been loaded, this function will attempt to load it via loookup(). If a null pointer is passed to version (the default), then any version will be acceptable.

Definition at line 366 of file pkg.cc.

References inherit_namesp(), lookup(), namesp_name(), rutz::sfmt(), and SRC_POS.

int tcl::pkg::init_status (  )  const throw ()

Returns a Tcl status code indicating whether the package initialization was successful.

Definition at line 315 of file pkg.cc.

tcl::interpreter & tcl::pkg::interp (  )  throw ()

Returns the Tcl interpreter that was passed to the constructor.

Definition at line 325 of file pkg.cc.

Referenced by destroy_on_unload().

void tcl::pkg::link_var ( const char *  var_name,
double &  var 
)

Links var with the Tcl variable var_name.

Definition at line 437 of file pkg.cc.

void tcl::pkg::link_var ( const char *  var_name,
int &  var 
)

Links the var with the Tcl variable var_name.

Definition at line 431 of file pkg.cc.

void tcl::pkg::link_var_const ( const char *  var_name,
double &  var 
)

Links var with the Tcl variable var_name.

The Tcl variable will be read_only.

Definition at line 465 of file pkg.cc.

void tcl::pkg::link_var_const ( const char *  var_name,
int &  var 
)

Links var with the Tcl variable var_name.

The Tcl variable will be read_only.

Definition at line 459 of file pkg.cc.

void tcl::pkg::link_var_copy ( const char *  var_name,
double  var 
)

Links a copy of var with the Tcl variable var_name.

The Tcl variable will be read-only.

Definition at line 451 of file pkg.cc.

References rutz::shared_ptr< T >::get().

void tcl::pkg::link_var_copy ( const char *  var_name,
int  var 
)

Links a copy of var with the Tcl variable var_name.

The Tcl variable will be read-only.

Definition at line 443 of file pkg.cc.

References rutz::shared_ptr< T >::get().

tcl::pkg * tcl::pkg::lookup ( tcl::interpreter interp,
const char *  name,
const char *  version = 0 
) throw () [static]

Find a package given its name and version.

If the package is not already loaded, this function will attempt to "require" the package. If a null pointer is passed to version (the default), then any version will be acceptable. If no suitable package cannot be found or loaded, a null pointer will be returned.

Definition at line 286 of file pkg.cc.

References tcl::interpreter::intp().

Referenced by destroy_on_unload(), inherit_namesp(), and inherit_pkg().

void tcl::pkg::namesp_alias ( const char *  namesp,
const char *  pattern = "*" 
)

Export commands into a different namespace.

Causes all of our package's currently defined commands and procedures to be imported into the specified other namespace. If pattern is different from the default value of "*", then only commands whose names match pattern according to glob rules will be aliased into the other namespace.

Definition at line 338 of file pkg.cc.

const char * tcl::pkg::namesp_name (  )  throw ()

Returns the package's "namespace name".

Note that the "namespace name" will be the same as the "package name" except possibly for capitalization. The "namespace name" is the name of the namespace that is used as the default prefix all commands contained in the package.

Definition at line 379 of file pkg.cc.

Referenced by inherit_pkg().

void tcl::pkg::on_exit ( exit_callback *  callback  ) 

Specify a function to be called when the package is destroyed.

(Package destruction typically occurs at application exit, when the Tcl interpreter and all associated objects are destroyed.)

Definition at line 266 of file pkg.cc.

const char * tcl::pkg::pkg_name (  )  const throw ()

Return the package's "package name".

Note that the "package name" will be the same as the "namespace name" except possibly for capitalization. The "package name" is the name that is passed to Tcl_PkgProvide() and Tcl_PkgProvide(), and has a well-defined capitalization scheme: first character uppercase, all remaining letters lowercase.

Definition at line 384 of file pkg.cc.

Referenced by finish_init().

void tcl::pkg::set_init_status_error (  )  throw ()

Mark the package as having failed its initialization.

Definition at line 471 of file pkg.cc.

void tcl::pkg::verbose_init ( bool  verbose  )  throw () [static]

Control whether packages should be verbose as they start up.

Definition at line 477 of file pkg.cc.

const char * tcl::pkg::version (  )  const throw ()

Returns the package version string.

Definition at line 389 of file pkg.cc.


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:31:38 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3