Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

cmdparam.h File Reference


Detailed Description

Public headers for cmdparam.c.

Header
/u/nn/cvsroot/lissom/src/cmdparam.h,v 1.84 2002/10/17 05:26:23 jbednar Exp

Definition in file cmdparam.h.

#include <stdio.h>
#include <string>
#include "ipc.h"
#include "stringparser.h"
#include "parameter.h"
#include "parametermap.h"
#include "expressionparser.h"

Include dependency graph for cmdparam.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Compounds

class  CmdWrapper
 Abstract base class packaging up a command as a function object; this is used to support both global functions and functions with access to a particular object. More...


Defines

#define blackboard   (*blackboard_ptr)
#define params_add_lower_bound_int(name, val)   blackboard.lookup(name).add_lower_bound(val)
#define params_add_upper_bound_int(name, val)   blackboard.lookup(name).add_upper_bound(val)
#define params_check_all()   blackboard.check_all()
#define params_define_default_expr(name, val)   blackboard.lookup(name).add_default_expr(val)
#define params_define_doc(name, val)   blackboard.lookup(name).add_doc(val)
#define params_define_param(name, type, constant, ptr)   blackboard.define_param(ParamType(name,type,constant,ptr))
#define params_print_constants(fp)   blackboard.print_constants(fp)
#define params_print_constants_doc(fp)   blackboard.print_constants_doc(fp)
#define params_print_parameters(fp)   blackboard.print_parameters(fp)
#define params_print_parameters_doc(fp)   blackboard.print_parameters_doc(fp)
#define params_update_all_default_values()   blackboard.update_all_default_values(CmdParamStringParser(blackboard))
#define cmdparam_set(name, expr)   blackboard.lookup(name).set(CmdParamStringParser(blackboard),expr)
#define cmdparam_changes_verbose   ParameterDefinition<>::changes_verbose
#define PARSE_I(x)   Parse(blackboard,x).cmdi()
#define PARSE_F(x)   Parse(blackboard,x).cmdf()
#define PARSE_C(x)   Parse(blackboard,x).cmds()
#define SETFNOBJ_DEFINE2(cargs, paramname, fnname)   blackboard.lookup(#paramname).add_setfn(new setfnobj2_ ## fnname(cargs))
#define SETFN_DEFINE2(paramname, fnname)   SETFNOBJ_DEFINE2(,paramname,fnname)
 Wrapper to call a global or static setfn as a SetFnWrapper.

#define DECLARE_A(name_str, is_constant, initial_value)   BlackboardType::ParamType(allocating_Polymorph(initial_value),name_str,is_constant)
#define PARAM_A(bboard, name_str, initial_value, options, doc)   bboard.define_param(DECLARE_A(name_str,false,initial_value).add_doc(doc)options)
#define DECLARE_PARAM(type, name_str, is_constant, location)   BlackboardType::ParamType(make_Polymorph(location),name_str,is_constant)
 Construct (but do not register) undocumented parameter.

#define PARAM(type, name, location)   DECLARE_PARAM(type,#name,false,location)
#define PARAM_NN(type, name, location, doc)   blackboard.define_param(PARAM(type,name,location).add_doc(doc))
 Parameter which has no bounds.

#define PARAM_LL(type, name, location, lower, doc)   blackboard.define_param(PARAM(type,name,location).add_doc(doc).add_lower_bound(lower))
 Parameter (of any type) with an integer lower bound.

#define PARAM_II(type, name, location, lower, upper, doc)   blackboard.define_param(PARAM(type,name,location).add_doc(doc).add_lower_bound(lower).add_upper_bound(upper))
 Parameter (of any type) with integer upper and lower bounds.

#define PARAM_N(type, name, doc)   blackboard.define_param(PARAM(type,name,&name).add_doc(doc))
#define PARAM_L(type, name, lower, doc)   blackboard.define_param(PARAM(type,name,&name).add_doc(doc).add_lower_bound(lower))
#define PARAM_I(type, name, lower, upper, doc)   blackboard.define_param(PARAM(type,name,&name).add_doc(doc).add_lower_bound(lower).add_upper_bound(upper))
#define CONST_I(name, value, is_param, doc)
 Symbolic integer constant.

