1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * rp_tcloptions |
---|
4 | * |
---|
5 | * This library is used to implement configuration options for the |
---|
6 | * Tcl API used in Rappture. It lets you define a series of |
---|
7 | * configuration options like the ones used for Tk widgets, and |
---|
8 | * provides functions to process them. |
---|
9 | * |
---|
10 | * ====================================================================== |
---|
11 | * AUTHOR: Michael McLennan, Purdue University |
---|
12 | * Copyright (c) 2008 Purdue Research Foundation |
---|
13 | * |
---|
14 | * See the file "license.terms" for information on usage and |
---|
15 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
16 | * ====================================================================== |
---|
17 | */ |
---|
18 | #ifndef RP_TCLOPTIONS |
---|
19 | #define RP_TCLOPTIONS |
---|
20 | |
---|
21 | #include <tcl.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * These data structures are used to define configuration options |
---|
25 | * associated with parameters and optimizer cores. They work just |
---|
26 | * like Tk widget options, but for objects that are not widgets. |
---|
27 | */ |
---|
28 | #ifdef offsetof |
---|
29 | #define Rp_Offset(type, field) ((int) offsetof(type, field)) |
---|
30 | #else |
---|
31 | #define Rp_Offset(type, field) ((int) ((char *) &((type *) 0)->field)) |
---|
32 | #endif |
---|
33 | |
---|
34 | typedef int (RpCustomTclOptionParse)_ANSI_ARGS_((Tcl_Interp *interp, |
---|
35 | Tcl_Obj *valObj, ClientData cdata, int offset)); |
---|
36 | typedef int (RpCustomTclOptionGet)_ANSI_ARGS_((Tcl_Interp *interp, |
---|
37 | ClientData cdata, int offset)); |
---|
38 | typedef void (RpCustomTclOptionCleanup)_ANSI_ARGS_((ClientData cdata, |
---|
39 | int offset)); |
---|
40 | |
---|
41 | typedef struct RpTclOptionType { |
---|
42 | char *type; /* name describing this type */ |
---|
43 | RpCustomTclOptionParse *parseProc; /* procedure to parse new values */ |
---|
44 | RpCustomTclOptionGet *getProc; /* procedure to report cur value */ |
---|
45 | RpCustomTclOptionCleanup *cleanupProc; /* procedure to free up value */ |
---|
46 | } RpTclOptionType; |
---|
47 | |
---|
48 | typedef struct RpTclOption { |
---|
49 | char *optname; /* name of option: -switch */ |
---|
50 | RpTclOptionType *typePtr; /* type of this switch */ |
---|
51 | ClientData extraInfo; /* extra data needed for switch type */ |
---|
52 | int offset; /* location of data within struct */ |
---|
53 | } RpTclOption; |
---|
54 | |
---|
55 | /* |
---|
56 | * Built-in types defined in rp_tcloptions.c |
---|
57 | */ |
---|
58 | extern RpTclOptionType RpOption_Int; |
---|
59 | #define RP_OPTION_INT &RpOption_Int |
---|
60 | |
---|
61 | extern RpTclOptionType RpOption_Double; |
---|
62 | #define RP_OPTION_DOUBLE &RpOption_Double |
---|
63 | |
---|
64 | extern RpTclOptionType RpOption_String; |
---|
65 | #define RP_OPTION_STRING &RpOption_String |
---|
66 | |
---|
67 | extern RpTclOptionType RpOption_List; |
---|
68 | #define RP_OPTION_LIST &RpOption_List |
---|
69 | |
---|
70 | /* |
---|
71 | * Here are the functions in the API: |
---|
72 | */ |
---|
73 | EXTERN int RpTclOptionsProcess _ANSI_ARGS_((Tcl_Interp *interp, |
---|
74 | int objc, Tcl_Obj *CONST objv[], RpTclOption *options, |
---|
75 | ClientData cdata)); |
---|
76 | |
---|
77 | EXTERN int RpTclOptionGet _ANSI_ARGS_((Tcl_Interp *interp, |
---|
78 | RpTclOption *options, ClientData cdata, char *desiredOpt)); |
---|
79 | |
---|
80 | EXTERN void RpTclOptionsCleanup _ANSI_ARGS_((RpTclOption *options, |
---|
81 | ClientData cdata)); |
---|
82 | |
---|
83 | #endif |
---|