1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 
14 /* $Id: iparam.h 9043 2008-08-28 22:48:19Z giles $ */
15 /* Definitions and interface for interpreter parameter list implementations */
16 /* Requires ialloc.h, istack.h */
17 
18 #ifndef iparam_INCLUDED
19 #  define iparam_INCLUDED
20 
21 #include "gsparam.h"
22 
23 /*
24  * This file defines the interface to iparam.c, which provides
25  * several implementations of the parameter dictionary interface
26  * defined in gsparam.h:
27  *      - an implementation using dictionary objects;
28  *      - an implementation using name/value pairs in an array;
29  *      - an implementation using name/value pairs on a stack.
30  *
31  * When reading ('putting'), these implementations keep track of
32  * which parameters have been referenced and which have caused errors.
33  * The results array contains 0 for a parameter that has not been accessed,
34  * 1 for a parameter accessed without error, or <0 for an error.
35  */
36 
37 typedef struct iparam_loc_s {
38     ref *pvalue;		/* (actually const) */
39     int *presult;
40 } iparam_loc;
41 
42 #define iparam_list_common\
43     gs_param_list_common;\
44     gs_ref_memory_t *ref_memory; /* a properly typed copy of memory */\
45     union {\
46       struct {	/* reading */\
47 	int (*read)(iparam_list *, const ref *, iparam_loc *);\
48 	ref policies;	/* policy dictionary or null */\
49 	bool require_all;	/* if true, require all params to be known */\
50       } r;\
51       struct {		/* writing */\
52 	int (*write)(iparam_list *, const ref *, const ref *);\
53 	ref wanted;		/* desired keys or null */\
54       } w;\
55     } u;\
56     int (*enumerate)(iparam_list *, gs_param_enumerator_t *, gs_param_key_t *, ref_type *);\
57     int *results;		/* (only used when reading, 0 when writing) */\
58     uint count;		/* # of key/value pairs */\
59     bool int_keys		/* if true, keys are integers */
60 typedef struct iparam_list_s iparam_list;
61 struct iparam_list_s {
62     iparam_list_common;
63 };
64 
65 typedef struct dict_param_list_s {
66     iparam_list_common;
67     ref dict;			/* dictionary or array */
68 } dict_param_list;
69 typedef struct array_param_list_s {
70     iparam_list_common;
71     ref *bot;
72     ref *top;
73 } array_param_list;
74 
75 /* For stack lists, the bottom of the list is just above a mark. */
76 typedef struct stack_param_list_s {
77     iparam_list_common;
78     ref_stack_t *pstack;
79     uint skip;			/* # of top items to skip (reading only) */
80 } stack_param_list;
81 
82 /* Procedural interface */
83 /*
84  * For dict_param_list_read (only), the second parameter may be NULL,
85  * equivalent to an empty dictionary.
86  * The 3rd (const ref *) parameter is the policies dictionary when reading,
87  * or the key selection dictionary when writing; it may be NULL in either case.
88  * If the bool parameter is true, if there are any unqueried parameters,
89  * the commit procedure will return an e_undefined error.
90  */
91 int dict_param_list_read(dict_param_list *, const ref * /*t_dictionary */ ,
92 			 const ref *, bool, gs_ref_memory_t *);
93 int dict_param_list_write(dict_param_list *, ref * /*t_dictionary */ ,
94 			  const ref *, gs_ref_memory_t *);
95 int array_indexed_param_list_read(dict_param_list *, const ref * /*t_*array */ ,
96 				  const ref *, bool, gs_ref_memory_t *);
97 int array_indexed_param_list_write(dict_param_list *, ref * /*t_*array */ ,
98 				   const ref *, gs_ref_memory_t *);
99 int array_param_list_read(array_param_list *, ref *, uint,
100 			  const ref *, bool, gs_ref_memory_t *);
101 int stack_param_list_read(stack_param_list *, ref_stack_t *, uint,
102 			  const ref *, bool, gs_ref_memory_t *);
103 int stack_param_list_write(stack_param_list *, ref_stack_t *,
104 			   const ref *, gs_ref_memory_t *);
105 
106 #define iparam_list_release(plist)\
107   gs_free_object((plist)->memory, (plist)->results, "iparam_list_release")
108 
109 #endif /* iparam_INCLUDED */
110