#define CONST_B(name, value, is_param, doc)
 Symbolic boolean constant.

#define CONST_F(name, value, is_param, doc)
 Symbolic floating-point constant.

#define CONST_S(name, is_param, doc)
 Symbolic string constant, useful only for documentation.

#define CMD_MAX_ARGUMENTS   512
 Maximum number of arguments that can be supplied to a command.

#define CMD_MAX_LINE_LENGTH   16384
 Command-line length limit; see also bufsize in ExpressionParser<MapT>::getstringval().

#define CMD_NO_ERROR   0
#define CMD_FATAL_ERROR   -20000
#define CMD_MISC_ERROR   -20001
#define CMD_FILE_ERROR   -20002
#define CMD_PARAMETER_ERROR   -20003
#define CMD_MEMORY_ERROR   -20004
#define CMD_PREREQ_ERROR   -20005
#define CMD_EMPTY   -20006
 Can be returned by command_exec_str().

#define CMD_PARSE_ERROR   -20007
 Can be returned by command_exec_str().

#define CMD_NEVER_CALLED   -20008
 Used for prerequisites.

#define CMD_SIGINT_ERROR   -20009
 Command received a SIGINT.

#define CMD_SHELL_ERROR   -20010
 System command returned with nonzero status.

#define CMD_ARGS   int argc, const char *argv[]
#define CMD_ARGS_DECL   int argc=0, const char *argv[]=0
#define CMD_UNUSED_ARGS   int, const char *[]
#define CMD_CALL_ARGS   argc,argv
#define CMD_HEADER(name)   cmdstat cmd_ ## name ( CMD_ARGS_DECL )
 Header-file declaration for a global command function.

#define CMD_DECLARE(name)
 Declare global command function with an associated function object wrapper.

#define CMDOBJ_DOC(name, prereq, cargs, numargs, usage, doc)
 Typical way to declare an ordinary command object with documentation.

#define CMD_DOC(name, prereq, numargs, usage, doc)   CMDOBJ_DOC(name,prereq,,numargs,usage,doc)
 Wrapper to call a global or static function as a CmdWrapper.

#define CMDOBJ_DEFINE_CATCHUP(cargs, numargs, name, usage, doc)
 Typical way to declare a command that should be run even if just catching up to a new counter value.

#define CMD_DEFINE_CATCHUP(numargs, name, usage, doc)   CMDOBJ_DEFINE_CATCHUP(,numargs,name,usage,doc)
 Wrapper to call a global or static catchup function as a CmdWrapper.

#define CMDOBJ_DECLARE(Owner, name)
 Defines a simple CmdWrapper wrapping a member function as a subclass.

#define CMD_ARG_LIST
#define CMD_ARG_ASSERT_UNUSED   { (void)argv; if (argc) ipc_notify(IPC_ONE,IPC_WARNING,"All arguments are ignored"); }
#define CMD_ARG_PARAMS(name)
 Extension of CMD_ARG_LIST that also makes command-specific parameters available, processing any default values for them that are given first on the command line.

#define CMD_ARG_ASSERT_EMPTY
 Warns if there are unused args remaining at the end of a command.


Typedefs

typedef ParameterDefinition ParamType
typedef ParameterMap< ParamTypeBlackboardType
typedef ExpressionParser Parse
typedef ParamStringParser CmdParamStringParser
typedef int cmdstat
typedef cmdstat(* commandfunptr )(int argc, const char *argv[])
typedef int(* CmdDefs_LineGenerator )(void)
 For use with cmddefs_exec_batch.

typedef int HooklistNum
 Type for hooklist index.


Functions

 CMD_HEADER (set)
 CMD_HEADER (hook)
