1% BEGIN LICENSE BLOCK
2% Version: CMPL 1.1
3%
4% The contents of this file are subject to the Cisco-style Mozilla Public
5% License Version 1.1 (the "License"); you may not use this file except
6% in compliance with the License.  You may obtain a copy of the License
7% at www.eclipse-clp.org/license.
8% 
9% Software distributed under the License is distributed on an "AS IS"
10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11% the License for the specific language governing rights and limitations
12% under the License. 
13% 
14% The Original Code is  The ECLiPSe Constraint Logic Programming System. 
15% The Initial Developer of the Original Code is  Cisco Systems, Inc. 
16% Portions created by the Initial Developer are
17% Copyright (C) 1997 - 2006 Cisco Systems, Inc.  All Rights Reserved.
18% 
19% Contributor(s): Kish Shen, CrossCore Optimization
20% 
21% END LICENSE BLOCK
22
23
24:- lib(module_options).
25
26:- local struct(options(/*session*/ session_dbname,session_storage,
27                        /*cursor*/  cursor_buffering,cursor_type)
28               ).
29
30default_options(options{cursor_buffering:"client",cursor_type:"read_only"}).
31
32
33valid_option_field(session_dbname, session_dbname of options).
34valid_option_field(session_storage, session_storage of options).
35
36valid_option_field(cursor_buffering, cursor_buffering of options).
37valid_option_field(cursor_type, cursor_type of options).
38
39
40valid_option_value(session_dbname, Value) :-  
41        (string(Value) ; atom(Value)), !.
42valid_option_value(session_storage, Value) :- 
43        (string(Value) ; atom(Value)), !.
44
45valid_option_value(cursor_buffering, Value) :-
46        (string(Value) ; atom(Value)), 
47        concat_string([Value], ValueS),
48        (ValueS == "server" ; ValueS = "client"), !.
49valid_option_value(cursor_type, Value) :-
50        (string(Value) ; atom(Value)), 
51        concat_string([Value], ValueS),
52        (ValueS == "no_cursor" ; ValueS = "read_only"), !.
53
54
55:- local struct(session_opts(dbname,storage)).
56:- local struct(cursor_opts(buffering,type)).
57
58valid_opts_field(Type, Name, Field) :-
59        concat_atom([Type, '_', Name], OptName),
60        valid_option_field(OptName, Field).
61
62valid_opt_value(Type, Name, Value) :-
63        concat_atom([Type, '_', Name], OptName),
64        valid_option_value(OptName, Value).
65
66get_opts(Type, OptList, OptStruct) :-
67        (foreach(F:V, OptList), param(Type), 
68         foreach(TF:V, TypedOptList) do
69            concat_atom([Type,'_',F], TF)
70        ),
71        get_options(TypedOptList, OptStruct).
72
73