char * cmdparams_completion_generator (char *text, int state)
 Returns possible completion for command (if any) or parameter (if any).

void cmdparam_init_hook (void)
 This routine must be called before using parameters or commands, and no commands should be defined after it is called.

int cmdparams_print_doc (FILE *fp, const char *name)
 Print documentation string for any known object to a file.

int cmdparam_save_current_state (const char *filename)
char * cmdparam_dupstr (const char *str)
 Allocate a copy of a string; must be freed when done using it.

bool cmdparams_set_single (BlackboardType &params, const string &arg, bool &seterror, bool mark=true, bool verbose=ParamType::changes_verbose, bool copysetfn=true)
 Implementation of cmd_set for one argument.

cmdstat cmdparams_set (BlackboardType &params, StringArgs &arglist, bool mark=true, bool warn=false, bool verbose=ParamType::changes_verbose, bool copysetfn=true)
char * params_completion_generator (char *text, int state)
 Wrapper for the blackboard's completion generator.

char * cmddefs_completion_generator (char *text, int state)
 For use with functions like readline(); returns a dynamically-allocated string with the next possible completion for the given partial word.

void cmddefs_declare_prereq_status (const char *name, cmdstat status)
 Ordinary prerequisites are handled automatically, but if a command makes mutually recursive calls to other commands which require it as a prerequisite, the command may call this routine beforehand to declare that its useful work is done, and thus that the prerequisite is satisfied.

void cmddefs_define_command (const char *name, CmdWrapper *function, int minargs, int exec_for_catchups)
 Add command to list of known commands.

void cmddefs_define_command_doc (const char *name, const char *usage, const char *doc)
 Define help string for command.

void cmddefs_define_command_prereq (const char *name, const char *prereq)
 Put a prerequisite for a command into a temporary holding area while the other commands are defined; doesn't take effect until activated later.

int cmddefs_exec_batch (CmdDefs_LineGenerator fn, const char *description)
 Reads commands iteratively and executes them in sequence.

int cmddefs_exec_file (const char *filename)
 Reads commands from a command file and executes them.

cmdstat cmddefs_exec_by_name (const char *name, int argc, const char *argv[])
cmdstat cmddefs_exec_str (const char *cmdtxt)
 Parse and execute the command specified in the given string.

cmdstat cmddefs_exec_str (const string &cmdtxt)
int cmddefs_num_total (void)
 Returns current size of command blackboard.

void cmddefs_print_all (FILE *fp)
 Print summary of command definitions to a file.

void cmddefs_print_all_doc (FILE *file)
void cmddefs_print_doc (FILE *fp, const char *name)
 Print documentation string for a command to a file.

void cmddefs_print_doc_for_index (FILE *fp, int idx)
void hooklists_empty_list (HooklistNum hooklistnum)
 Remove all the hooks defined in the given list.

void hooklists_reset_list (HooklistNum hooklist)
 Reset current hook of the given list to the beginning.

void hooklists_run_list (HooklistNum hooklist, int counter, int catchuponly)
 Run the counter hooks in the given list which specify this counter value.

int hooklists_define_list (const char *listname, const char *countername)
 Defines a new hooklist and returns its number.


Variables

BlackboardType global_blackboard
 Top-level parameter def blackboard.

BlackboardTypeblackboard_ptr
 Pointer to current blackboard.

char cmddefs_line_buffer [CMD_MAX_LINE_LENGTH+1+sizeof(int)]
int command_num_called


Define Documentation

#define CMD_ARG_ASSERT_EMPTY
 

Value:

{\
  if (!arglist.empty()) {\
    const string rep = arglist.stringrep();\
    ipc_notify(IPC_ONE,IPC_WARNING,"Unused arguments: %s",rep.c_str());}}
Warns if there are unused args remaining at the end of a command.

Definition at line 348 of file cmdparam.h.

#define CMD_ARG_LIST
 

Value:

StringParser::arglist argl(&argv[0],&argv[argc]);\
  const CmdParamStringParser p(blackboard);\
  StringArgs arglist(p, argl.begin(), argl.end())

Definition at line 326 of file cmdparam.h.

#define CMD_ARG_PARAMS name   
 

Value:

CMD_ARG_LIST;\
  BlackboardType argparams(&blackboard.lookup_map("::cmd::" #name),"arguments");\
  cmdparams_set( argparams,arglist,true,false,false,false)
Extension of CMD_ARG_LIST that also makes command-specific parameters available, processing any default values for them that are given first on the command line.

Definition at line 341 of file cmdparam.h.

#define CMD_DECLARE name   
 

Value:

cmdstat cmd_ ## name ( CMD_ARGS );                         \
struct cmdobj_ ## name : public CmdWrapper {                \
  cmdstat operator() ( CMD_ARGS_DECL ) {                     \
    return cmd_ ## name(CMD_CALL_ARGS);                       \
  }                                                            \
}
Declare global command function with an associated function object wrapper.

Definition at line 207 of file cmdparam.h.

#define CMDOBJ_DECLARE Owner,
name   
 

Value:

cmdstat cmd_ ## name ( CMD_ARGS_DECL );                    \
class cmdobj_ ## name : public CmdWrapper {                 \
  Owner* owner;                                              \
public:                                                       \
  cmdobj_ ## name (Owner* owner_i) : owner(owner_i) { };       \
  cmdstat operator() ( CMD_ARGS_DECL ) {                        \
    return owner->cmd_ ## name (CMD_CALL_ARGS);                  \
  }                                                               \
};                                                                 \
friend class cmdobj_ ## name
Defines a simple CmdWrapper wrapping a member function as a subclass.

Definition at line 243 of file cmdparam.h.

#define CMDOBJ_DEFINE_CATCHUP cargs,
numargs,
name,
usage,
doc   
 

Value:

cmddefs_define_command(#name,new cmdobj_ ## name(cargs),numargs,True); \
cmddefs_define_command_doc(#name,usage,doc)
Typical way to declare a command that should be run even if just catching up to a new counter value.

Definition at line 232 of file cmdparam.h.

#define CMDOBJ_DOC name,
prereq,
cargs,
numargs,
usage,
doc   
 

Value:

cmddefs_define_command(#name,new cmdobj_ ## name(cargs),numargs,False); \
cmddefs_define_command_doc(#name,usage,doc);                             \
cmddefs_define_command_prereq(#name,prereq)
Typical way to declare an ordinary command object with documentation.

Definition at line 217 of file cmdparam.h.

#define CONST_B name,
value,
is_param,
doc   
 

Value:

{ static Tristate paramstorage=value;       \
  blackboard.define_param(DECLARE_PARAM(PARAM_3BOOL,#name,!is_param,&paramstorage).add_doc(doc).add_lower_bound(value).add_upper_bound(value)); }
Symbolic boolean constant.

Definition at line 134 of file cmdparam.h.

#define CONST_F name,
value,
is_param,
doc   
 

Value:

{ static double paramstorage=value;       \
  blackboard.define_param(DECLARE_PARAM(PARAM_DOUBLE,#name,!is_param,&paramstorage).add_doc(doc).add_lower_bound(value).add_upper_bound(value)); }
Symbolic floating-point constant.

Definition at line 140 of file cmdparam.h.

#define CONST_I name,
value,
is_param,
doc   
 

Value:

{ static int paramstorage=value;       \
  blackboard.define_param(DECLARE_PARAM(PARAM_INT,#name,!is_param,&paramstorage).add_doc(doc).add_lower_bound(value).add_upper_bound(value)); }
Symbolic integer constant.

Definition at line 128 of file cmdparam.h.

Referenced by ipc_init_hook(), WorldViews::register_params_and_commands(), and KernelFactory::register_params_and_commands().

#define CONST_S name,
is_param,
doc   
 

Value:

{ static string paramstorage=#name; \
  blackboard.define_param(DECLARE_PARAM(PARAM_USTRING,#name,!is_param,&paramstorage).add_doc(doc)); }
Symbolic string constant, useful only for documentation.

Definition at line 146 of file cmdparam.h.

Referenced by WorldViews::register_params_and_commands().


Function Documentation

char* cmddefs_completion_generator char *    text,
int    state
 

For use with functions like readline(); returns a dynamically-allocated string with the next possible completion for the given partial word.

Free should be called on the string when done with it.

Definition at line 1454 of file cmdparam.c.

References cmdparam_dupstr(), and command_definitions.

Referenced by cmdparams_completion_generator().

void cmddefs_declare_prereq_status const char *    name,
cmdstat    status
 

Ordinary prerequisites are handled automatically, but if a command makes mutually recursive calls to other commands which require it as a prerequisite, the command may call this routine beforehand to declare that its useful work is done, and thus that the prerequisite is satisfied.

This prevents a vicious circle of attempted prerequisite satisfaction.

Definition at line 724 of file cmdparam.c.

References cmddefs_lookup().

Referenced by Eyes::uninit().

int cmddefs_exec_batch CmdDefs_LineGenerator    fn,
const char *    description
 

Reads commands iteratively and executes them in sequence.

The command lines come from cmddefs_line_buffer, which the given function should place a string into once it is called with no arguments on a single PE. The fn should return True ("done") when there is no more input available.

Each line may be up to CMD_MAX_LINE_LENGTH total, and may contain up to one command with up to CMD_MAX_ARGUMENTS arguments, up to CMD_MAX_LINE_LENGTH total.

The description should be something like "file filename..." or "prompt".

Definition at line 1133 of file cmdparam.c.

References CMD_EMPTY, CMD_MAX_LINE_LENGTH, cmddefs_exec_str(), and ipc_barrier().

Referenced by cmddefs_exec_file(), and main().

int cmdparams_print_doc FILE *    fp,
const char *    name
 

Print documentation string for any known object to a file.

Returns True if object was found.

Definition at line 1925 of file cmdparam.c.

References command_definitions, ParameterDefinition< T >::doc_string(), and ParameterDefinition< T >::is_valid().

bool cmdparams_set_single BlackboardType   params,
const string &    arg,
bool &    seterror,
bool    mark,
bool    verbose,
bool    copysetfn
 

Implementation of cmd_set for one argument.

Returns true if the input had the proper form, regardless of the result. On exit, 'seterror' is set to false if the set failed, and is otherwise not changed.

Definition at line 2060 of file cmdparam.c.

References ParameterMap< ParamType >::set_matching(), and trim_quotes().

Referenced by command_parse_line().

int hooklists_define_list const char *    listname,
const char *    countername
 

Defines a new hooklist and returns its number.

   Example C usage: 

   (at start of program) 
     HooklistNum before_input;
     before_input = hooklists_define_list("before_input");

   (at location where hooks should execute)
     hooklists_run_list(before_input,t,False);
     
   Now the command
     hook before_input        5 set exc_rad 1

   will cause parameter exc_rad to be changed to 1 whenever
   hooklists_run_list is called with t=5.
   

Returns the number assigned to this list.

Definition at line 1506 of file cmdparam.c.

void hooklists_run_list HooklistNum    hooklist,
int    counter,
int    catchuponly
 

Run the counter hooks in the given list which specify this counter value.

Earlier values not yet run are called only if their definition specifies that.

This routine should be called at most once for each counter value, from the location where you want hooks from the given list to be called.

Definition at line 1739 of file cmdparam.c.

References command_exec().

char* params_completion_generator char *    text,
int    state
 

Wrapper for the blackboard's completion generator.

Only completes from the global blackboard, not any sub-boards defined elsewhere.

Definition at line 1948 of file cmdparam.c.


Generated on Mon Jan 20 02:35:52 2003 for RF-LISSOM by doxygen1.3-rc2